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 installs successfully a dependency via URL, but fails via local path #8682

Closed
4 tasks done
aaaaahaaaaa opened this issue Nov 16, 2023 · 7 comments · Fixed by #8692
Closed
4 tasks done

Poetry installs successfully a dependency via URL, but fails via local path #8682

aaaaahaaaaa opened this issue Nov 16, 2023 · 7 comments · Fixed by #8692
Labels
area/installer Related to the dependency installer kind/bug Something isn't working as expected

Comments

@aaaaahaaaaa
Copy link

  • Poetry version: 1.7.0
  • Python version: 3.10.12
  • OS version and name: MacOS 14.0
  • pyproject.toml:
  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

Poetry successfully installs a tar.gz served via a URL, but if the exact same dep/file is downloaded locally, then Poetry fails to install it. I'm very confused, I'm not sure I'm missing something blatantly obvious here.

Here is very straightforward way to reproduce:

Successful:

> poetry new teeeest
> cd teeeest
> poetry add https://developers.google.com/static/search-ads/reporting/download/python/searchads360-py.tar.gz

Fails:

> poetry remove google-ads-searchads360
> mkdir libs && wget https://developers.google.com/static/search-ads/reporting/download/python/searchads360-py.tar.gz -P libs
> poetry add libs/searchads360-py.tar.gz


Updating dependencies
Resolving dependencies... (5.5s)Path /var/folders/9g/r0mdzn2s7_l5cd3_2v_y6m6c0000gn/T/tmpwwsu787v/searchads360-py for google-ads-searchads360 does not exist
Path /var/folders/9g/r0mdzn2s7_l5cd3_2v_y6m6c0000gn/T/tmpwwsu787v/searchads360-py for google-ads-searchads360 does not exist
Path /var/folders/9g/r0mdzn2s7_l5cd3_2v_y6m6c0000gn/T/tmpwwsu787v/searchads360-py for google-ads-searchads360 does not exist
Path /var/folders/9g/r0mdzn2s7_l5cd3_2v_y6m6c0000gn/T/tmpwwsu787v/searchads360-py for google-ads-searchads360 does not exist
Path /var/folders/9g/r0mdzn2s7_l5cd3_2v_y6m6c0000gn/T/tmpwwsu787v/searchads360-py for google-ads-searchads360 does not exist


  OverrideNeeded

  ({Package('google-ads-searchads360', '0.0.1', source_type='directory', source_url='/var/folders/9g/r0mdzn2s7_l5cd3_2v_y6m6c0000gn/T/tmpwwsu787v/searchads360-py'): {'proto-plus': <Dependency proto-plus (>=1.22.2,<2.0.0dev)>}}, {Package('google-ads-searchads360', '0.0.1', source_type='directory', source_url='/var/folders/9g/r0mdzn2s7_l5cd3_2v_y6m6c0000gn/T/tmpwwsu787v/searchads360-py'): {'proto-plus': <Dependency proto-plus (>=1.19.4,<2.0.0dev)>}})

  at ~/.pyenv/versions/3.10.12/lib/python3.10/site-packages/poetry/puzzle/provider.py:660 in complete_package
      656│                     current_overrides.update({dependency_package: package_overrides})
      657│                     overrides.append(current_overrides)
      658│ 
      659│             if overrides:
    → 660│                 raise OverrideNeeded(*overrides)
      661│ 
      662│         # Modifying dependencies as needed
      663│         clean_dependencies = []
      664│         for dep in dependencies:

The following error occurred when trying to handle this error:


  AssertionError

  

  at ~/.pyenv/versions/3.10.12/lib/python3.10/site-packages/poetry/mixology/partial_solution.py:151 in _register
      147│         name = assignment.dependency.complete_name
      148│         old_positive = self._positive.get(name)
      149│         if old_positive is not None:
      150│             value = old_positive.intersect(assignment)
    → 151│             assert value is not None
      152│             self._positive[name] = value
      153│ 
      154│             return
      155│ 

And succesful again:

> python -m http.server 8888 --directory libs &
> poetry add http://localhost:8888/searchads360-py.tar.gz
@aaaaahaaaaa aaaaahaaaaa added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Nov 16, 2023
@dimbleby
Copy link
Contributor

installing a source distribution as a direct dependency seems to have been broken for years, if indeed it ever worked.

I guess no-one is doing that, and I recommend that you don't either!

@aaaaahaaaaa
Copy link
Author

I see. Thanks for clarifying that. It should be reflected in the documentation with a warning because it currently contains clear examples for doing just that.

@dimbleby
Copy link
Contributor

this has also been true for years, but feel free to submit a merge request

@dimbleby
Copy link
Contributor

I reckon this should fix it, if anyone wants this enough to write a testcase and submit a merge request:

diff --git a/src/poetry/inspection/info.py b/src/poetry/inspection/info.py
index 2e6875aa..9d317933 100644
--- a/src/poetry/inspection/info.py
+++ b/src/poetry/inspection/info.py
@@ -319,6 +319,8 @@ class PackageInfo:

             # now this is an unpacked directory we know how to deal with
             new_info = cls.from_directory(path=sdist_dir)
+            new_info._source_type = "file"
+            new_info._source_url = path.resolve().as_posix()

         if not info:
             return new_info

dimbleby added a commit to dimbleby/poetry that referenced this issue Nov 19, 2023
@dimbleby dimbleby mentioned this issue Nov 19, 2023
@radoering radoering added area/installer Related to the dependency installer and removed status/triage This issue needs to be triaged labels Nov 19, 2023
radoering pushed a commit to dimbleby/poetry that referenced this issue Nov 19, 2023
radoering pushed a commit that referenced this issue Nov 19, 2023
MrGreenTea pushed a commit to MrGreenTea/poetry that referenced this issue Dec 18, 2023
@f3flight
Copy link

f3flight commented Dec 21, 2023

@dimbleby I ran into the same issue recently and I tried using the fixed code and somehow it doesn't help. Moreover, even if use a local wheel instead of sdist, it fails with the same AssertionError for me. It only happens on some MacOS hosts, somehow. Works fine on Linux. The command which fails is poetry add --lock -G dev <path-to-local-file>. Something else might be going on for me, I will try to debug - but the exception is from the same place in the code.

@f3flight
Copy link

f3flight commented Jan 17, 2024

@dimbleby, @radoering, @aaaaahaaaaa - here are my findings and some FYI:

Env is MacOS 14.x.
Command is poetry add --lock -G dev <path-to-sdist-OR-wheel>

I have found that if path contains symlinks, then the command fails no matter if I provide sdist or wheel, with the same AssertionError as originally reported. Somewhere in the process of resolution poetry resolves the path, and then compares 2 objects of type FileDependency, where one has a resolved _dependency.path, while other doesn't (if path contains one or more symlinks). This causes it to fail because it thinks these two dependencies are different, and therefore this line

value = old_positive.intersect(assignment)
gives a None.

I should mention that my use case is a testing scenario where the dependency is already present as a normal dependency, but I'm overriding it by "adding" a different version of it from a file, as a dev dependency (because adding to normal dependencies from a file is not allowed). This is part of a compatibility testing workflow I'm working on.

I think the code should be changed somewhere to always resolve path before comparing, maybe FileDependency init should be modified (it's in poetry-core project), or somewhere else - I'm not sure where the deviation and existing resolving happens so cannot really come up with the best solution.

For my use case I have modified my script to resolve the path before calling poetry, which solved the problem for me.

Copy link

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 Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/installer Related to the dependency installer kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants