Just getting started - I setup a small example rep...
# general
l
Just getting started - I setup a small example repo to capture what I think I want to do, but where I'm running into questions - https://github.com/rjrudin/pants-monorepo . Hoping someone can help with the initial 4 questions I have in the README file, which - high-level - are: 1) Why are dependencies not shown; 2) Recommendation for running tests in PyCharm; 3) Controlling version of Pytest; 4) How to do what I used to do via Gradle with app/lib dependencies .
The commit history also shows the small steps I took to build the project
r
You can check pants documentation for how to set pytest version https://www.pantsbuild.org/docs/python-test-goal#pytest-version-and-plugins
b
Dang, @refined-addition-53644 beat me to it 😂
😄 2
So for 1) Pants (at the moment) doesn't support multiple lockfiles in your mono. Just one-monolithic one. See https://github.com/pantsbuild/pants/issues/12314
If you do switch to a monolithic lockfile, check out https://www.pantsbuild.org/docs/python-third-party-dependencies on how to tell Pants to use it
l
Re: Pytest version - it dovetails with question 2 - what's the recommended way for PyCharm to run a test? Currently, we add pytest to a requirements_test.txt file and that gets dumped into the venv via "pip install". If I configure the pytest block in pants.toml, that doesn't make any difference to PyCharm.
r
I am not a PyCharm user. So can't say much but if it's similar to VS code, I think using a virtual env would be the way to go as suggested here https://www.pantsbuild.org/docs/contributor-setup#hooking-up-the-python-virtual-environment
b
Right now, when you use Pants you're kind of giving the keys over to Pants to run things (including test). Currently, if you want to wire your editor to understand your env, you'll have to do that yourself. Pants does provide some info on how to help though: https://www.pantsbuild.org/docs/setting-up-an-ide
1
Dang you @refined-addition-53644!! 😂 Edit: oh different links 🙌
r
I waited long enough 😄
😒 1
b
I'm hopeful 2022 will bring Pants-supported in-editor plugin support
h
Multiple Python lockfiles is coming soon!
🙌 3
And IntelliJ/PyCharm integration also
💯 2
👀 3
b
@happy-kitchen-89482 Now do VSCode 😂 I'm an open-source fanboy
h
Initially for JVM, but we want to provide Python support soon as well
l
Thanks - getting back to question 1 - if I understand https://www.pantsbuild.org/docs/python-third-party-dependencies correctly, I should still have a single requirements.txt file (which is true of this example that I found to be helpful, in addition to the pants example - https://github.com/semaphoreci-demos/semaphore-demo-python-pants ). But when I run a goal, pants will figure out which dependencies are really needed, correct? (If so, that sounds good, just wrapping my head around because it's different from the Java/Gradle approach of each subproject having its own list of dependencies, and subproject A can depend on B and so forth)
h
Well, the plan is to provide the support via LSP/BSP, which I think will make it easier to integrate with VSCode too?
😍 2
🙌 2
b
@happy-kitchen-89482 sounds right
h
@lively-exabyte-12840 Yes, that is correct
the requirements file (and the lockfile you derive from it) represent the universe of allowed dependencies
But Pants will compute the actual subset of needed dependencies in each situation
The problem with that Gradle approach is keeping all those separate dependencies mutually compatible
Here Pants takes care of that
l
Got it - related to that, we're not creating a pex binary yet, but I assume if we did, Pants will compute the subset of dependencies to be included in that binary? (I am equating "pex binary" with "executable jar", where again, Java/Gradle would look at the dependencies of each subproject to compute what should get stuffed into that jar)
1
Right - with Gradle, I spent a lot of time looking at dependency trees and checking for mismatches and trying to narrow down the dependencies of each subproject as much as possible
h
Correct
The pex will contain exactly the needed dependencies (both local and external)
l
Thanks, I'll keep progressing further (main thing is I need to get to a "this works, we can migrate over" point and also be able to answer questions for my team)
h
Similarly if you use Pants to build an AWS Lambda or a GCP Cloud Function, it'll contain just what it needs
Or if you use Pants to build a wheel or sdist, its metadata will specify just the requirements it needs
I'll take a look at that repo and see if I can answer the dependencies question
Oh I see, that issue is to do with the multiple requirements.txt
Let me know if having one repo-wide one solves it
l
I think the ultimate goal is - when we deploy, we of course only want the dependencies that are needed (regardless of the build tool). Having a single requirements file and then trusting Pants to only use the necessary dependencies is a good approach, though I think we'll need to build up that trust on the team via evidence. This is my lack of Python knowledge, but I'm thinking right now in Java terms of being able to scan the classpath at runtime to verify what's been loaded and what hasn't been loaded
b
Running
./pants dependencies <file>
should delight you then 😉
h
Yes, you can always run
./pants dependencies
,
./pants dependees
and
./pants peek
to verify that dependencies are what you expect
There is also this pending issue for "visibility" support: https://github.com/pantsbuild/pants/issues/13393
This, when implemented, will let you control which dependencies are allowed
l
13393 is good stuff; that's one concern I've been thinking about, where someone coding in app1 could easily grab code from app2, which we wouldn't want
Thanks for all the responses! It took me awhile to master all this stuff with Gradle, hoping for a lot less time with Pants 🙂
🙌 2
h
you can always run ./pants dependencies, ./pants dependees and ./pants peek to verify that dependencies are what you expect
See https://www.pantsbuild.org/docs/project-introspection