I have created a setup.py for my python project to include a number of .json files during the packaging of my .egg. When I run the command python setup.py install I can see in the output as well as inspecting the .egg itself that the .json were included in the packaging.
Here is my setup.py
setup(name='exmaple',
version='0.0.1',
author='nc',
description='TBD',
long_description=open('README.md').read(),
packages=find_packages(exclude=['tests', 'examples']),
data_files=[('json-configs', glob('json-configs/*.json'))],
python_requires='~=3.0',
install_requires=[
'importlib_resources==1.0.2'
]
)
The issue I am having is around how to appropriately access these files during runtime of my python application. The .json files are configurations that need to be read in at runtime if the appropriate class is executed. I have been reading a lot about package_data and that seems to be the preferred approach, but I would strongly prefer to not have an __init__.py file in my json-configs folder for reasons outside of the scope of this question.
Is there a best practice for reading in data_files during execution? Is this not the use case for data_files and should I really only be using package_data with importlib to read in resource files? Are there other better alternatives to reading in resource files that need to be accessed during the execution of a python program?