Is there an example repo with multiple python pack...
# general
f
Is there an example repo with multiple python packages which each have individual tests? something like the below for structure package1 package1 tests readme.md
would love some advice here — for being a monorepo oriented project, i can’t find many examples of complex projects
a
The python example project has a structure of
Copy code
├── helloworld
│   ├── BUILD
│   ├── __init__.py
│   ├── greet
│   │   ├── BUILD
│   │   ├── __init__.py
│   │   ├── greeting.py
│   │   ├── greeting_test.py
│   │   └── translations.json
│   ├── main.py
│   └── translator
│       ├── BUILD
│       ├── __init__.py
│       ├── translator.py
│       └── translator_test.py
├── BUILD
├── LICENSE
├── README.md
├── mypy.ini
├── pants
├── pants.ci.toml
├── pants.toml
├── pants_from_sources
├── python-default.lock
└── requirements.txt
greet
and
translator
both have individual tests with associated BUILD files. Does that help?
f
hm, thats more of a "single package", right? you have a single python package called
helloworld
in this case. What if i want to have multiple? for example having
greet
and
translate
as two packages;
from greet import X
instead of
from helloworld.greet ...
. Is there a recommended structure for that? Right now I do:
Copy code
greet
  - greet 
     - greeting.py
   - tests
   - README.MD 
   - pyproject.toml
   - BUILD
translate
  - translate
     - translate.py
   - tests
   - README.MD 
   - pyproject.toml
   - BUILD
is that the right way?
a
I think what you are asking is how to import local packages in the same way one imports a 3rd party package? Pants uses source roots to indicate which directories should be treated as import targets (libraries, etc). I've modified the python example project to demonstrate. You can see the modifications using git
git diff HEAD~
once you've unzipped the attachment. The monorepo structure demonstrated is:
Copy code
├── helloworld
│   ├── BUILD
│   ├── __init__.py
│   └── main.py
├── libs
│   ├── greet
│   │   ├── BUILD
│   │   ├── __init__.py
│   │   ├── greeting.py
│   │   ├── greeting_test.py
│   │   └── translations.json
│   └── translator
│       ├── BUILD
│       ├── __init__.py
│       ├── translator.py
│       └── translator_test.py
├── pants.toml
The change to
root_patterns
in
pants.toml
enables the libs to be imported directly. I hope this helps
1
👍 1