I tried to add a TXT file into my python package, load it by pkg_resources
, and do some other stuff with data after that. The structure of my python package is following:
package_name
|-- requirements.txt
|-- setup.py
|-- MANIFEST.in
|-- package
|-- __init__.py
|-- name
|-- __init__.py
|-- my_file.py
|-- test
|-- __init__.py
|-- test_1.py
|-- data
|-- MY_DATA.txt
The content of ~/package_name/package/name/my_file.py
:
import pkg_resources
DATA_PATH = 'package.name.data'
MY_DATA_PATH = pkg_resources.resource_filename(DATA_PATH, 'MY_DATA.txt')
def do_some_stuff_with_data(data_path=MY_DATA_PATH):
...
When I run tests on my local machine, the code runs without any problem. However, when I try to push it into git
repository via CI/CD, tests fail on the error below:
/tmp/testenv/lib/python3.7/site-packages/package/name/test/test_name.py:13: in <module>
from package.name.my_file import (
/tmp/testenv/lib/python3.7/site-packages/package/name/my_file.py:28: in <module>
MY_DATA_PATH = pkg_resources.resource_filename(DATA_PATH, 'MY_DATA.txt')
/tmp/testenv/lib/python3.7/site-packages/pkg_resources/__init__.py:1206: in resource_filename
return get_provider(package_or_requirement).get_resource_filename(
/tmp/testenv/lib/python3.7/site-packages/pkg_resources/__init__.py:437: in get_provider
return _find_adapter(_provider_factories, loader)(module)
/tmp/testenv/lib/python3.7/site-packages/pkg_resources/__init__.py:1452: in __init__
self.module_path = os.path.dirname(getattr(module, '__file__', ''))
/tmp/testenv/lib/python3.7/posixpath.py:156: in dirname
p = os.fspath(p)
E TypeError: expected str, bytes or os.PathLike object, not NoneType
I know, that data path is written correctly. I checked the typos for several times. I also thought that the error could have been caused by not adding data path to MANIFEST.in
file. However, the addition did not solve the problem.
Do you have any idea what I am missing?