how is the difference of semantics of “built-in” c...
# general
f
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
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
thanks for clarifying — that makes perfect sense 👌
c
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
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
ah, so there is generic code for certain kinds which delegates — interesting
c
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
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
got it
b
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.