Skip to content

Unable to specify a VCS-via-file URL #412

@uranusjr

Description

@uranusjr

Say I have a Git repoitory locally on /path/to/repo, it is currently not possible to specify a package in it:

>>> from packaging.requirements import Requirement
>>> Requirement("mypackage @ git+file:///path/to/repo")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "packaging/requirements.py", line 130, in __init__
    raise InvalidRequirement("Invalid URL: {0}".format(req.url))
packaging.requirements.InvalidRequirement: Invalid URL: git+file:///path/to/repo

This is because the Requirement class currently ensures the URL contains netloc:

elif not (parsed_url.scheme and parsed_url.netloc) or (
not parsed_url.scheme and not parsed_url.netloc
):
raise InvalidRequirement(f"Invalid URL: {req.url}")

IMO the class should not perform any validation, since PEP 508 does not in any restrict what qualifies as a URL, and any decision on what URLs to support falls entirely on the caller. At the very least, it should allow the caller to provide a custom validator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions