limited-insurance-37393
08/12/2022, 1:58 PMlib module as a distribution for publishing to PyPI, and I also have code in a sibling module that depends on the contents of lib which I want to package separately. The layout looks like:
src/
concourse/
BUILD
lib/
pipelines/limited-insurance-37393
08/12/2022, 2:08 PMhundreds-father-404
08/12/2022, 2:12 PMpython_source target per file, unless you have conflicting metadata for that same file.
Note that python_sources is a target generator; it's only for boilerplate reduction to generate those individual python_source targets per file. When you do things like package as a distribution, all Pants cares about is the individual targets
That means that you have some options:
1. Use only one python_sources target generator, and then make your dependencies more granular. Right now, it sounds like you're depending on the python_sources target, which is an alias for "all of its generated targets". You can instead list the individual generated targets, usually like src/concourse/lib/utils.py
2. Or, have two python_sources targets but update sources field so they don't overlap, using ! globs to exclude possiblylimited-insurance-37393
08/12/2022, 2:13 PMhundreds-father-404
08/12/2022, 2:14 PMlimited-insurance-37393
08/12/2022, 2:41 PMpython_sources(
name="concourse-lib",
)
python_sources(
name="concourse-pipelines",
sources=["!lib/", "!__init__.py"]
)
python_distribution(
name="ol-concourse",
dependencies=[
":concourse-lib",
],
description="A Pythonic way to manage your Concourse pipelines",
provides=python_artifact(
name="ol-concourse",
version="0.1.0",
),
)
python_distribution(
name="ol-concourse-pipelines",
dependencies=[":concourse-pipelines", ":concourse-lib"],
description="Concourse pipeline definitions used at MIT Open Learning",
provides=python_artifact(
name="ol-concourse-pipelines",
version="0.1.0",
)
)limited-insurance-37393
08/12/2022, 2:41 PM⇉ ./pants package src/concourse:ol-concourse
10:39:47.77 [ERROR] 1 Exception encountered:
AmbiguousOwnerError: Found multiple sibling python_distribution targets that are the closest ancestor dependees of src/concourse/__init__.py:concourse-lib and are therefore candidates to own it: src/concourse:ol-concourse-pipelines, src/concourse:ol-concourse. Only a single such owner is allowed, to avoid ambiguity. See <https://www.pantsbuild.org/v2.12/docs/python-distributions> for how python_sources targets are mapped to distributions. See <https://www.pantsbuild.org/v2.12/docs/python-distributions>.limited-insurance-37393
08/12/2022, 2:42 PMpython_sources to
python_sources(
name="concourse-lib",
sources=["lib/**/*.py", "lib/*.py", "__init__.py"]
)
then I get
⇉ ./pants package src/concourse:ol-concourse
10:40:28.72 [ERROR] 1 Exception encountered:
NoSourceRootError: No source root found for `.`. See <https://www.pantsbuild.org/v2.12/docs/source-roots> for how to define source roots.limited-insurance-37393
08/12/2022, 2:45 PMrefined-addition-53644
08/12/2022, 3:09 PMrefined-addition-53644
08/12/2022, 3:13 PMlimited-insurance-37393
08/12/2022, 4:03 PMNoSourceRootError with the following contents of the BUILD file
python_sources(
name="concourse-lib",
sources=["lib/**/*.py", "lib/*.py", "__init__.py"]
)
python_distribution(
name="ol-concourse",
dependencies=[
":concourse-lib",
],
description="A Pythonic way to manage your Concourse pipelines",
provides=python_artifact(
name="ol-concourse",
version="0.1.0",
),
)refined-addition-53644
08/12/2022, 4:18 PMlib as a sourcelimited-insurance-37393
08/12/2022, 4:20 PMlib . Unfortunately that's still not enough to get rid of the NoSourceRootError for .refined-addition-53644
08/12/2022, 4:27 PMconcourse directory
python_distribution(
name="ol-concourse",
dependencies=[
"./concourse:concourse-lib",
],
description="A Pythonic way to manage your Concourse pipelines",
provides=python_artifact(
name="ol-concourse",
version="0.1.0",
),
)
And the BUILD inside the concourse just has the
python_sources(
name="concourse-lib",
sources=["lib/**/*.py", __init__.py])
• You can always refer to target in sub directory using relative path from the target definition
• For anything else you need to provide the path relative to pantslimited-insurance-37393
08/12/2022, 4:28 PMlimited-insurance-37393
08/12/2022, 4:29 PMrefined-addition-53644
08/12/2022, 4:31 PMlib as far as I see the reporefined-addition-53644
08/12/2022, 4:33 PMpython_sources(
name="concourse-lib",
dependencies=["./lib:concourse-libs"])refined-addition-53644
08/12/2022, 4:41 PMconcourse. Sorry that wasn’t necessary.limited-insurance-37393
08/12/2022, 4:54 PMol-concourse-pipelines distribution one level deeper under the pipelines directory and set the top-level BUILD under src/concourse to be
python_sources(
name="concourse",
)
python_distribution(
name="ol-concourse",
dependencies=[
":concourse",
"./lib:concourse-libs",
],
description="A Pythonic way to manage your Concourse pipelines",
provides=python_artifact(
name="ol-concourse",
version="0.1.0",
),
)