I recently started experimenting with Poetry for package and dependency management, and I am still getting used to the differences between it and my experience with setuptools. Specifically, I would appreciate help in understanding how to handle the following scenario.
I have a data file that I want to bundle with my package stored in a package subdirectory. Using setup.py I would specify the file and directory names in the setup.py file and then access the file in my code using the pkg_resources API.
What is the equivalent approach using Poetry and pyproject.toml?
Unlike setuptools poetry bundles automatically all files within your package folder into your package, unless you haven't explicit excluded them in your .gitignore or the pyproject.toml.
So after the package is installed, you can access them with pkg_resources.
sinoroc's answer is deprecated. The new method since python 3.9 is:
p = importlib.resources.as_file(importlib.resources.files('resources') / 'resource.toml')
with p as f:
my_toml = tomllib.load(f.open('rb')) # as an example
Unfortunately, that doesn't really answer the original post. I don't have a solution for poetry yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With