prospector-dev / prospector

Inspects Python source files and provides information about type and location of classes, methods etc
GNU General Public License v2.0
1.95k stars 173 forks source link

[BUG] KeyError: 'version' when running in a folder with pyproject.toml which contains a path dependency #591

Open char0lene opened 1 year ago

char0lene commented 1 year ago

Describe the bug When you start prospector in a folder with a pyproject.toml (from poetry). And this file does contain a path path dependency; Then prospector throws a KeyError and does not execute, because apparently it misses a dependency version. (You can not include a version in the path dependency, as far as I observed.)

To Reproduce

  1. have 2 poetries (in different directories)
  2. include a path dependency in one poetry (A) to the other poetry (B)
  3. open a terminal in the folder with poetry A
  4. run prospector

Expected behavior

Traceback (most recent call last):
 File "/home/user/.local/bin/prospector", line 8, in <module>
   sys.exit(main())
 File "/home/user/.local/lib/python3.10/site-packages/prospector/run.py", line 189, in
main
   config = ProspectorConfig()
 File "/home/user/.local/lib/python3.10/site-packages/prospector/config/__init__.py", l
ine 36, in __init__
   self.libraries = self._find_used_libraries(self.config, self.profile)
 File "/home/user/.local/lib/python3.10/site-packages/prospector/config/__init__.py", l
ine 205, in _find_used_libraries
   for found_dep in autodetect_libraries(self.workdir):
 File "/home/user/.local/lib/python3.10/site-packages/prospector/autodetect.py", line 9
0, in autodetect_libraries
   libraries = find_from_requirements(path)
 File "/home/user/.local/lib/python3.10/site-packages/prospector/autodetect.py", line 7
2, in find_from_requirements
   reqs = find_requirements(path)
 File "/home/user/.local/lib/python3.10/site-packages/requirements_detector/detect.py",
line 68, in find_requirements
   requirements = from_pyproject_toml(poetry_toml)
 File "/home/user/.local/lib/python3.10/site-packages/requirements_detector/detect.py",
line 116, in from_pyproject_toml
   spec = spec["version"]
KeyError: 'version'

Environment (please complete the following information):

Additional context

You need two pyproject.toml poetry files.

bellmatt commented 1 year ago

This looks like the same issue as https://github.com/PyCQA/prospector/issues/556 - there's a workaround in that issue if you need one. The fix for this in requirements_detector has been merged now, so hopefully a fixed version of prospector is not too far away 🤞

sbrunner commented 2 weeks ago

556 is closed as fixed in 1.10 can this one also be closed?