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

Manually parse URL without depending on packaging #1071

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading