creosote: Exception in package_to_module
Tried it on my project: https://github.com/staticf0x/mrmonitor
Invocation: creosote --venv (poetry env info --path) --deps-file pyproject.toml --paths . --sections tool.poetry.dependencies
Parsing mrmonitor.py
Parsing reviews.py
Parsing pyproject.toml for packages
Found packages in pyproject.toml: arrow, click, python-dotenv, python-gitlab, rich
Resolving...
Traceback (most recent call last):
File "/home/username/.local/bin/creosote", line 8, in <module>
sys.exit(main())
^^^^^^
File "/home/username/.local/lib/python3.11/site-packages/creosote/cli.py", line 90, in main
deps_resolver.resolve()
File "/home/username/.local/lib/python3.11/site-packages/creosote/resolvers.py", line 109, in resolve
self.populate_packages()
File "/home/username/.local/lib/python3.11/site-packages/creosote/resolvers.py", line 87, in populate_packages
self.package_to_module(package)
File "/home/username/.local/lib/python3.11/site-packages/creosote/resolvers.py", line 53, in package_to_module
for filename, _, _ in dist.list_installed_files():
File "/home/username/.local/lib/python3.11/site-packages/distlib/database.py", line 677, in list_installed_files
for result in self._get_records():
^^^^^^^^^^^^^^^^^^^
File "/home/username/.local/lib/python3.11/site-packages/distlib/database.py", line 596, in _get_records
with contextlib.closing(r.as_stream()) as stream:
^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'as_stream'
Same thing in another project with requirements.txt
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17 (9 by maintainers)
@staticf0x the related code which crashed here originally has been completely rewritten and I just tried it out here without issues:
@staticf0x I’m glad to hear #139 solves this for you. I’m merging it in then 😄
Many thanks for taking the time to create the repro steps. I’ll try to follow them later, so to make sure this won’t happen either way. I’ll leave this issue open until I’ve done so.
If you want to reproduce the bug, you could follow these steps:
dnf install python3-clickpip3 install --user arrowThis should hopefully be enough to replicate the behavior
In
map_package_to_module_via_distlibthere’s a call todist.list_installed_files(), forarrowit works, but not forclick.In
_get_records()(https://github.com/pypa/distlib/blob/05375908c1b2d6b0e74bdeb574569d3609db9f56/distlib/database.py#L587) you can see this line:For
arrowit returns a resource with path/home/username/.local/lib/python3.11/site-packages/arrow-1.2.3.dist-info/RECORD, which is my user python directory (installed viapip3 install --user).Now look at
pip3 show arrow:but for
pip3 show click:and the resource is not returned, because the
RECORDfile is not there.Now back to creosote: see this line: https://github.com/fredrikaverpil/creosote/blob/main/src/creosote/resolvers.py#L122
First it maps the package using venv, which is correct, that method runs just fine, but then it tries to map those packages again using distlib, but it’s not aware of venv. Shouldn’t it be “if venv else distlib” instead of “venv then distlib”?
See output from pdb:
So both packages are correctly mapped in
map_package_to_import_via_top_level_txt_file, butclickcannot be mapped inmap_package_to_module_via_distlibafter that.Hope this helps.
pip3 show creosote:creosote --venv (poetry env info --path) --deps-file pyproject.toml --paths mrmonitor.py --sections tool.poetry.dependencies --verbose: