nutritious-morning-93919
10/02/2023, 9:50 PMbroad-processor-92400
10/02/2023, 10:07 PMpy
(and any other immediate children of /
) is the "entry point" of that library, so Pants will understand an import like from py.shared.logging import configure
as referring to the logging.py
file... which sounds like it is wrong for you!
Potentially you want a source root configuration roots = ["/py/shared", "py/src/apps"]
. This means that Pants will understand that the immediate children of those directories are the top-level libraries for import statements.
(For the specifics of this case, calling a file logging.py
to import like import logging ...
is likely to be very confusing, as it conflicts with the standard library logging
module)nutritious-morning-93919
10/02/2023, 10:21 PMnutritious-morning-93919
10/02/2023, 10:21 PMnutritious-morning-93919
10/02/2023, 10:25 PMnutritious-morning-93919
10/02/2023, 10:26 PMbroad-processor-92400
10/02/2023, 10:26 PM/
means it only applies to that exact path starting at the pants.toml
file ("build root") which might be fine for you; while no leading /
means it finds any directory path that matches. e.g. a common source root config is roots = ["src"]
to find any src/
directory anywhere in the repo.nutritious-morning-93919
10/02/2023, 10:27 PMenough-analyst-54434
10/02/2023, 10:28 PMnutritious-morning-93919
10/02/2023, 10:28 PMenough-analyst-54434
10/02/2023, 10:29 PMenough-analyst-54434
10/02/2023, 10:29 PMnutritious-morning-93919
10/02/2023, 10:29 PMnutritious-morning-93919
10/02/2023, 10:41 PMenough-analyst-54434
10/02/2023, 10:42 PMenough-analyst-54434
10/02/2023, 10:44 PMnutritious-morning-93919
10/02/2023, 10:53 PMnutritious-morning-93919
10/02/2023, 10:55 PMenough-analyst-54434
10/02/2023, 11:01 PM/
only makes sense for a single language + single project - exactly what the example repos all are. So those repos may be horrible guidance for you when confused about source roots and imports.
As far as providing guidance to the arbitrary decision for a repo with many languages and/or projects - I've personally lived in 2 approaches. Google did src/java
, src/python
, src/cpp
- 1 root per language, all 1000s of projects / teams / apps living under there together. Twitter had 1 monorepo that did that too, and another monorepo (insert joke here) that did 1 source root per project - little fiefdoms: finch/src/scala
, finch/src/python
, crow/src/scala
, etc... (where projects tended to have damn bird names.enough-analyst-54434
10/02/2023, 11:05 PMnutritious-morning-93919
10/03/2023, 12:12 AM