Hello! Could someone please confirm or denywhether...
# development
c
Hello! Could someone please confirm or denywhether validation of dependencies allows saying for a application /apps/X in a monorepo that it may not depend on other /apps/* siblings, but of course may have dependencies on itself? I can't find magic incantation that works, this is the closest I can think of, but I still get errors. I guess it's some silly mistake, but I can't see it.
Copy code
apps/BUILD:
__dependencies_rules__(
    ({"type": python_sources}, "!//apps/**/*", "*"),
)

apps/*/BUILD:
__dependencies_rules__(
        ({"type": python_sources}, "*"),
        extend=True,
    )
c
You may want to use a macro to provide some data, or the entire dependencies call, but try this (your verbose selectors are 👍 I'm just going for less typing here..):
Copy code
# apps/*/BUILD
__dependencies_rules__(
  (
    (python_sources, python_source),
    "/**/*",  # Allow all sources in this app to depend on anything in the current subtree
    "!/../**/*",  # Deny depending on any (other) apps (the previous rule will match before this one to keep the current app as allowed)
  )
)
Having said that, I think you could get away with a single rule at the apps level:
Copy code
# apps/BUILD
__dependencies_rules__(
  (
    (python_sources, python_source),
    "./**/*",  # Always allow anything from a source's current subtree.
    "!//apps/**/*",  # Deny depending on (other) apps.
  )
)
Uhm, or not. As you'd not be able to depend on sibling parts higher up from the same app. I'll keep it any way to illustrate my train of thought on this, perhaps nudges some ideas.. 😉
Also note, that my rules are not exhaustive, so you may have to provide additional rules for stuff not in
/apps
f
if you want to experiment in a toy project to learn how visibility rules work, I've created a while ago this repo https://github.com/pantsbuild/example-visibility. There's another repo of mine where you can see how the rules are being used, e.g. https://github.com/AlexTereshenkov/cheeseshop-query/blob/main/cheeseshop/cli/utils/BUILD. To learn more about visibility rules, feel free to take a look at https://blog.pantsbuild.org/visibility-feature-in-pants-2-16/
c
Thanks Andreas and Alexey! I will play around, I didn't think to use /../ in the paths, I'll see what works. In general, I feel that the visibility config is a bit complicated for the simplest cases, it took a while to get my head around it.
f
yes, it can be rather terse in the beginning, but once you got the basics right, most trivial rules are super easy to write. Then there's always that annoying edge case you can't find a way to express and then Andreas is telling you what to do 😄
but definitely take a look at the example-visibility repo, it has the simplest examples to get started and experiment
👍🏽 1
c
thanks for the feedback. I agree that it would be nice with some sort of abstraction or sugar on top of this to make it easier to express common patterns.