is the only difference between the 2.7.0 `python_l...
# general
a
is the only difference between the 2.7.0
python_library
and the 2.8.0
python_sources
just the name? it /feels/ like everything works differently
f
It does work differently since the implementation of file targets has been generalized into “target generators.” This is mostly visible only to plugin authors. In 2.7.x and earlier versions,
python_library
represented multiple source files and there were “subtargets” addressable on the command-line via file specs (i.e., the name of the file). These file subtargets were a special case in the engine. In 2.8.x, per-file subtargets have been generalized into “target generators” where a target can dynamically create other targets.
python_sources
is a target generator that generates
python_source
targets (which represent each Python file). One of the motivations for the feature was for the Go backend. The
go_mod
target is a target generator which generates targets for the packages in third-party dependencies. This allows those packages to be part of the build graph so that Pants knows the dependencies among them. This is an example of a target generator that does not generate per-file targets (since the “unit of build” in Go programs is the package).
w
but in terms of how they operate,
python_library
and
python_sources
should be identical.
h
Hi! Yeah, indeed, there should be few practical changes other than the rename. These things are now possible, but not necessary to use: • you can directly create a
python_source
and
python_test
target • you can set `overrides`:
Copy code
python_tests(
   name="tests",
   overrides={
      "foo_test.py": {"timeout": 120},
      ("bar_test.py", "baz_test.py"): {"timeout": 200},
   },
)
The other changes are: •
./pants peek
will have different
target_type
for some targets. Whereas
./pants peek path/to/f_test.py
used to say
python_tests
, now it's
python_test
./pants filter --target-type
differentiates between
python_source
vs.
python_sources
• The globs
./pants $goal dir:
now matches "generated targets" with goals like
list
and
peek
when using
dir:
and
dir::
, whereas we used to leave them off What changes are you seeing?