Skip to content

Commit b1c543d

Browse files
committed
initial commit: minimal repro of rules_python/issues/2283.
bazel-contrib/rules_python#2283.
0 parents  commit b1c543d

File tree

11 files changed

+3265
-0
lines changed

11 files changed

+3265
-0
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
common --incompatible_strict_action_env

.bazelversion

Whitespace-only changes.

BUILD

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
load("@rules_python//python:defs.bzl", "py_binary")
2+
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
3+
4+
compile_pip_requirements(
5+
name = "requirements",
6+
requirements_in = "requirements.in",
7+
requirements_txt = "requirements.txt",
8+
)
9+
10+
py_binary(
11+
name = "main",
12+
srcs = [
13+
"main.py",
14+
],
15+
deps = [
16+
"@pip//pandas:pkg",
17+
],
18+
)

MODULE.bazel

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module(
2+
name = "rules_python_2283_mvce",
3+
)
4+
5+
bazel_dep(
6+
name = "rules_python",
7+
version = "1.0.0",
8+
)
9+
10+
python_version = "3.12.3"
11+
12+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
13+
python.toolchain(
14+
is_default = True,
15+
python_version = python_version,
16+
)
17+
18+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
19+
20+
# Install all python deps, using the python interpreter above.
21+
# For each package foo listed in requirements.txt, this creates a @pip_foo repo
22+
# with a top-level :pkg py_library target.
23+
pip.parse(
24+
hub_name = "pip",
25+
python_version = python_version,
26+
quiet = False,
27+
requirements_lock = ":requirements.txt",
28+
)
29+
use_repo(pip, "pip")

MODULE.bazel.lock

Lines changed: 3077 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
This repo demonstrates the python toolchain cache invalidation from
2+
https://github.com/bazelbuild/rules_python/issues/2283.
3+
4+
## Overview
5+
The repo contains a trivial python script (`main.py`) that imports a package from pip.
6+
A python toolchain is configured using the latest versions of bazel (8.0.0) and rules_python
7+
(1.0.0).
8+
9+
`pre-commit.sh` is a git pre-commit hook, used to abort a commit if any target fails to build.
10+
11+
## Setup
12+
13+
1. Clone the repo
14+
2. Symlink `pre-commit.sh` to `.git/hooks/pre-commit`
15+
3. `bazel build ...`
16+
4. Make a change to the repo that bazel won't notice (e.g. edit README.md). This is just to
17+
convince git to run the pre-commit hook in the next step.
18+
5. `git commit -am "some message"`
19+
20+
## Expected results
21+
22+
The first build, in step 3, should print messages like this:
23+
24+
```
25+
Collecting pandas==2.1.4 (from -r /var/folders/28/qqqxx4y55dz08x1bzcc9z7jm0000gn/T/tmpyann5bc8 (line 1))
26+
```
27+
28+
The second build, called from the pre-commit hook in step 5, shouldn't print any of these messages,
29+
since the packages should already be cached.
30+
31+
## Observed results
32+
33+
The second build does print `Collecting pandas` messages, showing that the package cache is
34+
invalidated.

bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.0.0

main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from pandas import DataFrame
2+
3+
# This script doesn't do anything. i just needed a dependency on a pip package to exhibit
4+
# https://github.com/bazelbuild/rules_python/issues/2283.
5+
if __name__ == "__main__":
6+
print(f"{DataFrame}")

pre-commit.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
# pre-commit hook. ln -s this to .git/hooks/pre-commit.
4+
5+
set -x
6+
7+
# when this script is run as a git hook, git sets GIT_EXEC_PATH automatically.
8+
# when this script is run directly, this should not be set.
9+
env | grep GIT_EXEC_PATH
10+
11+
bazel build ...

requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pandas==2.1.4

requirements.txt

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.12
3+
# by the following command:
4+
#
5+
# bazel run //:requirements.update
6+
#
7+
numpy==1.26.4 \
8+
--hash=sha256:03a8c78d01d9781b28a6989f6fa1bb2c4f2d51201cf99d3dd875df6fbd96b23b \
9+
--hash=sha256:08beddf13648eb95f8d867350f6a018a4be2e5ad54c8d8caed89ebca558b2818 \
10+
--hash=sha256:1af303d6b2210eb850fcf03064d364652b7120803a0b872f5211f5234b399f20 \
11+
--hash=sha256:1dda2e7b4ec9dd512f84935c5f126c8bd8b9f2fc001e9f54af255e8c5f16b0e0 \
12+
--hash=sha256:2a02aba9ed12e4ac4eb3ea9421c420301a0c6460d9830d74a9df87efa4912010 \
13+
--hash=sha256:2e4ee3380d6de9c9ec04745830fd9e2eccb3e6cf790d39d7b98ffd19b0dd754a \
14+
--hash=sha256:3373d5d70a5fe74a2c1bb6d2cfd9609ecf686d47a2d7b1d37a8f3b6bf6003aea \
15+
--hash=sha256:47711010ad8555514b434df65f7d7b076bb8261df1ca9bb78f53d3b2db02e95c \
16+
--hash=sha256:4c66707fabe114439db9068ee468c26bbdf909cac0fb58686a42a24de1760c71 \
17+
--hash=sha256:50193e430acfc1346175fcbdaa28ffec49947a06918b7b92130744e81e640110 \
18+
--hash=sha256:52b8b60467cd7dd1e9ed082188b4e6bb35aa5cdd01777621a1658910745b90be \
19+
--hash=sha256:60dedbb91afcbfdc9bc0b1f3f402804070deed7392c23eb7a7f07fa857868e8a \
20+
--hash=sha256:62b8e4b1e28009ef2846b4c7852046736bab361f7aeadeb6a5b89ebec3c7055a \
21+
--hash=sha256:666dbfb6ec68962c033a450943ded891bed2d54e6755e35e5835d63f4f6931d5 \
22+
--hash=sha256:675d61ffbfa78604709862923189bad94014bef562cc35cf61d3a07bba02a7ed \
23+
--hash=sha256:679b0076f67ecc0138fd2ede3a8fd196dddc2ad3254069bcb9faf9a79b1cebcd \
24+
--hash=sha256:7349ab0fa0c429c82442a27a9673fc802ffdb7c7775fad780226cb234965e53c \
25+
--hash=sha256:7ab55401287bfec946ced39700c053796e7cc0e3acbef09993a9ad2adba6ca6e \
26+
--hash=sha256:7e50d0a0cc3189f9cb0aeb3a6a6af18c16f59f004b866cd2be1c14b36134a4a0 \
27+
--hash=sha256:95a7476c59002f2f6c590b9b7b998306fba6a5aa646b1e22ddfeaf8f78c3a29c \
28+
--hash=sha256:96ff0b2ad353d8f990b63294c8986f1ec3cb19d749234014f4e7eb0112ceba5a \
29+
--hash=sha256:9fad7dcb1aac3c7f0584a5a8133e3a43eeb2fe127f47e3632d43d677c66c102b \
30+
--hash=sha256:9ff0f4f29c51e2803569d7a51c2304de5554655a60c5d776e35b4a41413830d0 \
31+
--hash=sha256:a354325ee03388678242a4d7ebcd08b5c727033fcff3b2f536aea978e15ee9e6 \
32+
--hash=sha256:a4abb4f9001ad2858e7ac189089c42178fcce737e4169dc61321660f1a96c7d2 \
33+
--hash=sha256:ab47dbe5cc8210f55aa58e4805fe224dac469cde56b9f731a4c098b91917159a \
34+
--hash=sha256:afedb719a9dcfc7eaf2287b839d8198e06dcd4cb5d276a3df279231138e83d30 \
35+
--hash=sha256:b3ce300f3644fb06443ee2222c2201dd3a89ea6040541412b8fa189341847218 \
36+
--hash=sha256:b97fe8060236edf3662adfc2c633f56a08ae30560c56310562cb4f95500022d5 \
37+
--hash=sha256:bfe25acf8b437eb2a8b2d49d443800a5f18508cd811fea3181723922a8a82b07 \
38+
--hash=sha256:cd25bcecc4974d09257ffcd1f098ee778f7834c3ad767fe5db785be9a4aa9cb2 \
39+
--hash=sha256:d209d8969599b27ad20994c8e41936ee0964e6da07478d6c35016bc386b66ad4 \
40+
--hash=sha256:d5241e0a80d808d70546c697135da2c613f30e28251ff8307eb72ba696945764 \
41+
--hash=sha256:edd8b5fe47dab091176d21bb6de568acdd906d1887a4584a15a9a96a1dca06ef \
42+
--hash=sha256:f870204a840a60da0b12273ef34f7051e98c3b5961b61b0c2c1be6dfd64fbcd3 \
43+
--hash=sha256:ffa75af20b44f8dba823498024771d5ac50620e6915abac414251bd971b4529f
44+
# via pandas
45+
pandas==2.1.4 \
46+
--hash=sha256:00028e6737c594feac3c2df15636d73ace46b8314d236100b57ed7e4b9ebe8d9 \
47+
--hash=sha256:0aa6e92e639da0d6e2017d9ccff563222f4eb31e4b2c3cf32a2a392fc3103c0d \
48+
--hash=sha256:1ebfd771110b50055712b3b711b51bee5d50135429364d0498e1213a7adc2be8 \
49+
--hash=sha256:294d96cfaf28d688f30c918a765ea2ae2e0e71d3536754f4b6de0ea4a496d034 \
50+
--hash=sha256:3f06bda01a143020bad20f7a85dd5f4a1600112145f126bc9e3e42077c24ef34 \
51+
--hash=sha256:426dc0f1b187523c4db06f96fb5c8d1a845e259c99bda74f7de97bd8a3bb3139 \
52+
--hash=sha256:45d63d2a9b1b37fa6c84a68ba2422dc9ed018bdaa668c7f47566a01188ceeec1 \
53+
--hash=sha256:482d5076e1791777e1571f2e2d789e940dedd927325cc3cb6d0800c6304082f6 \
54+
--hash=sha256:6b728fb8deba8905b319f96447a27033969f3ea1fea09d07d296c9030ab2ed1d \
55+
--hash=sha256:8a706cfe7955c4ca59af8c7a0517370eafbd98593155b48f10f9811da440248b \
56+
--hash=sha256:8ea107e0be2aba1da619cc6ba3f999b2bfc9669a83554b1904ce3dd9507f0860 \
57+
--hash=sha256:ab5796839eb1fd62a39eec2916d3e979ec3130509930fea17fe6f81e18108f6a \
58+
--hash=sha256:b0513a132a15977b4a5b89aabd304647919bc2169eac4c8536afb29c07c23540 \
59+
--hash=sha256:b7d852d16c270e4331f6f59b3e9aa23f935f5c4b0ed2d0bc77637a8890a5d092 \
60+
--hash=sha256:bd7d5f2f54f78164b3d7a40f33bf79a74cdee72c31affec86bfcabe7e0789821 \
61+
--hash=sha256:bdec823dc6ec53f7a6339a0e34c68b144a7a1fd28d80c260534c39c62c5bf8c9 \
62+
--hash=sha256:d2d3e7b00f703aea3945995ee63375c61b2e6aa5aa7871c5d622870e5e137623 \
63+
--hash=sha256:d65148b14788b3758daf57bf42725caa536575da2b64df9964c563b015230984 \
64+
--hash=sha256:d797591b6846b9db79e65dc2d0d48e61f7db8d10b2a9480b4e3faaddc421a171 \
65+
--hash=sha256:dc9bf7ade01143cddc0074aa6995edd05323974e6e40d9dbde081021ded8510e \
66+
--hash=sha256:e9f17f2b6fc076b2a0078862547595d66244db0f41bf79fc5f64a5c4d635bead \
67+
--hash=sha256:edbaf9e8d3a63a9276d707b4d25930a262341bca9874fcb22eff5e3da5394732 \
68+
--hash=sha256:f237e6ca6421265643608813ce9793610ad09b40154a3344a088159590469e46 \
69+
--hash=sha256:f69b0c9bb174a2342818d3e2778584e18c740d56857fc5cdb944ec8bbe4082cf \
70+
--hash=sha256:fcb68203c833cc735321512e13861358079a96c174a61f5116a1de89c58c0ef7
71+
# via -r requirements.in
72+
python-dateutil==2.9.0.post0 \
73+
--hash=sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3 \
74+
--hash=sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427
75+
# via pandas
76+
pytz==2024.2 \
77+
--hash=sha256:2aa355083c50a0f93fa581709deac0c9ad65cca8a9e9beac660adcbd493c798a \
78+
--hash=sha256:31c7c1817eb7fae7ca4b8c7ee50c72f93aa2dd863de768e1ef4245d426aa0725
79+
# via pandas
80+
six==1.17.0 \
81+
--hash=sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274 \
82+
--hash=sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81
83+
# via python-dateutil
84+
tzdata==2024.2 \
85+
--hash=sha256:7d85cc416e9382e69095b7bdf4afd9e3880418a2413feec7069d533d6b4e31cc \
86+
--hash=sha256:a48093786cdcde33cad18c2555e8532f34422074448fbc874186f0abd79565cd
87+
# via pandas

0 commit comments

Comments
 (0)