Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pants: Add st2_*_python_distribution() macros to pants-plugins/macros.py #5901

Merged
merged 5 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ python_test_utils(
name="test_utils",
skip_pylint=True,
)

file(
name="license",
source="LICENSE",
)
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Added
to pants' use of PEX lockfiles. This is not a user-facing addition.
#5778 #5789 #5817 #5795 #5830 #5833 #5834 #5841 #5840 #5838 #5842 #5837 #5849 #5850
#5846 #5853 #5848 #5847 #5858 #5857 #5860 #5868 #5871 #5864 #5874 #5884 #5893 #5891
#5890 #5898
#5890 #5898 #5901
Contributed by @cognifloyd

* Added a joint index to solve the problem of slow mongo queries for scheduled executions. #5805
Expand Down
99 changes: 99 additions & 0 deletions pants-plugins/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,105 @@
# limitations under the License.


def st2_publish_repos():
"""Return the list of repos twine should publish to.

Twine will publish to ALL of these repos when running `./pants publish`.

We use ST2_PUBLISH_REPO, an env var, To facilitate switching between
@testpypi and @pypi. That also means someone could publish to their own
private repo by changing this var.

Credentials for pypi should be in ~/.pypirc or in TWINE_* env vars.
"""
# TODO: switch from hard-coded to env() once we upgrade to pants 2.16
# return [env("ST2_PUBLISH_REPO", "@pypi")] # noqa: F821
return ["@pypi"]


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.
"""
if "dest" not in kwargs:
raise ValueError("'dest' path is required for st2_license macro")
relocated_files( # noqa: F821
name="license",
files_targets=["//:license"],
src="",
**kwargs,
)


def st2_runner_python_distribution(**kwargs):
"""Create a python_distribution (wheel/sdist) for a StackStorm runner."""
runner_name = kwargs.pop("runner_name")
description = kwargs.pop("description")

st2_license(dest=f"contrib/runners/{runner_name}_runner")

kwargs["provides"] = python_artifact( # noqa: F821
name=f"stackstorm-runner-{runner_name.replace('_', '-')}",
description=description,
version_file=f"{runner_name}_runner/__init__.py", # custom for our release plugin
# test_suite="tests",
zip_safe=kwargs.pop(
"zip_safe", True
), # most runners are safe to run from a zipapp
)

dependencies = kwargs.pop("dependencies", [])
for dep in [f"./{runner_name}_runner", ":license"]:
if dep not in dependencies:
dependencies.append(dep)

kwargs["dependencies"] = dependencies
kwargs["repositories"] = st2_publish_repos()

python_distribution(**kwargs) # noqa: F821


def st2_component_python_distribution(**kwargs):
"""Create a python_distribution (wheel/sdist) for a core StackStorm component."""
st2_component = kwargs.pop("component_name")
description = (
f"{st2_component} StackStorm event-driven automation platform component"
)
scripts = kwargs.pop("scripts", [])

st2_license(dest=st2_component)

kwargs["provides"] = python_artifact( # noqa: F821
name=st2_component,
description=description,
scripts=[
script[:-6] if script.endswith(":shell") else script for script in scripts
],
version_file=f"{st2_component}/__init__.py", # custom for our release plugin
# test_suite=st2_component,
zip_safe=False, # We rely on __file__ to load many things, so st2 should not run from a zipapp
)

dependencies = kwargs.pop("dependencies", [])
for dep in [st2_component, ":license"] + scripts:
dep = f"./{dep}" if dep[0] != ":" else dep
if dep not in dependencies:
dependencies.append(dep)

# see st2_shell_sources_and_resources below
if dep.endswith(":shell"):
dep_res = f"{dep}_resources"
if dep_res not in dependencies:
dependencies.append(dep_res)

kwargs["dependencies"] = dependencies
kwargs["repositories"] = st2_publish_repos()

python_distribution(**kwargs) # noqa: F821


def st2_shell_sources_and_resources(**kwargs):
"""This creates a shell_sources and a resources target.

Expand Down