Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] prospector fails when pyproject.toml contain multiple constraints dependencies #626

Open
ikappaki opened this issue Jul 23, 2023 · 0 comments

Comments

@ikappaki
Copy link

Describe the bug A clear and concise description of what the bug is.

When a multiple constraints dependency is specified in the pyproject.toml file, prospector fails with the following error:

 File "C:\venv311\Lib\site-packages\requirements_detector\poetry_semver\__init__.py", line 23, in parse_constraint
    or_constraints = re.split(r"\s*\|\|?\s*", constraints.strip())
                                              ^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'strip'

To Reproduce Steps to reproduce the behavior:

  1. pip install poetry and create a project
$ poetry new issue
Created package issue in issue
  1. cd issue and update the myproject.toml to include an example package (in our case requests) with multiple constraints
#...
[tool.poetry.dependencies]
requests = [
    {version = "<=1.9", python = ">=3.6,<3.8"},
    {version = "^2.0", python = ">=3.8"}
]
#...
  1. prospector -X .
  2. The above error is raised

Expected behavior A clear and concise description of what you expected to happen.

The prospector should finish without errors

Screenshots If applicable, add screenshots to help explain your problem.

> prospector -X .
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "c:\venv311\Scripts\prospector.exe\__main__.py", line 7, in <module>
  File "c:\venv311\Lib\site-packages\prospector\run.py", line 188, in main
    config = ProspectorConfig()
             ^^^^^^^^^^^^^^^^^^
  File "c:\venv311\Lib\site-packages\prospector\config\__init__.py", line 36, in __init__
    self.libraries = self._find_used_libraries(self.config, self.profile)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\venv311\Lib\site-packages\prospector\config\__init__.py", line 215, in _find_used_libraries
    for found_dep in autodetect_libraries(self.workdir):
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\venv311\Lib\site-packages\prospector\autodetect.py", line 89, in autodetect_libraries
    libraries = find_from_requirements(path)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\venv311\Lib\site-packages\prospector\autodetect.py", line 72, in find_from_requirements
    reqs = find_requirements(path)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\venv311\Lib\site-packages\requirements_detector\detect.py", line 72, in find_requirements
    requirements = from_pyproject_toml(poetry_toml)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\venv311\Lib\site-packages\requirements_detector\detect.py", line 127, in from_pyproject_toml
    parsed_spec = str(parse_constraint(spec))
                      ^^^^^^^^^^^^^^^^^^^^^^
  File "c:\venv311\Lib\site-packages\requirements_detector\poetry_semver\__init__.py", line 23, in parse_constraint
    or_constraints = re.split(r"\s*\|\|?\s*", constraints.strip())
                                              ^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'strip'

Environment (please complete the following information):

  • OS: MS-windows
  • Tool: prospector
  • Prospector version 1.10.2
  • Python version 3.11.4

Additional context Add any other context about the problem here. Putting the list of
dependencies installed, e.g. the output of pip freeze also helps.

The problem is that requirements-detector dependency assumes that a poetry dependency constraint is either a string or a map, but not a list.

(I've just realised that this is really a requirements-detector issue, but thought to still raise it here for perspective, feel free to migrate it to that project).

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant