Skip to content

Commit 9a6ccd8

Browse files
Add fallback for pure python source distributions
pip download will give you a .tar.gz even if you remove the --only-binary options. There is some risk here the you will get a whl for your host platform. I took an allowlist approach in alexgartner-bc/rules_pip@acd9b01 but I don't really want to maintain that.
1 parent fe33a45 commit 9a6ccd8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

python/pip_install/tools/wheel_installer/wheel_installer.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,10 @@ def main() -> None:
155155

156156
_configure_reproducible_wheels()
157157

158+
base_pip_args = [sys.executable, "-m", "pip"]
159+
158160
pip_args = (
159-
[sys.executable, "-m", "pip"]
161+
base_pip_args
160162
+ (["--isolated"] if args.isolated else [])
161163
+ (["download", "--only-binary=:all:"] if args.download_only else ["wheel"])
162164
+ ["--no-deps"]
@@ -172,12 +174,19 @@ def main() -> None:
172174
requirement_file.close()
173175
# Requirement specific args like --hash can only be passed in a requirements file,
174176
# so write our single requirement into a temp file in case it has any of those flags.
175-
pip_args.extend(["-r", requirement_file.name])
177+
requirement_file_args = ["-r", requirement_file.name]
178+
pip_args.extend(requirement_file_args)
176179

177180
env = os.environ.copy()
178181
env.update(deserialized_args["environment"])
179182
# Assumes any errors are logged by pip so do nothing. This command will fail if pip fails
180-
subprocess.run(pip_args, check=True, env=env)
183+
check = not args.download_only
184+
res = subprocess.run(pip_args, check=check, env=env)
185+
# fallback for source distributable
186+
if res.returncode != 0:
187+
pip_cmd = base_pip_args + ["wheel", "--no-deps"] + requirement_file_args
188+
subprocess.run(pip_cmd, check=True, env=env)
189+
181190
finally:
182191
try:
183192
os.unlink(requirement_file.name)

0 commit comments

Comments
 (0)