Hi, not very experienced here. Trying to setup a p...
# general
b
Hi, not very experienced here. Trying to setup a python monorepo. I'm starting from the example-python repo, and a virtualenv. I want to be able to
import helloworld
from anywhere (as long as my virtualenv is sourced). Any ideas what command to run? (I'm on ubuntu/linux if that matters) In general in my project, I'm hoping I'd have many packages like
helloworld
, and I could "build" all of them into my virtualenv with one command.
👋 1
1
h
Hi, can you explain a bit further what you mean by "from anywhere"?
I think your question relates to the concept of source roots (https://www.pantsbuild.org/docs/source-roots) but I want to be sure I understand it
And also if you could elaborate on what you're using the virtualenv for. Usually Pants sets up venvs for you under the covers, as needed, and you don't need to explicitly source anything. So my answer will slightly depend on what you're trying to do.
b
Thanks for responding! • "from anywhere" means e.g I can run
ipython
anywhere (in any directory) on my machine, and run the line
import helloworld
in the interpreter, and it will know I'm talking about the helloworld package in the example-python repo. ◦ the same way I could, if I did
pip install fire
in my virtualenv,
import fire
in an
ipython
session, and it would use the version of
fire
in my virtualenv • I'm using virutalenv to isolate my python environment for each thing I'm working on. So for the monorepo I'm trying to build, when I'm working on it, I would be in a virtualenv.
Probably I am not using pants to it's full potential, but right now I'm doing ok with virtualenv and poetry to manage 3rd party stuff. Now I just need something to “install” our in house packages so they can be imported, if that makes any sense 🤷‍♂️
I guess my first problem is that “helloworld” is not a package, since it has no setup.py or pyproject.toml ?
h
It's a package, it's just not built into a publishable distribution, like a wheel
Unless you need it to be
For in-repo consumption you don't need it to be
b
if I make a new file
example-python/temp/temp.py
with a single line:
Copy code
import helloworld
and run
python temp.py
from
example-python/temp/
, I'll get the error
ModuleNotFoundError: No module named 'helloworld'
h
Well, yes, since example-python/helloworld isn't on your sys.path in that case
But you're not using Pants at all in that example case
If you have your source roots set up correctly, and you
./pants run example-python/temp/temp.py
then the import should work
(punting on the question of how to run from within a subdir, for now...)
b
ah ok, thanks! This makes sense. I think I misunderstood what pants is.
Well, yes, since example-python/helloworld isn't on your sys.path in that case
exactly, I was looking for something that would automatically add all our internal packages with a single command. E.g. for now I can make a
setup.py
file in each internal package, and manually
pip install -e PKG_PATH
to add that internal package to my virtualenv. I was just looking for a single command to automagically find our internal packages (and maybe even create the
setup.py
files for me 😂 ). but I think I know now that is not what pants is for. Still excited to use pants for linting and testing! Thanks!
h
Ah yes, idiomatic use of Pants means you don't need those multiple setup.py files
You do things like
./pants run ...
,
./pants test ...
,
./pants package ...
and it knits together the in-repo and external dependencies for you.
👍 1
It can generate setup.py files for things you want to publish, but that's not typically how you'd use it just for consuming in-repo dependencies
👍 1
b
makes sense! I think losing
python ..
might be too much for my team right now 😂 . But the
./pants test
and
./pants lint
could be good starting points for us 😄
h
Editable installs (i.e., pip -e) don't play nicely with Pants because they violate assumptions about caching and hermeticity
👍 1