Skip to content

Conversation

@cognifloyd
Copy link
Member

@cognifloyd cognifloyd commented Feb 14, 2023

Background

This is another part of introducing pants, as discussed in various TSC meetings.

Related PRs can be found in:

Overview of this PR

This PR adds pants macros that reduce boilerplate around defining python_distribution():

  • st2_license()
  • st2_component_python_distribution()
  • st2_runner_python_distribution()

The next PR will actually add those macros to the relevant BUILD files.

See #5890 for a description of pants macros and what is involved in using them in pants.

st2_license() macro

We need to add a LICENSE file to all of our wheels. When building wheels, we don't have to add any special metadata to the setup.py setup() call (or pyproject.toml or similar); we only need to put the LICENSE file in the directory that will be the wheel.

def st2_license(**kwargs):
"""copy the LICENSE file into each wheel.
As long as the file is in the src root when building the sdist/wheel,
setuptools automatically includes the LICENSE file in the dist-info.
"""

st2_*_python_distribution() macros

These macros create:

  • a copy of the LICENSE file using the st2_license macro.
  • a python_artifact object with the details needed to generate the setup.py kwargs. For example, it includes the version_file arg which is unique to pants-plugins/release which uses this to inject the version based on that file.
  • a python_distribution target with the metadata for creating the wheel.

Using this macro is like creating a python_distribution like this in each of the BUILD files:

python_distribution(
    provides=python_artifact(
        name="...",  # the wheel name
        description="...",
        version="3.9dev",
        zip_safe=...,
        scripts=[...],
    ),
    dependencies=[
        "./....",  # the primary python module
        ":license",
    ],
    repositories=[
        "@pypi",  # we plan to publish this on pypi
    ],
)

st2_component_python_distribution() macro

This is meant for for our primary components: st2common, st2auth, st2api, st2client, etc.

For example, in the next PR this is how we'll define the st2api distribution:

st2/st2api/BUILD

Lines 1 to 4 in 7032faf

st2_component_python_distribution(
component_name="st2api",
scripts=["bin/st2api"],
)

st2_runner_python_distribution() macro

This is meant for our runners: contrib/runners/*_runner.

For example, in the next PR this is how we'll define the noop runner's distribution:

st2_runner_python_distribution(
runner_name="noop",
description=(
"No-Op action runner "
"for the StackStorm event-driven automation platform"
),
)

@cognifloyd cognifloyd added this to the pants milestone Feb 14, 2023
@cognifloyd cognifloyd self-assigned this Feb 14, 2023
@pull-request-size pull-request-size bot added the size/L PR that changes 100-499 lines. Requires some effort to review. label Feb 14, 2023
@cognifloyd cognifloyd marked this pull request as ready for review February 14, 2023 19:15
@cognifloyd cognifloyd requested a review from a team February 15, 2023 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pantsbuild size/L PR that changes 100-499 lines. Requires some effort to review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants