Skip to content

Commit 606f42f

Browse files
authored
Merge pull request #5901: Add st2_*_python_distribution() macros to pants-plugins/macros.py
2 parents 7b44357 + 908a45f commit 606f42f

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ python_test_utils(
5252
name="test_utils",
5353
skip_pylint=True,
5454
)
55+
56+
file(
57+
name="license",
58+
source="LICENSE",
59+
)

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Added
1616
to pants' use of PEX lockfiles. This is not a user-facing addition.
1717
#5778 #5789 #5817 #5795 #5830 #5833 #5834 #5841 #5840 #5838 #5842 #5837 #5849 #5850
1818
#5846 #5853 #5848 #5847 #5858 #5857 #5860 #5868 #5871 #5864 #5874 #5884 #5893 #5891
19-
#5890 #5898
19+
#5890 #5898 #5901
2020
Contributed by @cognifloyd
2121

2222
* Added a joint index to solve the problem of slow mongo queries for scheduled executions. #5805

pants-plugins/macros.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,105 @@
1313
# limitations under the License.
1414

1515

16+
def st2_publish_repos():
17+
"""Return the list of repos twine should publish to.
18+
19+
Twine will publish to ALL of these repos when running `./pants publish`.
20+
21+
We use ST2_PUBLISH_REPO, an env var, To facilitate switching between
22+
@testpypi and @pypi. That also means someone could publish to their own
23+
private repo by changing this var.
24+
25+
Credentials for pypi should be in ~/.pypirc or in TWINE_* env vars.
26+
"""
27+
# TODO: switch from hard-coded to env() once we upgrade to pants 2.16
28+
# return [env("ST2_PUBLISH_REPO", "@pypi")] # noqa: F821
29+
return ["@pypi"]
30+
31+
32+
def st2_license(**kwargs):
33+
"""Copy the LICENSE file into each wheel.
34+
35+
As long as the file is in the src root when building the sdist/wheel,
36+
setuptools automatically includes the LICENSE file in the dist-info.
37+
"""
38+
if "dest" not in kwargs:
39+
raise ValueError("'dest' path is required for st2_license macro")
40+
relocated_files( # noqa: F821
41+
name="license",
42+
files_targets=["//:license"],
43+
src="",
44+
**kwargs,
45+
)
46+
47+
48+
def st2_runner_python_distribution(**kwargs):
49+
"""Create a python_distribution (wheel/sdist) for a StackStorm runner."""
50+
runner_name = kwargs.pop("runner_name")
51+
description = kwargs.pop("description")
52+
53+
st2_license(dest=f"contrib/runners/{runner_name}_runner")
54+
55+
kwargs["provides"] = python_artifact( # noqa: F821
56+
name=f"stackstorm-runner-{runner_name.replace('_', '-')}",
57+
description=description,
58+
version_file=f"{runner_name}_runner/__init__.py", # custom for our release plugin
59+
# test_suite="tests",
60+
zip_safe=kwargs.pop(
61+
"zip_safe", True
62+
), # most runners are safe to run from a zipapp
63+
)
64+
65+
dependencies = kwargs.pop("dependencies", [])
66+
for dep in [f"./{runner_name}_runner", ":license"]:
67+
if dep not in dependencies:
68+
dependencies.append(dep)
69+
70+
kwargs["dependencies"] = dependencies
71+
kwargs["repositories"] = st2_publish_repos()
72+
73+
python_distribution(**kwargs) # noqa: F821
74+
75+
76+
def st2_component_python_distribution(**kwargs):
77+
"""Create a python_distribution (wheel/sdist) for a core StackStorm component."""
78+
st2_component = kwargs.pop("component_name")
79+
description = (
80+
f"{st2_component} StackStorm event-driven automation platform component"
81+
)
82+
scripts = kwargs.pop("scripts", [])
83+
84+
st2_license(dest=st2_component)
85+
86+
kwargs["provides"] = python_artifact( # noqa: F821
87+
name=st2_component,
88+
description=description,
89+
scripts=[
90+
script[:-6] if script.endswith(":shell") else script for script in scripts
91+
],
92+
version_file=f"{st2_component}/__init__.py", # custom for our release plugin
93+
# test_suite=st2_component,
94+
zip_safe=False, # We rely on __file__ to load many things, so st2 should not run from a zipapp
95+
)
96+
97+
dependencies = kwargs.pop("dependencies", [])
98+
for dep in [st2_component, ":license"] + scripts:
99+
dep = f"./{dep}" if dep[0] != ":" else dep
100+
if dep not in dependencies:
101+
dependencies.append(dep)
102+
103+
# see st2_shell_sources_and_resources below
104+
if dep.endswith(":shell"):
105+
dep_res = f"{dep}_resources"
106+
if dep_res not in dependencies:
107+
dependencies.append(dep_res)
108+
109+
kwargs["dependencies"] = dependencies
110+
kwargs["repositories"] = st2_publish_repos()
111+
112+
python_distribution(**kwargs) # noqa: F821
113+
114+
16115
def st2_shell_sources_and_resources(**kwargs):
17116
"""This creates a shell_sources and a resources target.
18117

0 commit comments

Comments
 (0)