Skip to content

Invoking bazel with a different PATH re-fetches pip_repository #2551

@Ubehebe

Description

@Ubehebe

🐞 bug report

Forked from #2283 (comment)

Affected Rule

The issue is caused by the rule: pip_repository

Is this a regression?

Yes, the previous version in which this bug was not present was: ~0.32.2

Description

I run bazel build ... from a git pre-commit hook as part of my development workflow. Although it is not well-documented, git modifies the PATH env var when running hooks. (You can see this for yourself by putting echo "$PATH" in a pre-commit hook, then comparing the output of git hook run pre-commit versus running the hook script directly.)

Meanwhile, since #2000, the pip_repository rule has internal code that calls repository_ctx.getenv("PATH"): https://github.com/bazelbuild/rules_python/blob/main/python/private/repo_utils.bzl#L271. repository_ctx.getenv is documented:

any change to the value of the variable named by name will cause this repository to be re-fetched.

Putting the git and rules_python behaviors together causes the bug. Doing a bazel build ... directly and then doing it indirectly via git hook run pre-commit re-fetches the pip_repository. (The reverse order also works.)

🔬 Minimal Reproduction

https://github.com/Ubehebe/rules_python_2283_mvce

🔥 Exception or Error

Console messages printed when pip_repository is unexpectedly re-fetched. Example:

Collecting pandas==2.1.4 (from -r /var/folders/28/qqqxx4y55dz08x1bzcc9z7jm0000gn/T/tmpyann5bc8 (line 1))

🌍 Your Environment

Operating System:

$ uname -a
Darwin 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:11 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6020 arm64

Output of bazel version:

Bazelisk version: development
Build label: 8.0.0
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Mon Dec 09 18:02:00 2024 (1733767320)
Build timestamp: 1733767320
Build timestamp as int: 1733767320

Rules_python version:

1.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions