Skip to content

Commit

Permalink
Manually parse URL without depending on packaging (#1071)
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Oct 2, 2023
1 parent 271d0f1 commit 9f6ede6
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/pipx/package_specifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import logging
import re
import urllib.parse
from pathlib import Path
from typing import List, NamedTuple, Optional, Set, Tuple

Expand Down Expand Up @@ -73,24 +74,17 @@ def _parse_specifier(package_spec: str) -> ParsedPackage:
else:
raise PipxError(f"{package_path} does not exist")

# packaging currently (2020-07-19) only does basic syntax checks on URL.
# Some examples of what it will not catch:
# - invalid RCS string (e.g. "gat+https://...")
# - non-existent scheme (e.g. "zzzzz://...")
# If this looks like a URL, treat it as such.
if not valid_pep508:
try:
package_req = Requirement("notapackagename @ " + package_spec)
except InvalidRequirement:
# not a valid url
pass
else:
parsed_url = urllib.parse.urlsplit(package_spec)
if parsed_url.scheme and parsed_url.netloc:
valid_url = package_spec

# Treat the input as a local path if it does not look like a PEP 508
# specifier nor a URL. In this case we want to split out the extra part.
if not valid_pep508 and not valid_url:
(package_path_str, package_extras_str) = _split_path_extras(package_spec)

(package_path, package_path_exists) = _check_package_path(package_path_str)

if package_path_exists:
valid_local_path = str(package_path.resolve()) + package_extras_str

Expand Down

1 comment on commit 9f6ede6

@ericfrederich
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to come here and thank @uranusjr for fixing this...

I must have created a new VM between 2023-10-01 when packaging==23.2 was released and broke this, and 2023-10-23 when this got backported into pipx==1.2.1 or 2023-12-02 when it got released with pipx==1.3.0.
The unfortunate window where there was an incompatibility.

... but then I saw it was also the same person who created the offending commit within packaging in the first place ;-)
pypa/packaging@fe8f0bb

Please sign in to comment.