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

purple-plastic-57801

03/04/2023, 4:55 PM
👋 I'm attempting to onboard pants into a current multi root python project that is stitched together with a pile of makefiles. So far I have.. pants.toml
Copy code
[GLOBAL]
pants_version = "2.15.0"
pants_ignore = [
    "enclosure",
    "observatory_api/*",
    "teletom",
    "third_party/*"
]

backend_packages = [
  "pants.backend.python",
  "pants.backend.python.lint.black",

]

[anonymous-telemetry]
enabled = false

[source]
root_patterns = [
  "/teletom_shared/src"
]

[python]
interpreter_constraints = ["==3.11.*"]

enable_resolves = true

resolves = { python-default = "python-default.lock" }
Copy code
pants roots
08:55:06.37 [INFO] Initializing scheduler...
08:55:06.84 [INFO] Scheduler initialized.
teletom_shared/src
When I run
pants tailor ::
it generates the BUILD files, but none of the sources are there 🤔 Example
Copy code
python_sources()

python_tests(
    name="tests",
)
e

enough-analyst-54434

03/04/2023, 4:59 PM
it generates the BUILD files, but none of the sources are there
You mean this?:
python_sources()
p

purple-plastic-57801

03/04/2023, 5:00 PM
Yeah. New here.. sorry.
e

enough-analyst-54434

03/04/2023, 5:00 PM
That uses defaults for name and sources.
p

purple-plastic-57801

03/04/2023, 5:00 PM
I figured it woudl add dependenices?
Huh I guess not.
e

enough-analyst-54434

03/04/2023, 5:00 PM
So, pretend BUILD files don't exist. You're just confusing yourself with them. They ought not to exist in this case, Pants just needs them.
p

purple-plastic-57801

03/04/2023, 5:01 PM
Guess bazel hurt my brain
e

enough-analyst-54434

03/04/2023, 5:01 PM
Yeah, Pants will automatically take some root signal - say a file path or a test target, and it will figure out the implied root files, parse those, find imports and recurse.
It discovers the depndencies on the fly.
p

purple-plastic-57801

03/04/2023, 5:03 PM
That's pretty neat 🤔
e

enough-analyst-54434

03/04/2023, 5:03 PM
Try
pants dependencies some/file.py
p

purple-plastic-57801

03/04/2023, 5:03 PM
Yeah I did and see that
It can't be this easy
e

enough-analyst-54434

03/04/2023, 5:03 PM
Gotcha - ok.
p

purple-plastic-57801

03/04/2023, 5:03 PM
... whats the catch? 🤣
e

enough-analyst-54434

03/04/2023, 5:04 PM
The catch is there is a small bit of overhead of course.
p

purple-plastic-57801

03/04/2023, 5:04 PM
No where near as much to get this working vs bazel + rules_python + gazelle
e

enough-analyst-54434

03/04/2023, 5:04 PM
The process we run to parse each file for imports is fully cached, but if you restart pantsd, there is some cost to re-learning those imports are cached.
👍 1
Yeah, ok. So the big difference from Bazel is just that, the rules system is 1st class and fully dogfooded - no special built in rules in the core - which I believe Bazel relies on. And its fully recursive. So you can do things like run javac to learn imports before running javac to compile a dep graph, etc.
And the other big difference is BUILD should only be needed to settle ambiguity. You shouldn't need BUILD at all for most cases. Except you do, because legacy; so tailor helps auto-generate those relics that don't make sense when you read them.
Some day we'll finally remove the need for BUILD except when its actually needed.
p

purple-plastic-57801

03/04/2023, 5:11 PM
Got it. Interesting
h

happy-kitchen-89482

03/04/2023, 10:11 PM
Thanks to @curved-television-6568's https://github.com/pantsbuild/pants/pull/16998 we do now have the ability to synthesize targets on the fly, and I would love to try and use that to get rid of the little target stubs like
python_sources()
etc that as John mentioned exist for legacy reasons.
🎉 1
2 Views