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

billions-keyboard-33102

07/05/2022, 9:00 AM
Hi, using pants with python. For
python_sources
https://www.pantsbuild.org/docs/reference-python_sources In the docs under
dependencies
it says:
This augments any dependencies inferred by Pants, such as by analyzing your imports
Is there a way to disable the automatic import analysis and just use the manual list? I want to be explicit about the dependencies that’s all.
a

ambitious-actor-36781

07/05/2022, 9:02 AM
Copy code
[python-infer]
imports = false
https://www.pantsbuild.org/docs/reference-python-infer
👍 2
b

billions-keyboard-33102

07/05/2022, 9:02 AM
Thank you!
h

hundreds-father-404

07/05/2022, 2:34 PM
Hi! It is totally valid to not use dependency inference, although we generally strongly encourage using it for three reasons 1) Dependency inference tends to be far more precise, as it infers at the file level. To get the same precision, you should ban using
python_sources
(plural) and only use
python_source
targets. But that's a disaster to maintain. The precision gives you much finer-grained caching and better project introspection, like
--changed-since
2) Dependency inference tends to be more accurate. W/ explicit deps, it's easy to forget to remove deps from BUILD files. It's also sometimes possible to leave off a real dep because a transitive dependency includes it 3) Manual BUILD file management is a pain, and engineers often get frustrated What's your thinking around wanting to be explicit?
h

happy-kitchen-89482

07/05/2022, 3:53 PM
Sometimes people want to be explicit in order to enforce dependency rules at code review time. One of our most upvoted open tickets is to provide that enforcement automatically, so you can get the best of both worlds. @billions-keyboard-33102 is that relevant to your use-case? Or do you prefer explicit deps for some other reason?
1
b

billions-keyboard-33102

07/05/2022, 3:57 PM
Hi, so I was using the dependency inference, and it works great - possibly might even revert to that. Reason for being explicit is for high-level dependency of subsystems. In a pants mono-repo you can import anything from anywhere, but this could harm future development if you create a dependency unnecessarily. Say the repo consists of 3 high-level subsystems
subsystem1
,
subsystem2
,
subsystem3
. I have a map in my head that
subsystem1
depends on
subsystem2
, but not
subsystem3
. Another example, I would also consider it strange if some authorisation code imported a testing library. Explicit dependencies seemed a nice way of enforcing these things. EDIT: yes the ticket you linked describes this better!
❤️ 1
h

happy-kitchen-89482

07/05/2022, 3:57 PM
Aha!
If you have any comments to add to that ticket, it helps us prioritize!
b

billions-keyboard-33102

07/05/2022, 3:58 PM
Sure, thank you - I’ll take a look
❤️ 1
Looks like this got merged - thank you very much to all involved! We’ll upgrade our version of pants when it does and revert back to automatic dependency inference.
❤️ 1
I am trying it out now using
2.16.dev0
I haven’t figured out how to allow visibility for the python_requirements (
<http://requirements.in|requirements.in>
)
15:27:49.65 [WARN] Dependency rule violation for some/path.py:../../../../some on //:requirements#pyyaml
Using this in my BUILD file:
Copy code
__dependencies_rules__(
      ("*", ".", "//:requirements#*", "?*"),
      ("*", "!*"), # Allow all by default, with a warning
)
I will wait for the documentation! 🤔
2 Views