Are there example monorepos with multiple `pyproje...
# general
g
Are there example monorepos with multiple
pyproject.toml
and
poetry.lock
files? I've looked at the example-python repo and read most of the getting starting docs with some additional docs on python and I don't understand if I need anything more than
poetry_requirements(name="poetry")
in my
BUILD
files, i.e. do I need to add python_sources? ๐Ÿงต
pants.toml for context
Copy code
[GLOBAL]
pants_version = "2.19.0"

backend_packages = [
  "pants.backend.docker",
  "pants.backend.experimental.python.lint.ruff",
  "pants.backend.experimental.terraform",
  "pants.backend.experimental.terraform.lint.tfsec",
  "pants.backend.experimental.tools.yamllint",
  "pants.backend.python",
  "pants.backend.python.lint.black",
  "pants.backend.python.typecheck.mypy",
  "pants.backend.shell.lint.shellcheck",
  "pants.backend.shell.lint.shfmt",
]

[source]
root_patterns = ["/"]

[ruff]
config = ".ruff.toml"

[black]
config = ".black"

[python]
interpreter_constraints = ['>=3.9,<3.11']
r
Pants supports pyproject.toml but it generates its own lock file. So it won't use poetry.lock You can have multiple lock files through Multiple resolves
g
Can that be committed to code?
r
Yes it can!
โœ… 1
g
I found a few blog posts etc on poetry but nothing that strings it all together and I'm feeling a bit overwhelmed.
r
Yes it should be !
g
OK, I think I'll try using that methodology for several lock files.
do I need to also specify python_sources() when using poetry_requirements(name="poetry")?
r
You should read about parametrized mechanism if you are going to import one project in another https://www.pantsbuild.org/2.19/docs/python/overview/lockfiles#multiple-lockfiles
๐Ÿ‘ 1
Especially this part
Transitive dependencies must use the same resolve
All transitive dependencies of a source target must use the same resolve. Pants's dependency inference already handles this for you by only inferring dependencies between targets that share the same resolve. If you manually add a dependency across different resolves, Pants will error with a helpful message when you try to use that dependency.
๐Ÿ‘€ 1
You will have to specify which resolve it is part of
poetry_requirements(name="<custom_name>", resolve="<custom_name>")
๐Ÿ‘ 1
g
Should
pants tailor ::
be generating
python_sources
and
python_tests
in
BUILD
files or am I expected to add all of those by hand?
r
Should be able to generate most of it if your source root etc are properly defined. If not you will have to add it manually
g
I have about 150 individual pyproject.toml at varying depths within a monorepo. I set:
Copy code
[source]
root_patterns = ["/"]
r
I don't think it adds any information about resolve though. So you'll have to modify them later. You can asd sub project level resolve default value for all targets using _`__default__`_. Check https://www.pantsbuild.org/blog/2022/10/26/pants-2-14#less-boilerplate-via-hierarchical-defaults-for-target-field-values
g
What I'm hearing is it really pays to have a single py directory at the top level of the monorepo and then a lot of this can just be inferred.
r
I have about 150 individual pyproject.toml at varying depths within a monorepo. I set:
[source]
root_patterns = ["/"]
It depends on what your import statements look like. Read the docs please about source root and their purpose.
g
I read that doc entirely and came away with just having it set to "/"
I originally had this:
Copy code
[source]
marker_filenames = ["pyproject.toml"]
but when the docs said it was equivalent with
Copy code
[source]
root_patterns = ["/"]
I went with that instead.
๐Ÿ‘ 1
r
Yeah single resolve makes it simpler especially if there are intra dependencies among sub packages
๐Ÿ‘ 1
c
๐Ÿ™Œ 1
https://pantsbuild.slack.com/archives/C046T6T9U/p1708626508874379?thread_ts=1708625784.153949&amp;cid=C046T6T9U yes,
pants tailor
adds those targets for you. if it does not, something is off.
๐Ÿ™Œ 1