I would like to create two different packages from...
# general
b
I would like to create two different packages from the same python distribution, somehow parameterizing it, but I am unsure of how to do it correctly. So something like this:
Copy code
python_sources(
    name="python-core",
    sources=["file1.py", "file2.py"],
)

python_sources(
    name="python-superset",
    sources=["file1.py", "file2.py", "file3.py"],
)

python_distribution(
    name="python-dist",
    dependencies=parameterize("python-core", "python-superset"),
    provides=python_artifact(
        name="python-artifact",
        version="1.0.0",
        description="blah blah blah.",
        author="Author Authorson",
        classifiers=[
            "Programming Language :: Python :: 3.8",
        ],
    ),
)
I know the parameterize does not work here but I would like to somehow be able to specify what source list to use at packaging time. Doesn't matter if it only builds one or both cases.
I can see 2.16 has env() which would allow me to do something like this 👀
Okay I am dumb, I can just have multiple targets in one...
👆 1
l
can you show what that looks like?
b
I just added two python_distribution to my BUILD file. One for each python_source.
🙂 1
l
did you do anything to avoid repetition between the two targets? (for example of blah blah blah 🙂)
b
I am unsure what you mean
I just copy-pasted one from the other and changed the dependency
and used different names for the python_distribution and python_artifact to not have any clashes
👍 1
h
I think multiple targets sounds like the right way to model this
You can use a macro to cut down on repetitive boilerplate (or just set local vars in the BUILD file, it's eval'd as python)
👍 1
b
I would actually like the second distribution to depend on the first distribution instead, how would you go about doing that? I looked at the docs
As in, it would be cool if I could build a core package and a super set package that would depend on the core package but keeping them separate
is it possible to add a distribution to the dependencies of another distribution?
h
Yes. In fact, it happens automatically if you let Pants generate the setup.py. If it sees that code in distribution B depends on code in distribution A it will add a requirement on A in B's metadata. You don't need to add an explicit dep.
But the two packages do need to be disjoint - they can't share code (that's just good hygiene in general, that Pants enforces)
you don't want to publish the same code in two distributions, really ever
b
yes I plan on having file1, file2 in one and file3, file4 in another package where file3 and file4 then import from file1 and file2
h
Then that import is enough for Pants to know to add the requirement in the distribution metadata
b
alright neat, will try it out, thanks!
ah, it is just not possible to do this in the same BUILD file?
it works if I use a BUILD file one level out for the distribution that has files importing from the other distribution
h
They can be in the same BUILD file, AFAICR
b
Only seems like it if distribution D1 depending on sources S1 does not import from S2 depended on by D2, if they are inside the same build file. Or at least I have gotten ambiguity error when doing it.
h
If it's the BUILD file above then you do have ambiguity because file1.py and file2.py are in two
python_sources()
.
b
Yes but in my actual use case I came to I don't share any files between python_sources.
Copy code
version = "1.0.0"
author = "Veo"
name = "math"

description_math_core = "Sunstone core math library (numpy)"

sources = ["projections_v2.py", "fov.py", "virtualcam.py"]

python_sources(
    name=f"{name}-core",
    sources=sources,
)

python_distribution(
    name=f"{name}-core-dist",
    dependencies=[f":{name}-core"],
    provides=python_artifact(
        name=f"{name}-core-artifact",
        version=version,
        description=description_math_core,
        author=author,
    ),
)

description_math = "Mmath library (numpy+opencv+cuda)"

sources = ["resampling.py", "cropping.py"]

python_sources(
    name=f"{name}",
    sources=sources,
)

python_distribution(
    name=f"{name}-dist",
    dependencies=[f":{name}"],
    provides=python_artifact(
        name=f"{name}-artifact",
        version=version,
        description=description_math,
        author=author,
    ),
)
Here resampling.py imports from projections_v2.py and causes the ambiguity error
h
Hmm, what is the exact error message you get?
b
Copy code
AmbiguousOwnerError: Found multiple sibling python_distribution targets that are the closest ancestor dependents of sunstone/math/projections_v2.py:math-core and are therefore candidates to own it: sunstone/math:math-dist, sunstone/math:math-core-dist. Only a single such owner is allowed, to avoid ambiguity. See <https://www.pantsbuild.org/v2.16/docs/python-distributions> for how python_sources targets are mapped to distributions. See <https://www.pantsbuild.org/v2.16/docs/python-distributions>.
h
Ah, so
sunstone/math:math-dist
and
sunstone/math:math-core-dist
do both depend on
sunstone/math/projections_v2.py
?
directly, I mean?
b
I would say
sunstone/math:math-dist
only indirectly depends on projections_v2.py considering it depends on a source file that imports projections_v2.py