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

ambitious-student-81104

07/11/2022, 7:33 PM
What’s the recommended way to convert the pants-generated
.lockfile
to something like a
requirements.txt
so that I can
pip instsall
it so that my VSCode can figure out the dependency?
h

happy-kitchen-89482

07/11/2022, 7:33 PM
The recommendation is to use
./pants export ::
for that
it'll generate a venv that you can point VSCode to
a

ambitious-student-81104

07/11/2022, 7:36 PM
oof.. this backfired, because
export
actually walks the dependencies; but we would still love for it to just work, because it’s the min-change solution for now
p

polite-garden-50641

07/11/2022, 7:36 PM
or we use this in order to generate a pip compatible lock file (in order to run pip-audit on it):
Copy code
pip install -U "pex==2.1.95"
mkdir -p dist/
sed '/^\/\//d' 3rdparty/python/repo_pex_lock_file > dist/lockfile.json # remove pants comments from lock file
pex3 lock export --platform current dist/lockfile.json > dist/pip_compatible_lock_file.txt
🙏 1
h

happy-kitchen-89482

07/11/2022, 7:39 PM
You can run
export
on just a subset of the repo that has a consistent resolve, you don't have to run it on
::
a

ambitious-student-81104

07/11/2022, 7:41 PM
Thanks Benjy. Let me try that.
does
export
accept regex? i just want to exclude one directory.
h

hundreds-father-404

07/11/2022, 7:45 PM
if you use Pants 2.13, then you can do
./pants export :: -ignore_me/dir
. We added support for excluding specs by prefixing with
-
. (We also now allow you to have directories match everything in the directory, vs a previous gotcha that
dir
really meant
dir:dir
)
e

enough-analyst-54434

07/11/2022, 7:48 PM
So you can pip install? If so, don't and just
PEX_TOOLS=1 pex --lock my-lock.json --include-tools -- venv create/venv/here
.
a

ambitious-student-81104

07/11/2022, 7:48 PM
@hundreds-father-404 that’s really sweet, but we are just upgrading to 2.11 for now 😢
@enough-analyst-54434 let me try that! yes, i was previously just pip installing, because we weren’t using lockfiles altogether - we were using a manual script to generate a
constraints.txt
file for our monorepo
e

enough-analyst-54434

07/11/2022, 7:50 PM
The wart is the grepping / sed you have to do since Pantsadds comments to the json 😕
a

ambitious-student-81104

07/11/2022, 7:51 PM
haha, just noticed
e

enough-analyst-54434

07/11/2022, 7:51 PM
Asher has his solution above for that.
a

ambitious-student-81104

07/11/2022, 7:53 PM
working beautifully
e

enough-analyst-54434

07/11/2022, 7:55 PM
There are some other
venv
options you may wish to use like
--pip
to include
pip
in the venv so you can mutate it. Just chuck a
-h
on the end of the command line to find out more.
Zameer pointed out this was not an ideal command line, but since it exists and works the motivation to make it simpler has fallen behind other pressing concerns: https://github.com/pantsbuild/pex/issues/1752
a

ambitious-student-81104

07/11/2022, 8:49 PM
gotcha. thanks a lot!
8 Views