https://pantsbuild.org/ logo
#general
Title
# general
r

refined-addition-53644

04/04/2022, 9:19 AM
Hi, would it be possible to maintain multiple poetry based (i.e. multiple
pyproject.toml
) python projects using multiple lockfiles "resolves"? I guess the issue could be if these projects have some common third party dependencies. We have a monorepo but it contains multiple python packages generated using poetry which have their own dependencies.
b

bitter-ability-32190

04/04/2022, 3:30 PM
You should be able to use Pants' 2.10 or greater "multiple resolves" feature. https://www.pantsbuild.org/docs/python-third-party-dependencies#user-lockfiles
👍 1
r

refined-addition-53644

04/04/2022, 3:35 PM
yeah that's what prompted me to ask here, but as it's mentioned
If you want the same requirement to show up in multiple resolves, you currently need to create a distinct target per resolve. This will be improved in Pants 2.11 through a new
parametrize()
mechanism.
I suppose this is yet to be added to 2.11 though.
b

bitter-ability-32190

04/04/2022, 3:35 PM
I think it might be in, but It's cutting edge (so possibly not yet documented)
h

hundreds-father-404

04/04/2022, 3:36 PM
it's added in 2/11, just not documented. my goal for this weeek is to update 2.11 docs
❤️ 1
😮 1
r

refined-addition-53644

04/04/2022, 3:49 PM
Copy code
# src/py/utils/BUILD

python_sources(
    # The files in this folder can be used with both resolves.
    #
    # This `parametrize` mechanism is added in Pants 2.11. In
    # Pants 2.10, you can explicitly create multiple targets.
    resolve=parametrize("data-science", "web-app"),
)
@hundreds-father-404 How does this work? If I have say
pandas
defined as a dependency in both
data-science
and
web-app
, putting the
parameterize
line will make sure to just generate one target associated with
pandas
?
h

hundreds-father-404

04/04/2022, 3:57 PM
parametrize creates one target per param: src/py/utils/f.py@resolve=data-science src/py/utils/f.py@resolve=web-app run ./pants list or peek to see that a target only infers deps from the same resolve, so it should Just Work. note you only need to use parametrize when code needs to work w/ multiple resolves
r

refined-addition-53644

04/04/2022, 4:06 PM
So if
pandas
is defined in both
data-science
and
web-app
, I only need to use one of the resolves from
data-science
and
web-app
where
pandas
is a 3rd party dependency?
w

witty-crayon-22786

04/04/2022, 4:07 PM
fwiw, there are docs for
parametrize
in 2.11: https://www.pantsbuild.org/v2.11/docs/targets#parametrizing-targets … but they’re not specific to this usecase
relatedly, 2.10.x’s error messages probably need to do a better job explaining what to do when you have conflicting resolve: https://github.com/pantsbuild/pants/issues/14864
4 Views