What’s the recommended way to convert the pants-ge...
# general
a
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
The recommendation is to use
./pants export ::
for that
it'll generate a venv that you can point VSCode to
a
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
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
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
Thanks Benjy. Let me try that.
does
export
accept regex? i just want to exclude one directory.
h
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
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
@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
The wart is the grepping / sed you have to do since Pantsadds comments to the json 😕
a
haha, just noticed
e
Asher has his solution above for that.
a
working beautifully
e
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
gotcha. thanks a lot!