not sure if this is possible, but is there a pants...
# general
h
not sure if this is possible, but is there a pants command that’s essentially equivalent to
poetry install
? I ask because it’s convenient to be able to create a local environment for debugging that contains every package, but unfortunately i’m not able to use
poetry install
in our monorepo because of a tensorflow dependency that doesn’t work on M1 macs. [long story short: https://pantsbuild.slack.com/archives/C046T6T9U/p1642537615072100 we’re using an older tensorflow version in
pyproject.toml
(which doesn’t work on M1) and then using markers to tell pants to ignore it on M1 and install
tensorflow-macos==2.7.0
instead by setting it in a
python_requirement_library
in a BUILD file] it would be helpful if there were some pants command to create an environment with contains everything, including these additional pants constraints
additional context:
Copy code
#pyproject.toml
...
tensorflow = { version = "2.5.1", markers = "sys_platform != 'darwin' or platform_machine != 'arm64'" }
...
Copy code
#BUILD
python_requirement_library(
    name="tensorflow-macos",
    requirements=[
        "tensorflow-macos==2.7.0; sys_platform == 'darwin' and platform_machine == 'arm64'",
        "tensorflow-metal==0.3.0; sys_platform == 'darwin' and platform_machine == 'arm64'",
    ],
)

python_library(
    name="local-tensorflow",
    sources=["**/*.py"],
    dependencies=[":tensorflow-macos"],
)
h
I haven't used this goal so am not 100% certain, but I think you'd want to use
export
to create a virtualenv. Does that look right? https://www.pantsbuild.org/docs/setting-up-an-ide#third-party-dependencies-python
e
pants repl <files or targets>
is another option. Is a repl session with all the deps good enough for debugging or do you need an at-rest venv with access to the activated scripts, etc?
h
@hundreds-father-404 that’s exactly what I was looking for! unfortunately
export
only exists in 2.9, but the instructions for 2.7 work perfectly 🙂 one question though: is there a way to also include dev dependencies? e.g. we have ipython and jupyter, but obviously they’re not used directly in the codebase so they’re not installed as a third-party dependency @enough-analyst-54434 that’s also very useful, but it’s nice to have the ability to run scratch scripts as well. also, i don’t know if i’m doing something wrong, but i’m not able to import anything in that pants console, neither third-party dependencies nor first-party code
h
one question though: is there a way to also include dev dependencies? e.g. we have ipython and jupyter, but obviously they’re not used directly in the codebase so they’re not installed as a third-party dependency
There is not currently, unfortunately. But if you're using tool lockfiles in 2.7, you could set up a custom tool lockfile (by setting
[black].lockfile
etc), then use that little bash snippet to also do
-r path/to/black_lock.txt
. I think that https://github.com/pantsbuild/pants/issues/12449 might be relevant to your question. It would allow you to define a "dev requirement" via
python_requirement
(and
python_requirements
etc), so it would be included in
export
e
i don’t know if i’m doing something wrong, but i’m not able to import anything in that pants console, neither third-party dependencies nor first-party code
Huh, yeah - that should work.
./pants repl
doesn't mean much if you can't import anything! Then that just means
python
!
Yeah, so @high-energy-55500 repl not working for you is strange / a bug. In the pants repo for example:
Copy code
$ ./pants dependencies src/python/pants/util/contextutil.py
3rdparty/python#ansicolors
src/python/pants/util/dirutil.py
And I can import them both, 3rdparty dep and local src:
Copy code
$ ./pants repl src/python/pants/util/contextutil.py
Python 3.7.12 (default, Oct 28 2021, 09:58:59) 
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import colors
>>> print(colors.__file__)
/home/jsirois/.cache/pants/named_caches/pex_root/installed_wheels/f25c1d6c49102373d349f5f8f1cddc41ce409e15/ansicolors-1.1.8-py2.py3-none-any.whl/colors/__init__.py
>>> from pants.util import dirutil
>>> print(dirutil.__file__)
/home/jsirois/dev/pantsbuild/jsirois-pants/.pants.d/tmpqv30ctos/src/python/pants/util/dirutil.py
>>> 
now exiting InteractiveConsole...