BUILD file symbols #18117
Replies: 3 comments 4 replies
-
There probably could be though...? It seems like it would be straightforward to extract docstrings from macros. |
Beta Was this translation helpful? Give feedback.
-
Another option that avoids the nesting would be to have (require?) explicit |
Beta Was this translation helpful? Give feedback.
-
I wonder if it will be possible to use the macro namespace immediately after definition in the same BUILD file. conceptually, you probably wouldn't need the namespace for macro functions in the same BUILD file, but constants are iffy. with macros.namespace("ex_inc", description="I may want to describe this namespace") as ns:
@ns.macro(help="My help text")
def macro_impl(...):
pass
ns.const.MY_CONST(42, help="Describe `MY_CONST` that has value 42")
# this is defined, so it is usable.
macro_impl(...)
# but could you do this?
ex_inc.macro_impl(...)
# or would you have to do this, using the `ns` object from the with block?
ns.macro_impl(...)
some_target(
# and how would you access consts in the same BUILD file?
some_field=ex_inc.MY_CONST,
# or would it be like this
other_field=ns.MY_CONST,
) It's a little more straightforward if you're defining the macros globally instead of in a namespace, as then just using This gets dicey in the same BUILD file because pants would have to inject stuff into |
Beta Was this translation helpful? Give feedback.
-
There are some good ideas presented in #14832 that needs a little bit more design and sign off before being implemented. The purpose of this discussion is to drive that home.
Current state
BUILD
files are just regular Python files with the added restriction that they may not useimport
.To offer generic BUILD-file constructs there's support for BUILD file "macros", whose contents are in effect prepended to each BUILD file in order to support globally defined values and methods.
There is no introspection for these macro defined values so they can't be documented properly.
Using the Plugin API backends may register new target types and BUILD file aliases. The targets are well documented and will not be further included in this discussion as they are already in a good position. BUILD file aliases are the Plugin API equivalence of a BUILD file macro file, and equally under-documented.
This is at the core of this discussion, to find new ways to declare macros both from macro files and the Plugin API, by exploring the UX/DX to support well documented macros.
UX - BUILD file macros
Introducing a new
macros
manager, users use this manager to setup their macro methods and values along with any documentation as desired. Pants will then make this information available in the online help usingpants macros --help
where all available macros are discoverable and documented.Macros manager example:
The declared macros and constants are then available directly in regular BUILD files:
Help for namespaced macros may be queried directly:
$ pants ex_inc --help # in case the namespace conflicts with another help topic, the full name may be used: $ pants macros.ex_inc --help
DX - Plugin API
TBD.
Some notes:
@rule
s to inspect/interact with.The idea with this last one, is to be able to refactor
__defaults__
and__dependencies_rules__
to be just another macro citizen. (may turn out there are too many dependencies that goes out of scope for macros to be feasible, but would like to explore this option)Beta Was this translation helpful? Give feedback.
All reactions