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 build" generates wheel with invalid Requires-Dist URL when pyproject.toml specifies dependency by path #3899

Closed
2 of 3 tasks
alangefe opened this issue Apr 8, 2021 · 5 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@alangefe
Copy link

alangefe commented Apr 8, 2021

  • I am on the latest Poetry version.

  • 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: Ubuntu 20.04

  • Poetry version: 1.1.5

Issue

I am using poetry to build a wheel for a particular project intended to be installed via pip. One of the project's dependencies is itself a local wheel, so pyproject.toml uses the path specification for that dependency like so:

[tool.poetry.dependencies]
my-dependency = {path = "my_dependency-0.1.0-py3-none-any.whl"}

When I attempt to use pip to install the wheel generated by poetry build, it fails, and pkg_resources complains that the dependency has an invalid URL. For example:

$ pip3 install -t ~/my_dist ./my_project-0.1.0-py3-none-any.whl 
Processing ./my_project-0.1.0-py3-none-any.whl
ERROR: Exception:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3023, in _dep_map
    return self.__dep_map
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2817, in __getattr__
    raise AttributeError(attr)
AttributeError: _DistInfoDistribution__dep_map

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3103, in __init__
    super(Requirement, self).__init__(requirement_string)
  File "/usr/lib/python3/dist-packages/pkg_resources/_vendor/packaging/requirements.py", line 101, in __init__
    raise InvalidRequirement("Invalid URL given")
pkg_resources.extern.packaging.requirements.InvalidRequirement: Invalid URL given

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/base_command.py", line 186, in _main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 357, in run
    resolver.resolve(requirement_set)
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 177, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 382, in _resolve_one
    set(req_to_install.extras) - set(dist.extras)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2980, in extras
    return [dep for dep in self._dep_map if dep]
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3025, in _dep_map
    self.__dep_map = self._compute_dependencies()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3035, in _compute_dependencies
    reqs.extend(parse_requirements(req))
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3096, in parse_requirements
    yield Requirement(line)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3105, in __init__
    raise RequirementParseError(str(e))
pkg_resources.RequirementParseError: Invalid URL given

In poetry 1.1.5, the Requires-Dist line that poetry generates in the wheel's METADATA file looks like this:

Requires-Dist: my-dependency @ my_dependency-0.1.0-py3-none-any.whl

This issue seems to have been introduced in poetry 1.1. For example, in poetry 1.0.10, the @ and following text was not generated, and pkg_resources handles the requirement just fine:

Requires-Dist: my-dependency

To replicate:

  1. In a poetry project, add a local wheel as a dependency. For example: poetry add ./my_dependency-0.1.0-py3-none-any.whl (In poetry 1.0.10, I found I had to put an absolute path in the pyproject.toml file or the poetry build step below would fail. But that's not needed in poetry 1.1.5.)
  2. Build a wheel for the project using poetry build.
  3. Try to install the wheel with pip using something like pip3 install -t <path> dist/my_project-0.1.0-py3-none-any.whl. This will fail with the "Invalid URL" exception.
@mvaled
Copy link

mvaled commented Apr 17, 2022

I'm also affected by this issue. Any progress?

@abn
Copy link
Member

abn commented Apr 17, 2022

@mvaled something like this should resolve this issue.

[tool.poetry.dependencies]
my-dependency = "^0.1"

[tool.poetry.dev-dependencies]
my-dependency = {path = "my_dependency-0.1.0-py3-none-any.whl"}

@blakehawkins
Copy link

blakehawkins commented Nov 22, 2022

@abn that didn't resolve it for me unfortunately

It looks like this is not being prioritised?

Edit: abn's solution works if you pip install my-dependency.whl before installing the project

@neersighted
Copy link
Member

Everything is a "priority," but contributors are volunteers and some tasks have higher priorities than others. This is a duplicate of #5273 which is solved in our upcoming release.

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 status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

5 participants