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

Poetry 1.2.0a2 issue adding packages with major version 0 (version 0.Y.Z) using only ^0 #5277

Closed
3 tasks done
ESKYoung opened this issue Mar 5, 2022 · 4 comments · Fixed by #5281
Closed
3 tasks done
Labels
kind/bug Something isn't working as expected

Comments

@ESKYoung
Copy link

ESKYoung commented Mar 5, 2022

  • I am on the latest Poetry version. Actually on preview version 1.2.0a2
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: macOS Monterey version 12.2.1
  • Poetry version: 1.2.0a2
  • Link of a Gist with the contents of your pyproject.toml file: Gist Link

Issue

Poetry 1.2.0a2 cannot find matching package versions for major version 0, where the caret is supplied as ^0 only. This works on Poetry 1.1, and is also a dependency specification example in the master documentation.

For example, using scikit-learn (the error occurs when adding other packages with the ^0 condition):

poetry add scikit-learn@^0  # fails
poetry add scikit-learn@^0.24  # works — installs the latest 0.24.Z version (0.24.2) as expected
poetry add "scikit-learn<1"  # works — installs the latest 0.Y.Z version (0.24.2) as expected

Running poetry add scikit-learn@^0 -vvv shows the following:

Using virtualenv: /Users/{USER_NAME}/Library/Caches/pypoetry/virtualenvs/poetry-bug-k1OA12gR-py3.9
PyPI: No release information found for scikit-learn-0.14a1, skipping
PyPI: 0 packages found for scikit-learn >=0,<0.1

  Stack trace:

  9  ~/.poetry/venv/lib/python3.9/site-packages/cleo/application.py:330 in run
      328│ 
      329│             try:
    → 330│                 exit_code = self._run(io)
      331│             except Exception as e:
      332│                 if not self._catch_exceptions:

  8  ~/.poetry/venv/lib/python3.9/site-packages/poetry/console/application.py:180 in _run
      178│         self._load_plugins(io)
      179│ 
    → 180│         return super()._run(io)
      181│ 
      182│     def _configure_io(self, io: IO) -> None:

  7  ~/.poetry/venv/lib/python3.9/site-packages/cleo/application.py:425 in _run
      423│                 io.set_input(ArgvInput(argv))
      424│ 
    → 425│         exit_code = self._run_command(command, io)
      426│         self._running_command = None
      427│ 

  6  ~/.poetry/venv/lib/python3.9/site-packages/cleo/application.py:467 in _run_command
      465│ 
      466│         if error is not None:
    → 467│             raise error
      468│ 
      469│         return event.exit_code

  5  ~/.poetry/venv/lib/python3.9/site-packages/cleo/application.py:451 in _run_command
      449│ 
      450│             if event.command_should_run():
    → 451│                 exit_code = command.run(io)
      452│             else:
      453│                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

  4  ~/.poetry/venv/lib/python3.9/site-packages/cleo/commands/base_command.py:118 in run
      116│         io.input.validate()
      117│ 
    → 118│         status_code = self.execute(io)
      119│ 
      120│         if status_code is None:

  3  ~/.poetry/venv/lib/python3.9/site-packages/cleo/commands/command.py:85 in execute
       83│ 
       84│         try:
    →  85│             return self.handle()
       86│         except KeyboardInterrupt:
       87│             return 1

  2  ~/.poetry/venv/lib/python3.9/site-packages/poetry/console/commands/add.py:139 in handle
      137│             return 0
      138│ 
    → 139│         requirements = self._determine_requirements(
      140│             packages,
      141│             allow_prereleases=self.option("allow-prereleases"),

  1  ~/.poetry/venv/lib/python3.9/site-packages/poetry/console/commands/init.py:352 in _determine_requirements
      350│                 # check that the specified version/constraint exists
      351│                 # before we proceed
    → 352│                 name, _ = self._find_best_version_for_package(
      353│                     requirement["name"],
      354│                     requirement["version"],

  ValueError

  Could not find a matching version of package scikit-learn

  at ~/.poetry/venv/lib/python3.9/site-packages/poetry/console/commands/init.py:381 in _find_best_version_for_package
      377│         )
      378│ 
      379│         if not package:
      380│             # TODO: find similar
    → 381│             raise ValueError(
      382│                 "Could not find a matching version of package {}".format(name)
      383│             )
      384│ 
      385│         return package.pretty_name, selector.find_recommended_require_version(package)

If scikit-learn = "^0" is added manually to the pyproject.toml, poetry install -vvv shows:

Using virtualenv: /Users/{USER_NAME}/Library/Caches/pypoetry/virtualenvs/poetry-bug-k1OA12gR-py3.9
Updating dependencies
Resolving dependencies...
   1: fact: poetry-bug is 0.1.0
   1: derived: poetry-bug
   1: fact: poetry-bug depends on scikit-learn (^0)
   1: selecting poetry-bug (0.1.0)
   1: derived: scikit-learn (>=0,<0.1)
   1: fact: no versions of scikit-learn match >=0,<0.1
   1: conflict: no versions of scikit-learn match >=0,<0.1
   1: ! scikit-learn (>=0,<0.1) is satisfied by scikit-learn (>=0,<0.1)
   1: ! which is caused by "poetry-bug depends on scikit-learn (^0)"
   1: ! thus: version solving failed
   1: Version solving took 0.040 seconds.
   1: Tried 1 solutions.

  Stack trace:

  4  ~/.poetry/venv/lib/python3.9/site-packages/poetry/puzzle/solver.py:138 in _solve
      136│ 
      137│         try:
    → 138│             result = resolve_version(
      139│                 self._package, self._provider, locked=locked, use_latest=use_latest
      140│             )

  3  ~/.poetry/venv/lib/python3.9/site-packages/poetry/mixology/__init__.py:24 in resolve_version
       22│     solver = VersionSolver(root, provider, locked=locked, use_latest=use_latest)
       23│ 
    →  24│     return solver.solve()
       25│ 

  2  ~/.poetry/venv/lib/python3.9/site-packages/poetry/mixology/version_solver.py:81 in solve
       79│             next = self._root.name
       80│             while next is not None:
    →  81│                 self._propagate(next)
       82│                 next = self._choose_package_version()
       83│ 

  1  ~/.poetry/venv/lib/python3.9/site-packages/poetry/mixology/version_solver.py:121 in _propagate
      119│                     # where that incompatibility will allow us to derive new assignments
      120│                     # that avoid the conflict.
    → 121│                     root_cause = self._resolve_conflict(incompatibility)
      122│ 
      123│                     # Back jumping erases all the assignments we did at the previous

  SolveFailure

  Because poetry-bug depends on scikit-learn (^0) which doesn't match any versions, version solving failed.

  at ~/.poetry/venv/lib/python3.9/site-packages/poetry/mixology/version_solver.py:315 in _resolve_conflict
      311│             )
      312│             self._log(f'{bang} which is caused by "{most_recent_satisfier.cause}"')
      313│             self._log(f"{bang} thus: {incompatibility}")
      314│ 
    → 315│         raise SolveFailure(incompatibility)
      316│ 
      317│     def _choose_package_version(self) -> Optional[str]:
      318│         """
      319│         Tries to select a version of a required package.

The following error occurred when trying to handle this error:


  Stack trace:

  11  ~/.poetry/venv/lib/python3.9/site-packages/cleo/application.py:330 in run
       328│ 
       329│             try:
     → 330│                 exit_code = self._run(io)
       331│             except Exception as e:
       332│                 if not self._catch_exceptions:

  10  ~/.poetry/venv/lib/python3.9/site-packages/poetry/console/application.py:180 in _run
       178│         self._load_plugins(io)
       179│ 
     → 180│         return super()._run(io)
       181│ 
       182│     def _configure_io(self, io: IO) -> None:

   9  ~/.poetry/venv/lib/python3.9/site-packages/cleo/application.py:425 in _run
       423│                 io.set_input(ArgvInput(argv))
       424│ 
     → 425│         exit_code = self._run_command(command, io)
       426│         self._running_command = None
       427│ 

   8  ~/.poetry/venv/lib/python3.9/site-packages/cleo/application.py:467 in _run_command
       465│ 
       466│         if error is not None:
     → 467│             raise error
       468│ 
       469│         return event.exit_code

   7  ~/.poetry/venv/lib/python3.9/site-packages/cleo/application.py:451 in _run_command
       449│ 
       450│             if event.command_should_run():
     → 451│                 exit_code = command.run(io)
       452│             else:
       453│                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

   6  ~/.poetry/venv/lib/python3.9/site-packages/cleo/commands/base_command.py:118 in run
       116│         io.input.validate()
       117│ 
     → 118│         status_code = self.execute(io)
       119│ 
       120│         if status_code is None:

   5  ~/.poetry/venv/lib/python3.9/site-packages/cleo/commands/command.py:85 in execute
        83│ 
        84│         try:
     →  85│             return self.handle()
        86│         except KeyboardInterrupt:
        87│             return 1

   4  ~/.poetry/venv/lib/python3.9/site-packages/poetry/console/commands/install.py:162 in handle
       160│         self._installer.verbose(self._io.is_verbose())
       161│ 
     → 162│         return_code = self._installer.run()
       163│ 
       164│         if return_code != 0:

   3  ~/.poetry/venv/lib/python3.9/site-packages/poetry/installation/installer.py:114 in run
       112│         local_repo = Repository()
       113│ 
     → 114│         return self._do_install(local_repo)
       115│ 
       116│     def dry_run(self, dry_run: bool = True) -> "Installer":

   2  ~/.poetry/venv/lib/python3.9/site-packages/poetry/installation/installer.py:251 in _do_install
       249│             )
       250│ 
     → 251│             ops = solver.solve(use_latest=self._whitelist).calculate_operations()
       252│         else:
       253│             self._io.write_line("Installing dependencies from lock file")

   1  ~/.poetry/venv/lib/python3.9/site-packages/poetry/puzzle/solver.py:77 in solve
        75│         with self._provider.progress():
        76│             start = time.time()
     →  77│             packages, depths = self._solve(use_latest=use_latest)
        78│             end = time.time()
        79│ 

  SolverProblemError

  Because poetry-bug depends on scikit-learn (^0) which doesn't match any versions, version solving failed.

  at ~/.poetry/venv/lib/python3.9/site-packages/poetry/puzzle/solver.py:146 in _solve
      142│             packages = result.packages
      143│         except OverrideNeeded as e:
      144│             return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
      145│         except SolveFailure as e:
    → 146│             raise SolverProblemError(e)
      147│ 
      148│         # NOTE passing explicit empty array for seen to reset between invocations during update + install cycle
      149│         results = dict(
      150│             depth_first_search(

In the above, it seems Poetry is searching for scikit-learn (>=0,<0.1) when given ^0. Whilst there is no scikit-learn=0.0.Z package, Poetry should actually search for scikit-learn (>=0,<1) according to the documentation.

@ESKYoung ESKYoung added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Mar 5, 2022
@ESKYoung
Copy link
Author

ESKYoung commented Mar 6, 2022

This seems to relate to issue #4153, and its related PR fix in python-poetry/poetry-core.

Looking at it, the fix was applied to poetry-core>=1.1.0a7, but the poetry.lock file in this repository is using poetry-core==1.1.0a6. Could this be updated for the next preview/release? Raised PR #5281 to resolve this.

@finswimmer
Copy link
Member

Ah, you found the related issue. 👍 I was sure this was reported earlier but couldn't found the issue anymore (github search is a mess ...)

The install-poetry.py installer script doesn't use the lock file. So you just have to reinstall the Poetry pre-release and poetry-core 1.1.0a7 will be picked up as a dependency.

@ESKYoung
Copy link
Author

ESKYoung commented Mar 6, 2022

Ah awesome, thanks @finswimmer — can confirm that this works now! 😄

I'll close this issue now — happy for the associated PR to be closed as well!

@ESKYoung ESKYoung closed this as completed Mar 6, 2022
@mkniewallner mkniewallner removed the status/triage This issue needs to be triaged label Jun 11, 2022
Copy link

github-actions bot commented Mar 1, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants