This project is archived. Its data is read-only. This project is read-only.
Files for a src-style project installed in editable or develop mode
In the case of a project with a `src`-style directory structure that is installed in _develop_ or _editable_ mode, it is not immediately possible to access the files. ``` . ├── setup.py └── src └── mypackage └── __init__.py ``` ``` #!/usr/bin/env python3 import setuptools setuptools.setup( name='MyProject', version='0.0.0.dev0', packages=setuptools.find_packages(where='src'), package_dir={ '': 'src', }, ) ``` ``` import importlib_metadata print("importlib_metadata.__version__", importlib_metadata.__version__) dist = importlib_metadata.distribution('MyProject') print("dist.locate_file('')", dist.locate_file('')) for file_ in dist.files: print("file_", file_) for file_ in dist.files: print("file_", file_) print(file_.read_text()) ``` ``` $ ./setup.py develop running develop running egg_info creating src/MyProject.egg-info writing src/MyProject.egg-info/PKG-INFO writing dependency_links to src/MyProject.egg-info/dependency_links.txt writing top-level names to src/MyProject.egg-info/top_level.txt writing manifest file 'src/MyProject.egg-info/SOURCES.txt' reading manifest file 'src/MyProject.egg-info/SOURCES.txt' writing manifest file 'src/MyProject.egg-info/SOURCES.txt' running build_ext Creating /tmp/tmp.BzMk6xAF0S/.venv/lib/python3.6/site-packages/MyProject.egg-link (link to src) MyProject 0.0.0.dev0 is already the active version in easy-install.pth Installed /tmp/tmp.BzMk6xAF0S/src Processing dependencies for MyProject==0.0.0.dev0 Finished processing dependencies for MyProject==0.0.0.dev0 ``` ``` $ python -c 'import mypackage' importlib_metadata.__version__ 1.5.0 dist.locate_file('') /tmp/tmp.BzMk6xAF0S/src file_ setup.py file_ src/MyProject.egg-info/PKG-INFO file_ src/MyProject.egg-info/SOURCES.txt file_ src/MyProject.egg-info/dependency_links.txt file_ src/MyProject.egg-info/top_level.txt file_ src/mypackage/__init__.py file_ setup.py Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/tmp.BzMk6xAF0S/src/mypackage/__init__.py", line 11, in <module> print(file_.read_text()) File "/tmp/tmp.BzMk6xAF0S/.venv/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 140, in read_text with self.locate().open(encoding=encoding) as stream: File "/usr/lib/python3.6/pathlib.py", line 1183, in open opener=self._opener) File "/usr/lib/python3.6/pathlib.py", line 1037, in _opener return self._accessor.open(self, flags, mode) File "/usr/lib/python3.6/pathlib.py", line 387, in wrapped return strfunc(str(pathobj), *args) FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmp.BzMk6xAF0S/src/setup.py' ``` This is obviously a special case, the combination of _editable_ (or _develop_) mode with _setuptools_ `package_dir` seems quite tricky to deal with.
issue