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

0 commit comments

Comments
 (0)