From 1b5c9f5d2f4bd483eece313085a8c9eecee0cef4 Mon Sep 17 00:00:00 2001 From: Zoran Simic Date: Wed, 15 Mar 2023 20:31:03 -0700 Subject: [PATCH 1/2] Loosen entry point checking to support non-wrapped executables --- src/pickley/package.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pickley/package.py b/src/pickley/package.py index 01842c7..faf0a8b 100644 --- a/src/pickley/package.py +++ b/src/pickley/package.py @@ -218,10 +218,15 @@ def is_venv_exe(self, path): Returns: (bool): True if 'path' points to a python executable part of this venv """ + path = runez.to_path(path) if runez.is_executable(path): + if path.stat().st_size > 1024: + # Some pypi packages started delivering full-blown executables (like 'ruff', a pypi package written in rust) + return True + for line in runez.readlines(path, first=1): if line.startswith("#!"): - if path.startswith(self.folder): + if path.parent == runez.to_path(self.folder): return True def pip_install(self, *args): From 8ee9185155bf51d8216fbd57fac2771591ff16d8 Mon Sep 17 00:00:00 2001 From: Zoran Simic Date: Wed, 15 Mar 2023 21:03:17 -0700 Subject: [PATCH 2/2] Trust pip show -f, don't double-check --- src/pickley/package.py | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/pickley/package.py b/src/pickley/package.py index faf0a8b..2f16ec6 100644 --- a/src/pickley/package.py +++ b/src/pickley/package.py @@ -52,7 +52,7 @@ def __init__(self, venv): self.files = None self.info = {} name = venv.pspec.dashed - if runez.DRYRUN and not venv.is_venv_exe("bin/pip"): + if runez.DRYRUN and not runez.is_executable("bin/pip"): self.bin.files = {venv.pspec.dashed: "dryrun"} # Pretend an entry point exists in dryrun mode return @@ -84,7 +84,7 @@ def __init__(self, venv): if "_completer" in basename: self.completers.add_file(path) - elif venv.is_venv_exe(path): + elif runez.is_executable(path): self.bin.add_file(path) elif dirname.endswith(".dist-info"): @@ -210,25 +210,6 @@ def bin_path(self, name, try_variant=False): if os.path.exists(path): return path - def is_venv_exe(self, path): - """ - Args: - path (str): Path to file to examine - - Returns: - (bool): True if 'path' points to a python executable part of this venv - """ - path = runez.to_path(path) - if runez.is_executable(path): - if path.stat().st_size > 1024: - # Some pypi packages started delivering full-blown executables (like 'ruff', a pypi package written in rust) - return True - - for line in runez.readlines(path, first=1): - if line.startswith("#!"): - if path.parent == runez.to_path(self.folder): - return True - def pip_install(self, *args): """Allows to not forget to state the -i index...""" r = self.run_pip("install", "-i", self.pspec.index, *args, fatal=False)