whats the best way to include python in a package ...
# general
b
whats the best way to include python in a package distribution? If I just do:
Copy code
python_distribution(
    name="hermes_package",
    dependencies=[":pyproject"],
    provides=python_artifact(
        name="mypackage",
    ),
    generate_setup=True,
    repositories=["@codeartifact"],
)
I publish out a package with no code. I can do:
Copy code
python_distribution(
    name="hermes_package",
    dependencies=[":pyproject", "mypackage/mypackage/module1:lib", "mypackage/mypackage/module2:lib", ...],
    provides=python_artifact(
        name="mypackage",
    ),
    generate_setup=True,
    repositories=["@codeartifact"],
)
but then I have to list every module, trying a wildcard:
Copy code
dependencies=[":pyproject", "mypackage/mypackage::"],
is not supported: `InvalidFieldException: mypackage/BUILD3 Failed to get dependencies for hermeshermes package The address
mypackage/mypackage::
from the
dependencies
field from the target mypackage:mypackage_package ended in a wildcard (
::
), which is not supported.` Is there a way to include all of the code for package without needing to list it all out?
h
Usually you just need a single explicit dependency on the
main
module, or some entry point, and the rest gets pulled in by dependency inference.
So for example if your
pyproject
contains the entry point, the rest should come along.
What do you see if you
pants dependencies --transitive path/to/distribution:hermes_package
That tells you what Pants sees as dependencies
b
oh that makes sense, my package is a utils package with no obvious entrypoint, just a bunch of helper methods
so currently if I don't list all the dependencies I just see:
Copy code
pants dependencies --transitive hermes:hermes_package

hermes:pyproject
my pyproject is simply:
Copy code
[build-system]
# PEP 517 specifies the build backend as "requires"
requires = ["setuptools>=42", "wheel"]
# The build-backend field specifies what tool will be used to perform the build.
build-backend = "setuptools.build_meta"
I guess this is a python packaging question in general, not pants specific
h
You need some chain of dependencies for Pants to follow. If you have a bunch of helper methods that are entirely independent then you will need to depend on them explicitly, because otherwise Pants has no idea what should go in the dist.
Well, it's a bit of both.
Generally you'd write a setup.py/setup.cfg/pyproject.toml/whatever that describes what should go in the dist
Pants can infer that for you, from dependencies, but you can also write an explicit config instead
In other words, in the worst case you're no worse off than doing things without Pants, you just have to manually configure the dist build via whatever method you like.
Should be ample documentation of both options
b
thanks, I'll have a look, probably just list out the dependencies for now
h
At least you need to seed the dependencies with something from which the remaining deps can be inferred
There must be some entry points or API endpoints or whatever that will do