I fail on understanding how to configure the `pyth...
# general
b
I fail on understanding how to configure the
python_distribution
in the BUILD file when building wheels. I would like to use a
pyproject.toml
file as the source of metadata, that also defines the python source files. If I understand the flow correctly, the
pants package
command do the building in a sandbox and therefore need to know about the paths to use. I got the
pyproject.toml
right, and the Python files too, if I specify one of the targets. Is it possible to specify the top folder only? Current setup, in a BUILD file at a subfolder (projects/my_fastapi_project/BUILD):
Copy code
resource(name="pyproject", source="pyproject.toml")

python_distribution(
    name="my-fastapi-project",
    dependencies=[
        ":pyproject",
        "bases/example/greet_api:greet_api",
    ],
    provides=python_artifact(),
    sdist = False,
    generate_setup = False,
)
I would like to be able to set the "bases" part as something like
bases
or
bases/*
or even
bases/example
- but that causes failure in the package command. Posting my experimenting-repo in a thread (with the commits showing the steps I'm taking to learn Pants.
The contents of the project-specific pyproject.toml
Copy code
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "my_fastapi_project"
version = "0.0.1"
description = 'A Python Polylith example code repo'
authors = [{ name = "David Vujic" }]


[tool.hatch.build.targets.wheel.force-include]
"../../bases/example/greet_api" = "example/greet_api"
"../../components/example/greeting" = "example/greeting"
"../../components/example/log" = "example/log"
What I also don't understand is how it will find the
components
when I only specified the
bases
folder in the python_distribution.
If I skip the
bases/example/greet_api:greet_api
I get a failure.
h
if
bases/example/greet_api:greet_api
is the entry point, and it transitively imports everything it depends on, then dependency inference should pull in all the deps you need. Pants will plop those into a sandbox, along with pyproject.toml, and then run setup.py (or an alternative pep517 build backend of your choice). So if the wrong thing is happening the first place to investigate is the sandbox.
You can keep those around with
--keep-sandboxes=always
Pants will log the path to every process sandbox, and you can poke around in there, run commands etc
So if
components
isn't in the sandbox, then I guess there is no import chain from
bases
to it, and you'll have to add it as an explicit dep
You can inspect those inferred import chains with `pants dependencies`: https://www.pantsbuild.org/2.20/reference/goals/dependencies
b
Thanks! The behavior is correct, I didn’t understand how Pants knew about the components, but understand now that it follows the imports.
h