|
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | 15 |
|
| 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 | + |
16 | 115 | def st2_shell_sources_and_resources(**kwargs): |
17 | 116 | """This creates a shell_sources and a resources target. |
18 | 117 |
|
|
0 commit comments