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

lively-exabyte-12840

01/14/2022, 3:03 PM
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

refined-addition-53644

01/14/2022, 3:11 PM
You can check pants documentation for how to set pytest version https://www.pantsbuild.org/docs/python-test-goal#pytest-version-and-plugins
b

bitter-ability-32190

01/14/2022, 3:11 PM
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

lively-exabyte-12840

01/14/2022, 3:14 PM
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

refined-addition-53644

01/14/2022, 3:18 PM
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

bitter-ability-32190

01/14/2022, 3:18 PM
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

refined-addition-53644

01/14/2022, 3:18 PM
I waited long enough 😄
😒 1
b

bitter-ability-32190

01/14/2022, 3:19 PM
I'm hopeful 2022 will bring Pants-supported in-editor plugin support
h

happy-kitchen-89482

01/14/2022, 3:20 PM
Multiple Python lockfiles is coming soon!
🙌 3
And IntelliJ/PyCharm integration also
💯 2
👀 3
b

bitter-ability-32190

01/14/2022, 3:21 PM
@happy-kitchen-89482 Now do VSCode 😂 I'm an open-source fanboy
h

happy-kitchen-89482

01/14/2022, 3:21 PM
Initially for JVM, but we want to provide Python support soon as well
l

lively-exabyte-12840

01/14/2022, 3:21 PM
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

happy-kitchen-89482

01/14/2022, 3:21 PM
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

bitter-ability-32190

01/14/2022, 3:22 PM
@happy-kitchen-89482 sounds right
h

happy-kitchen-89482

01/14/2022, 3:22 PM
@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

lively-exabyte-12840

01/14/2022, 3:23 PM
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

happy-kitchen-89482

01/14/2022, 3:24 PM
Correct
The pex will contain exactly the needed dependencies (both local and external)
l

lively-exabyte-12840

01/14/2022, 3:24 PM
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

happy-kitchen-89482

01/14/2022, 3:24 PM
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

lively-exabyte-12840

01/14/2022, 3:37 PM
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

bitter-ability-32190

01/14/2022, 3:39 PM
Running
./pants dependencies <file>
should delight you then 😉
h

happy-kitchen-89482

01/14/2022, 3:41 PM
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

lively-exabyte-12840

01/14/2022, 3:51 PM
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

hundreds-father-404

01/14/2022, 5:11 PM
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