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

Merged
Merged
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 @@ -93,6 +93,8 @@ END_UNRELEASED_TEMPLATE
also retrieved from the URL as opposed to only the `--hash` parameter. Fixes
[#2363](https://github.com/bazel-contrib/rules_python/issues/2363).
* (pypi) `whl_library` now infers file names from its `urls` attribute correctly.
* (pypi) When running under `bazel test`, be sure that temporary `requirements` file
remains writable.
* (py_test, py_binary) Allow external files to be used for main

{#v0-0-0-added}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,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 f"bazel run {target_label_prefix}.update"
Expand Down