Skip to content

Commit

Permalink
fix regression w/ pip 23.3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
wimglenn committed Dec 4, 2023
1 parent 5770e9f commit 6df2a5b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
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.3"
__version__ = "1.20.4"

from johnnydep.lib import *
48 changes: 34 additions & 14 deletions johnnydep/pipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@

def compute_checksum(target, algorithm="sha256", blocksize=2 ** 13):
hashtype = getattr(hashlib, algorithm)
hash_ = hashtype()
if algorithm == "blake2b":
hash_ = hashtype(digest_size=32)
else:
hash_ = hashtype()
log.debug("computing checksum", target=target, algorithm=algorithm)
with open(target, "rb") as f:
for chunk in iter(lambda: f.read(blocksize), b""):
Expand Down Expand Up @@ -150,19 +153,7 @@ def _cache_key(dist_name, index_url=None, env=None, extra_index_url=None, tmpdir
_get_cache = TTLCache(maxsize=512, ttl=60 * 5)


@cached(_get_cache, key=_cache_key)
def get(dist_name, index_url=None, env=None, extra_index_url=None, tmpdir=None, ignore_errors=False):
args = _get_wheel_args(index_url, env, extra_index_url) + [dist_name]
scratch_dir = tempfile.mkdtemp(dir=tmpdir)
log.debug("wheeling and dealing", scratch_dir=os.path.abspath(scratch_dir), args=" ".join(args))
try:
out = check_output(args, stderr=STDOUT, cwd=scratch_dir).decode("utf-8")
except CalledProcessError as err:
out = getattr(err, "output", b"").decode("utf-8")
log.warning(out)
if not ignore_errors:
raise
log.debug("wheel command completed ok", dist_name=dist_name)
def _extract_links_from_pip_log(out):
links = []
local_links = []
lines = out.splitlines()
Expand Down Expand Up @@ -200,6 +191,35 @@ def get(dist_name, index_url=None, env=None, extra_index_url=None, tmpdir=None,
if not links:
# prefer http scheme over file
links += local_links
return links


@cached(_get_cache, key=_cache_key)
def get(dist_name, index_url=None, env=None, extra_index_url=None, tmpdir=None, ignore_errors=False):
args = _get_wheel_args(index_url, env, extra_index_url) + [dist_name]
scratch_dir = tempfile.mkdtemp(dir=tmpdir)
log.debug("wheeling and dealing", scratch_dir=os.path.abspath(scratch_dir), args=" ".join(args))
try:
out = check_output(args, stderr=STDOUT, cwd=scratch_dir).decode("utf-8")
except CalledProcessError as err:
out = getattr(err, "output", b"").decode("utf-8")
log.warning(out)
if not ignore_errors:
raise
log.debug("wheel command completed ok", dist_name=dist_name)
links = []
try:
[whl] = glob(os.path.join(os.path.abspath(scratch_dir), "*.whl"))
except ValueError:
pass
else:
b2b = compute_checksum(whl, "blake2b")
path = "/".join([b2b[:2], b2b[2:4], b2b[4:], os.path.basename(whl)])
urls = {x for x in out.split() if x.startswith("http") and x.endswith(path)}
if len(urls) == 1:
links = list(urls)
if not links:
links = _extract_links_from_pip_log(out)
links = list(dict.fromkeys(links)) # order-preserving dedupe
links = [link for link in links if "/" in link and not link.endswith(".metadata")]
if not links:
Expand Down

0 comments on commit 6df2a5b

Please sign in to comment.