Skip to content

Commit

Permalink
Merge pull request #138 from wimglenn/v1.20.5
Browse files Browse the repository at this point in the history
pip>24 support
  • Loading branch information
wimglenn authored Jul 2, 2024
2 parents 102db09 + 6be8b72 commit 2ae919d
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ jobs:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
include:
- os: ubuntu-latest
python-version: "3.7"
Expand All @@ -32,6 +34,7 @@ jobs:
- name: Install dependencies
run: |
python -VV
python -m pip install -U pip
python -m pip install -r requirements-dev.txt
- name: Run tests for ${{ matrix.python-version }} on ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion johnnydep/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Display dependency tree of Python distribution"""

__version__ = "1.20.4"
__version__ = "1.20.5"

from johnnydep.lib import *
44 changes: 44 additions & 0 deletions johnnydep/pipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,50 @@ def _download_dist(url, scratch_file, index_url, extra_index_url):
def get_versions(dist_name, index_url=None, env=None, extra_index_url=None):
bare_name = requirements.Requirement(dist_name).name
log.debug("checking versions available", dist=bare_name)
if env is None:
pip_version = _get_pip_version()
else:
pip_version = dict(env)["pip_version"]
if int(pip_version.split(".")[0]) < 24:
return _get_versions_legacy(dist_name, index_url, env, extra_index_url)
args = [
sys.executable,
"-m",
"pip",
"index",
"versions",
"--pre",
"--no-cache-dir",
"--disable-pip-version-check",
"--no-color",
"--no-python-version-warning"
]
if index_url is not None:
args += ["--index-url", index_url]
if index_url != DEFAULT_INDEX:
hostname = urlparse(index_url).hostname
if hostname:
args += ["--trusted-host", hostname]
if extra_index_url is not None:
args += ["--extra-index-url", extra_index_url, "--trusted-host", urlparse(extra_index_url).hostname]
args.append(dist_name)
try:
out = check_output(args, stderr=STDOUT).decode("utf-8")
except CalledProcessError as e:
out = e.output.decode("utf-8")
if "ERROR: No matching distribution found for" in out:
return []
raise
for line in out.splitlines():
if line.startswith("Available versions: "):
versions = line[len("Available versions: "):].strip().split(", ")[::-1]
log.debug("found versions", dist=bare_name, versions=versions)
return versions


@ttl_cache(maxsize=512, ttl=60 * 5)
def _get_versions_legacy(dist_name, index_url=None, env=None, extra_index_url=None):
bare_name = requirements.Requirement(dist_name).name
args = _get_wheel_args(index_url, env, extra_index_url) + [dist_name + "==showmethemoney"]
try:
out = check_output(args, stderr=STDOUT)
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ coverage
wheel
whl >= 0.0.4
wimpy == 0.3 # just something we can pin
setuptools; python_version >= '3.12'
38 changes: 27 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@pytest.fixture(autouse=True)
def expire_caches():
pipper.get_versions.cache_clear()
pipper._get_versions_legacy.cache_clear()
pipper._get_cache.clear()
lib._get_info.cache_clear()

Expand Down Expand Up @@ -153,17 +154,32 @@ def fake_subprocess(mocker, add_to_index):
def wheel_proc(args, stderr, cwd=None):
exe = args[0]
req = args[-1]
args = [
exe,
"-m",
"pip",
"wheel",
"-vvv",
"--no-index",
"--no-deps",
"--no-cache-dir",
"--disable-pip-version-check",
]
if "versions" in args:
args = [
exe,
"-m",
"pip",
"index",
"versions",
"--pre",
"--no-index",
"--no-cache-dir",
"--disable-pip-version-check",
"--no-color",
"--no-python-version-warning"
]
else:
args = [
exe,
"-m",
"pip",
"wheel",
"-vvv",
"--no-index",
"--no-deps",
"--no-cache-dir",
"--disable-pip-version-check",
]
args.extend(["--find-links={}".format(p) for p in index_data])
args.append(req)
output = subprocess_check_output(args, stderr=stderr, cwd=cwd)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_good_python_env():
data = python_interpreter(sys.executable)
assert isinstance(data, tuple)
data = dict(data)
for value in data.values():
assert isinstance(value, text_type)
for key, value in data.items():
assert isinstance(value, text_type), key
assert sorted(data) == [
"implementation_name",
"implementation_version",
Expand Down

0 comments on commit 2ae919d

Please sign in to comment.