Skip to content

fix(pypi): allow pip_compile to work with read-only sources #2712

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Unreleased changes template.
* (toolchains) Remove all but `3.8.20` versions of the Python `3.8` interpreter who has
reached EOL. If users still need other versions of the `3.8` interpreter, please supply
the URLs manually {bzl:ob}`python.toolchain` or {bzl:obj}`python_register_toolchains` calls.
* (pypi) When running under `bazel test`, be sure that temporary `requirements` file
remains writable.

[20250317]: https://github.com/astral-sh/python-build-standalone/releases/tag/20250317

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,16 @@ def main(
requirements_out = os.path.join(
os.environ["TEST_TMPDIR"], os.path.basename(requirements_file) + ".out"
)
# Why this uses shutil.copyfileobj:
#
# Those two files won't necessarily be on the same filesystem, so we can't use os.replace
# or shutil.copyfile, as they will fail with OSError: [Errno 18] Invalid cross-device link.
shutil.copy(resolved_requirements_file, requirements_out)
#
# Further, shutil.copy preserves the source file's mode, and so if
# our source file is read-only (the default under Perforce Helix),
# this scratch file will also be read-only, defeating its purpose.
with open(resolved_requirements_file, "rb") as fsrc, open(requirements_out, "wb") as fdst:
shutil.copyfileobj(fsrc, fdst)

update_command = os.getenv("CUSTOM_COMPILE_COMMAND") or "bazel run %s" % (
update_target_label,
Expand Down