https://pantsbuild.org/ logo
#general
Title
# general
f

freezing-lamp-12123

07/23/2022, 12:26 PM
how is the difference of semantics of “built-in” commands like
build
,
test
,
fmt
,
run
, and
lint
encoded in pants? are the same knobs available for any targets?
1
reference:
Pants natively understands the semantics of a variety of build actions. These include "test", "lint", "fmt", "check", "package", "publish", "run", "repl" and more. It understands what these commands do and how that affects caching and concurrency
e

enough-analyst-54434

07/23/2022, 12:47 PM
Those are pretty misleading words. Pants doesn't actually natively understand any of those goals (verbs). The pants distribution just happens to ship with those goals, which are written using the standard plugin API, "built in", aka pre-packaged.
The basic idea is there is an API to add a goal. Say you want to add "doc" for generating documentation. ~All goals do their work by delegating. The way you do this is invent a type to represent the work, say
Documentation
in this case. The goal implementation then just asks Pants to produce
Documentation
for the files and targets supplied on the command line. Then, for each type of file or target that you know how to produce
Documentation
for, you write rules that do the real work, say a rule set that produces doc's via Sphinx for Python code. Those rules are written using the plugin API and they are also registered using the API.
f

freezing-lamp-12123

07/23/2022, 1:02 PM
thanks for clarifying — that makes perfect sense 👌
c

curved-television-6568

07/23/2022, 1:57 PM
the only exception being for the
help
goal (and few experimental ones) which are truly “built-in” in a way that is not available to plugins.
👍 1
h

happy-kitchen-89482

07/23/2022, 5:20 PM
Well, it is true that goal-specific semantics are baked in to the implementations that ship with Pants. E.g., the generic
fmt
goal (which delegates to language/tool-specific formatter implementations provided by plugins, including your custom plugins) knows that it has to delegate sequentially, so that formatters don't step on each others' toes, but the generic
lint
goal knows that it can delegate in parallel because the linters aren't overwriting the files they lint.
But yeah, "natively" means "pre-packaged". You can extend these goals or create your own using the same mechanisms Pants does for those pre-packaged goals.
f

freezing-lamp-12123

07/23/2022, 6:57 PM
ah, so there is generic code for certain kinds which delegates — interesting
c

curved-television-6568

07/23/2022, 7:26 PM
Indeed. I'll say a lot of implementation details in Pants are interesting (in a good way) worth to explore. That is one of the many qualities that attracted me to this project.
h

happy-kitchen-89482

07/23/2022, 7:52 PM
Yes, there is a generic implementation of, say, lint that understands the general concept of "linting" and provides common functionality for specific linter implementations to take advantage of
ditto
fmt
,
test
,
run
etc.
But you can also add your own goals that have nothing to do with these
f

freezing-lamp-12123

07/23/2022, 7:58 PM
got it
b

busy-vase-39202

07/25/2022, 4:24 PM
This could make a neat talk for a conference or meetup. If anyone is interested in developing a talk on Pants internals, give me a ping. I'd gladly help you work it up and find suitable events to submit it to.
4 Views