When running the REPL, is it possible to run it wi...
# general
b
When running the REPL, is it possible to run it with the entire source code available? I manage to run it for a single target, such as
pants repl components/example/greeting:greeting
and access the function(s) in that module. The other modules in the
example
namespace are unavailable. I have tried with
pants repl ::
but that exits with a failure, caused by failing to add third-party dependencies (example repo in thread).
Last part of the failure when running
pants repl ::
Copy code
raise ResolveError(
pex.environment.ResolveError: Failed to resolve requirements from PEX environment @ /private/var/folders/w_/y85gkc6s0hz4_35b4srjbcf80000gn/T/pants-sandbox-KILV1G/local_dists.pex.
Needed cp311-cp311-macosx_14_0_arm64 compatible dependencies for:
 1: fastapi~=0.111.0
    Required by:
      my_fastapi_project 0.0.1
    But this pex had no ProjectName(raw='fastapi', validated=False, normalized='fastapi') distributions.
 2: uvicorn~=0.29.0
    Required by:
      my_fastapi_project 0.0.1
    But this pex had no ProjectName(raw='uvicorn', validated=False, normalized='uvicorn') distributions.
c
I’ve done this: (will be ugly, on mobile..) pants export —resolve=python-default ./dist/export/virtualenvs/…/bin/pip install ipython PYTHONPATH=$(pants roots | paste -sd : -) ./dist/export/…./bin/ipython This will give you a repl with all code and all 3rd party libs importable (assumes a single resolve repo)
b
Thank you! This solved two problems for me: • running the repl with all deps (source code + third-party libs) • starting my editor (emacs) with the environment properly setup (knowledge about the namespaces, the pants "roots", and the libraries. edit: I confused myself there - actually were in the middle of constructing a classic
.venv
outside of pants. Still an issue for me, the combination of knowing about deps and libs. By prefixing
ipython
or
emacs
with the calculated extra pythonpaths from you + the path to the virtual env:
Copy code
PYTHONPATH=$(pants roots | paste -sd : -):dist/export/python/virtualenvs/python-default/3.11.9/lib/python3.11/site-packages/ ipython
🙏
👍 1