Hi! Is it possible to limit macros scope to a sing...
# general
s
Hi! Is it possible to limit macros scope to a single directory?
I want some macro to be only available in
my-project/
but not in
another-project/
c
no, they're currently repo-wide only.
if this is something you (and potentially others as well then) care about, if you write a feature request ticket for it, I think it could be doable to implement a per sub-tree macro loading thing.
s
I guess what I could is
assert str(build_file_dir()).startswith("my-project/")
they are still visible, but at least forbidden
c
yea, that could work as band-aid
s
I think what I really want is to be able to use functions from BUILD files up the tree, so that I could declare my macros in
my-project/BUILD
and then use them in
my-project/sub1/BUILD
and
my-project/sub2/BUILD
.
macro.py
files are not very convenient as you have to explicitly add them to your pants.toml
or maybe automatically add macros from
my-project/macros.py
c
this would likely be something like
load("my-macros.py")
in the BUILD file.. but it's interesting to be able to "export" functions declared directly in the BUILD file for the sub tree to consume..
s
at this point I feel like we're inventing python imports 😂
c
yea, perhaps allow a subset of the import syntax..
😛
but then.. if you import something, we'd want to check the imports of that as well etc.. otherwise the import guard does little.
s
yeah, I think macro glob like
Copy code
build_file_prelude_globs = ["**/macros.py"]
is good middleground, I'll try that
c
your top-level macro could have a macro-decorator for you other macros to use, that adds the use-check..