diff --git a/BUILD b/BUILD index 5328f1b40e..0112a2cba2 100644 --- a/BUILD +++ b/BUILD @@ -52,3 +52,8 @@ python_test_utils( name="test_utils", skip_pylint=True, ) + +file( + name="license", + source="LICENSE", +) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ea2f506aaa..46b7dc49b5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 diff --git a/pants-plugins/macros.py b/pants-plugins/macros.py index 454bbaa05f..f9a7c86397 100644 --- a/pants-plugins/macros.py +++ b/pants-plugins/macros.py @@ -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.