Skip to content

"poetry build" generates wheel with invalid Requires-Dist URL when pyproject.toml specifies dependency by path #3899

@alangefe

Description

@alangefe
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expectedstatus/triageThis issue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions