Skip to content

Commit 52438cd

Browse files
authored
Merge branch 'main' into main
2 parents 1dc2c0d + b47b92b commit 52438cd

37 files changed

Lines changed: 485 additions & 67 deletions

File tree

.github/workflows/publish.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727
# GitHub repository which is a fork of the upstream where the Pull Request will be opened.
2828
registry_fork: bazel-contrib/bazel-central-registry
2929
attest: false
30+
# Create non-draft PRs so the BCR bazel-io bot processes them. Otherwise,
31+
# since a bazel-contrib bot, we have to wait for BCR maintainers to mark it
32+
# non-draft or approve it.
33+
draft: false
3034
permissions:
3135
contents: write
3236
secrets:

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ END_UNRELEASED_TEMPLATE
6666
### Fixed
6767
* (tests) No more coverage warnings are being printed if there are no sources.
6868
([#2762](https://github.com/bazel-contrib/rules_python/issues/2762))
69+
* (gazelle) Ancestor `conftest.py` files are added in addition to sibling `conftest.py`.
70+
([#3497](https://github.com/bazel-contrib/rules_python/issues/3497))
6971

7072
{#v0-0-0-added}
7173
### Added
@@ -92,6 +94,23 @@ END_UNRELEASED_TEMPLATE
9294
to pass the `TOOL_VERSIONS` that include 3.8 toolchains or use the `bzlmod` APIs to add
9395
them back. This means any hub `pip.parse` calls that target `3.8` will be ignored from
9496
now on. ([#2704](https://github.com/bazel-contrib/rules_python/issues/2704))
97+
{object}`python.single_version_override`, like:
98+
99+
```starlark
100+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
101+
102+
python.single_version_override(
103+
python_version = "3.8.20",
104+
sha256 = {
105+
"aarch64-apple-darwin": "2ddfc04bdb3e240f30fb782fa1deec6323799d0e857e0b63fa299218658fd3d4",
106+
"aarch64-unknown-linux-gnu": "9d8798f9e79e0fc0f36fcb95bfa28a1023407d51a8ea5944b4da711f1f75f1ed",
107+
"x86_64-apple-darwin": "68d060cd373255d2ca5b8b3441363d5aa7cc45b0c11bbccf52b1717c2b5aa8bb",
108+
"x86_64-pc-windows-msvc": "41b6709fec9c56419b7de1940d1f87fa62045aff81734480672dcb807eedc47e",
109+
"x86_64-unknown-linux-gnu": "285e141c36f88b2e9357654c5f77d1f8fb29cc25132698fe35bb30d787f38e87",
110+
},
111+
urls = ["https://github.com/astral-sh/python-build-standalone/releases/download/20241002/cpython-{python_version}+20241002-{platform}-{build}.tar.gz"],
112+
)
113+
```
95114
* (toolchain) Remove all of the python 3.9 toolchain versions except for the `3.9.25`.
96115
This version has reached EOL and will no longer receive any security fixes, please update to
97116
`3.10` or above. ([#2704](https://github.com/bazel-contrib/rules_python/issues/2704))

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ use_repo(
242242
"pkgutil_nspkg2",
243243
"rules_python_runtime_env_tc_info",
244244
"somepkg_with_build_files",
245+
"whl_library_extras_direct_dep",
245246
"whl_with_build_files",
246247
)
247248

examples/pip_parse/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,8 @@ py_test(
7979
"WHEEL_DIST_INFO_CONTENTS": "$(rootpaths @pypi//requests:dist_info)",
8080
"YAMLLINT_ENTRY_POINT": "$(rlocationpath :yamllint)",
8181
},
82-
deps = ["@rules_python//python/runfiles"],
82+
deps = [
83+
"@pypi//libclang",
84+
"@rules_python//python/runfiles",
85+
],
8386
)

examples/pip_parse/requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ s3cmd~=2.1.0
33
yamllint~=1.28.0
44
sphinx
55
sphinxcontrib-serializinghtml
6+
libclang

examples/pip_parse/requirements_lock.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ jinja2==3.1.6 \
4242
--hash=sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d \
4343
--hash=sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67
4444
# via sphinx
45+
libclang==18.1.1 \
46+
--hash=sha256:0b2e143f0fac830156feb56f9231ff8338c20aecfe72b4ffe96f19e5a1dbb69a \
47+
--hash=sha256:3f0e1f49f04d3cd198985fea0511576b0aee16f9ff0e0f0cad7f9c57ec3c20e8 \
48+
--hash=sha256:4dd2d3b82fab35e2bf9ca717d7b63ac990a3519c7e312f19fa8e86dcc712f7fb \
49+
--hash=sha256:54dda940a4a0491a9d1532bf071ea3ef26e6dbaf03b5000ed94dd7174e8f9592 \
50+
--hash=sha256:69f8eb8f65c279e765ffd28aaa7e9e364c776c17618af8bff22a8df58677ff4f \
51+
--hash=sha256:6f14c3f194704e5d09769108f03185fce7acaf1d1ae4bbb2f30a72c2400cb7c5 \
52+
--hash=sha256:83ce5045d101b669ac38e6da8e58765f12da2d3aafb3b9b98d88b286a60964d8 \
53+
--hash=sha256:a1214966d08d73d971287fc3ead8dfaf82eb07fb197680d8b3859dbbbbf78250 \
54+
--hash=sha256:c533091d8a3bbf7460a00cb6c1a71da93bffe148f172c7d03b1c31fbf8aa2a0b \
55+
--hash=sha256:cf4a99b05376513717ab5d82a0db832c56ccea4fd61a69dbb7bccf2dfb207dbe
56+
# via -r requirements.in
4557
markupsafe==2.1.3 \
4658
--hash=sha256:05fb21170423db021895e1ea1e1f3ab3adb85d1c2333cbc2310f2a26bc77272e \
4759
--hash=sha256:0a4e4a1aff6c7ac4cd55792abf96c915634c2b97e3cc1c7129578aa68ebd754e \

examples/pip_parse/requirements_windows.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ jinja2==3.1.6 \
4646
--hash=sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d \
4747
--hash=sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67
4848
# via sphinx
49+
libclang==18.1.1 \
50+
--hash=sha256:0b2e143f0fac830156feb56f9231ff8338c20aecfe72b4ffe96f19e5a1dbb69a \
51+
--hash=sha256:3f0e1f49f04d3cd198985fea0511576b0aee16f9ff0e0f0cad7f9c57ec3c20e8 \
52+
--hash=sha256:4dd2d3b82fab35e2bf9ca717d7b63ac990a3519c7e312f19fa8e86dcc712f7fb \
53+
--hash=sha256:54dda940a4a0491a9d1532bf071ea3ef26e6dbaf03b5000ed94dd7174e8f9592 \
54+
--hash=sha256:69f8eb8f65c279e765ffd28aaa7e9e364c776c17618af8bff22a8df58677ff4f \
55+
--hash=sha256:6f14c3f194704e5d09769108f03185fce7acaf1d1ae4bbb2f30a72c2400cb7c5 \
56+
--hash=sha256:83ce5045d101b669ac38e6da8e58765f12da2d3aafb3b9b98d88b286a60964d8 \
57+
--hash=sha256:a1214966d08d73d971287fc3ead8dfaf82eb07fb197680d8b3859dbbbbf78250 \
58+
--hash=sha256:c533091d8a3bbf7460a00cb6c1a71da93bffe148f172c7d03b1c31fbf8aa2a0b \
59+
--hash=sha256:cf4a99b05376513717ab5d82a0db832c56ccea4fd61a69dbb7bccf2dfb207dbe
60+
# via -r requirements.in
4961
markupsafe==2.1.3 \
5062
--hash=sha256:05fb21170423db021895e1ea1e1f3ab3adb85d1c2333cbc2310f2a26bc77272e \
5163
--hash=sha256:0a4e4a1aff6c7ac4cd55792abf96c915634c2b97e3cc1c7129578aa68ebd754e \

gazelle/python/generate.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ func matchesAnyGlob(s string, globs []string) bool {
6666
return false
6767
}
6868

69+
// findConftestPaths returns package paths containing conftest.py, from currentPkg
70+
// up through ancestors, stopping at module root.
71+
func findConftestPaths(repoRoot, currentPkg, pythonProjectRoot string) []string {
72+
var result []string
73+
for pkg := currentPkg; ; pkg = filepath.Dir(pkg) {
74+
if pkg == "." {
75+
pkg = ""
76+
}
77+
if _, err := os.Stat(filepath.Join(repoRoot, pkg, conftestFilename)); err == nil {
78+
result = append(result, pkg)
79+
}
80+
if pkg == "" {
81+
break
82+
}
83+
}
84+
return result
85+
}
86+
6987
// GenerateRules extracts build metadata from source files in a directory.
7088
// GenerateRules is called in each directory where an update is requested
7189
// in depth-first post-order.
@@ -481,14 +499,17 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
481499
}
482500

483501
for _, pyTestTarget := range pyTestTargets {
484-
if conftest != nil {
485-
conftestModule := Module{Name: importSpecFromSrc(pythonProjectRoot, args.Rel, conftestFilename).Imp}
486-
if pyTestTarget.annotations.includePytestConftest == nil {
487-
// unset; default behavior
488-
pyTestTarget.addModuleDependency(conftestModule)
489-
} else if *pyTestTarget.annotations.includePytestConftest {
490-
// set; add if true, do not add if false
491-
pyTestTarget.addModuleDependency(conftestModule)
502+
shouldAddConftest := pyTestTarget.annotations.includePytestConftest == nil ||
503+
*pyTestTarget.annotations.includePytestConftest
504+
505+
if shouldAddConftest {
506+
for _, conftestPkg := range findConftestPaths(args.Config.RepoRoot, args.Rel, pythonProjectRoot) {
507+
pyTestTarget.addModuleDependency(
508+
Module{
509+
Name: importSpecFromSrc(pythonProjectRoot, conftestPkg, conftestFilename).Imp,
510+
Filepath: filepath.Join(conftestPkg, conftestFilename),
511+
},
512+
)
492513
}
493514
}
494515
pyTest := pyTestTarget.build()

gazelle/python/testdata/simple_test_with_conftest/bar/BUILD.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ py_test(
2323
deps = [
2424
":bar",
2525
":conftest",
26+
"//:conftest",
2627
],
2728
)

gazelle/python/testdata/simple_test_with_conftest_sibling_imports_disabled/bar/BUILD.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ py_test(
2222
main = "__test__.py",
2323
deps = [
2424
":conftest",
25+
"//:conftest",
2526
"//:simple_test_with_conftest_sibling_imports_disabled",
2627
],
2728
)

0 commit comments

Comments
 (0)