Skip to content

Commit e166653

Browse files
committed
Changelog and documentation
1 parent b1e98bf commit e166653

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ END_UNRELEASED_TEMPLATE
104104
* 3.12.11
105105
* 3.13.5
106106
* 3.14.0b3
107+
* (gazelle): New annotation `gazelle:include_pytest_conftest`. When not set (the
108+
default) or `true`, gazelle will inject any `conftest.py` file found in the same
109+
directory as a {obj}`py_test` target to that {obj}`py_test` target's `deps`.
110+
This behavior is unchanged from previous versions. When `false`, the `:conftest`
111+
dep is not added to the {obj}`py_test` target.
112+
107113

108114
{#v0-0-0-removed}
109115
### Removed

gazelle/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ The annotations are:
513513
| Tells Gazelle to ignore import statements. `imports` is a comma-separated list of imports to ignore. | |
514514
| [`# gazelle:include_dep targets`](#annotation-include_dep) | N/A |
515515
| Tells Gazelle to include a set of dependencies, even if they are not imported in a Python module. `targets` is a comma-separated list of target names to include as dependencies. | |
516+
| [`# gazelle:include_pytest_conftest bool`](#annotation-include_pytest_conftest) | N/A |
517+
| Whether or not to include a sibling `:conftest` target in the deps of a `py_test` target. Default behaviour is to include `:conftest`. | |
516518

517519

518520
#### Annotation: `ignore`
@@ -585,6 +587,89 @@ deps = [
585587
]
586588
```
587589

590+
#### Annotation: `include_pytest_conftest`
591+
592+
Added in [#3080][gh3080].
593+
594+
[gh3080]: https://github.com/bazel-contrib/rules_python/pull/3080
595+
596+
This annotation accepts any string that can be parsed by go's
597+
[`strconv.ParseBool`][ParseBool]. If an unparsable string is passed, the
598+
annotation is ignored.
599+
600+
[ParseBool]: https://pkg.go.dev/strconv#ParseBool
601+
602+
Starting with [`rules_python` 0.14.0][rules-python-0.14.0] (specifically [PR #879][gh879]),
603+
Gazelle will include a `:conftest` dependency to an `py_test` target that is in
604+
the same directory as `conftest.py`.
605+
606+
[rules-python-0.14.0]: https://github.com/bazel-contrib/rules_python/releases/tag/0.14.0
607+
[gh879]: https://github.com/bazel-contrib/rules_python/pull/879
608+
609+
This annotation allows users to adjust that behavior. To disable the behavior, set
610+
the annotation value to "false":
611+
612+
```
613+
# some_file_test.py
614+
# gazelle:include_pytest_conftest false
615+
```
616+
617+
Example:
618+
619+
Given a directory tree like:
620+
621+
```
622+
.
623+
├── BUILD.bazel
624+
├── conftest.py
625+
└── some_file_test.py
626+
```
627+
628+
The default Gazelle behavior would create:
629+
630+
```starlark
631+
py_library(
632+
name = "conftest",
633+
testonly = True,
634+
srcs = ["conftest.py"],
635+
visibility = ["//:__subpackages__"],
636+
)
637+
638+
py_test(
639+
name = "some_file_test",
640+
srcs = ["some_file_test.py"],
641+
deps = [":conftest"],
642+
)
643+
```
644+
645+
When `# gazelle:include_pytest_conftest false` is found in `some_file_test.py`
646+
647+
```python
648+
# some_file_test.py
649+
# gazelle:include_pytest_conftest false
650+
```
651+
652+
Gazelle will generate:
653+
654+
```starlark
655+
py_library(
656+
name = "conftest",
657+
testonly = True,
658+
srcs = ["conftest.py"],
659+
visibility = ["//:__subpackages__"],
660+
)
661+
662+
py_test(
663+
name = "some_file_test",
664+
srcs = ["some_file_test.py"],
665+
)
666+
```
667+
668+
See [Issue #3076][gh3076] for more information.
669+
670+
[gh3076]: https://github.com/bazel-contrib/rules_python/issues/3076
671+
672+
588673
#### Directive: `experimental_allow_relative_imports`
589674
Enables experimental support for resolving relative imports in
590675
`python_generation_mode package`.

0 commit comments

Comments
 (0)