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

silly-queen-7197

01/25/2023, 6:28 AM
Hi everyone, I'm new to Pants and am trying to learn / evaluate it for a potential project. One pattern we follow in the project is managing two separate requirement files
requirements.txt
and
requirements-dev.txt
. The first is for 3rd party dependencies we use in our application while the second is limited to
pytest
,
black
,
flake8
, and the like. When developing we have one
venv
that we can point VS Code . In addition to the code completion benefits we can use VS Code's Testing extension with python to easily set breakpoints when debugging tests. I ran
./pants export ::
but
pytest
isn't included as a dependency in the main
venv
it exported and I'm not sure how to use the exported
pytest
venv
as it's not able to import any of my code (I'm using a
src
style layout). I could just include
pytest
as a 3rd party dependency and specify
export = false
in my
pants.toml
but I don't want to ship
pytest
to production. How can I setup Pants so I can maintain install dependencies (e.g. pytest, typeshed, etc) to facilitate a good developer experience while ensuring I don't ship dev dependencies to production?
h

high-yak-85899

01/25/2023, 6:34 AM
The exported venv comes with pip
You can then pip install the requirements file from there. We have a bootstrap script in our repo that is rarely needed to be run since it primarily just sets up the developer experience
s

silly-queen-7197

01/25/2023, 6:43 AM
Thanks! That makes sense
h

happy-kitchen-89482

01/25/2023, 7:05 AM
Also, importantly - in idiomatic Pants use you should think of your
requirements.txt
(and the lockfile you are hopefully generating from it) as a "universe" of allowed 3rdparty dependencies. But Pants will actually use just the actually needed subset from that universe. So if Pants is building your production binaries, you can safely have
pytest
etc in your
requirements.txt
, and it won't show up in production.
As mentioned, we do recommend using the resolves/lockfiles feature. And if you still prefer to have `requirements.txt and
requirements-dev.txt
, a resolve can span multiple requirements.txt files, so when you
./pants export --resolve=python-default
you'll get a venv with everything from both files in it. But you do need a
python_requirements(source="requirements-dev.txt")
target of course.
s

silly-queen-7197

01/26/2023, 8:33 AM
That was very helpful, thank you!
7 Views