Embed resource files in final package at a given location
See original GitHub issueFrom @theunkn0wn1
The feature I would like to see out of this is to be able to embed resource files into the wheel (and subsequently the installed package) at an arbitrary location.
For instance, in my project i would like to embed the pyproject.toml
into the installed sources so the library may access this resource at runtime. I wish to do this to access the version string contained in the pyproject.toml
.
Presently, even if the tool.poetry.include
directive is used the file does not end up in the installation directory and is consequently not usable to the installed application.
My application has the structure
/
/pyproject.toml
/src/...
/test/...
What I would like to do is copy, at build time, /pyproject.toml
to /src/pyproject.toml
so it may be included in the wheel and usable a resource via importlib.resources
.
import importlib.resources as resources
import toml
import src # root application package (renames are planned)
package_meta = toml.loads(resources.read_text(src, "pyproject.toml"))
src.__version__ = package_meta['tool']['poetry']['version']
_Originally posted by @theunkn0wn1 in https://github.com/python-poetry/core/pull/6#issuecomment-608017525_
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (3 by maintainers)
@finswimmer @stephsamson Is there no current way to include resource files that are not in a package?
I’d like to include a changelog.md so it can be summarized when the package runs.
This is a more obscure use case, but I also have a self-hosting code that needs to store its own config setup, including its own pyproject.toml.
Closing this as a duplicate of #4583