From 82905736b77959610149e93b503168e1900cab88 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Mon, 30 Dec 2024 15:05:27 -0600 Subject: [PATCH 1/5] Pants: enable nFPM backend --- pants.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pants.toml b/pants.toml index ade479e33f..1a6ff6b16d 100644 --- a/pants.toml +++ b/pants.toml @@ -31,6 +31,9 @@ backend_packages = [ # packaging "pants.backend.experimental.makeself", + # packaging + "pants.backend.experimental.nfpm", + # internal plugins in pants-plugins/ "pants.backend.plugin_development", "api_spec", From 3e20568df0b5f217c79eb6255926332eb1dddb98 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Thu, 9 Jan 2025 21:14:39 -0600 Subject: [PATCH 2/5] pants-plugins/release: separate version extraction rule --- pants-plugins/release/rules.py | 55 ++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/pants-plugins/release/rules.py b/pants-plugins/release/rules.py index 86df6c0461..2bdc6931eb 100644 --- a/pants-plugins/release/rules.py +++ b/pants-plugins/release/rules.py @@ -21,6 +21,7 @@ from __future__ import annotations import re +from dataclasses import dataclass from pants.backend.python.util_rules.package_dists import ( SetupKwargs, @@ -88,6 +89,40 @@ def is_applicable(cls, _: Target) -> bool: # return target.address.spec.startswith("st2") +@dataclass(frozen=True) +class StackStormVersionRequest: + version_file: str + description_of_origin: str + + +@dataclass(frozen=True) +class StackStormVersion: + value: str + + +@rule +async def extract_version(request: StackStormVersionRequest) -> StackStormVersion: + version_digest_contents = await Get( + DigestContents, + PathGlobs( + [request.version_file], + description_of_origin=request.description_of_origin, + glob_match_error_behavior=GlobMatchErrorBehavior.error, + ), + ) + + version_file_contents = version_digest_contents[0].content.decode() + version_match = re.search( + r"^__version__ = ['\"]([^'\"]*)['\"]", version_file_contents, re.M + ) + if not version_match: + raise ValueError( + f"Could not find the __version__ in {request.version_file}\n{version_file_contents}" + ) + + return StackStormVersion(version_match.group(1)) + + @rule async def setup_kwargs_plugin(request: StackStormSetupKwargsRequest) -> SetupKwargs: kwargs = request.explicit_kwargs.copy() @@ -100,13 +135,12 @@ async def setup_kwargs_plugin(request: StackStormSetupKwargsRequest) -> SetupKwa version_file = kwargs.pop("version_file") - version_digest_contents, readme_digest_contents = await MultiGet( + version, readme_digest_contents = await MultiGet( Get( - DigestContents, - PathGlobs( - [f"{request.target.address.spec_path}/{version_file}"], + StackStormVersion, + StackStormVersionRequest( + version_file=f"{request.target.address.spec_path}/{version_file}", description_of_origin=f"StackStorm version file: {version_file}", - glob_match_error_behavior=GlobMatchErrorBehavior.error, ), ), Get( @@ -118,19 +152,10 @@ async def setup_kwargs_plugin(request: StackStormSetupKwargsRequest) -> SetupKwa ), ) - version_file_contents = version_digest_contents[0].content.decode() - version_match = re.search( - r"^__version__ = ['\"]([^'\"]*)['\"]", version_file_contents, re.M - ) - if not version_match: - raise ValueError( - f"Could not find the __version__ in {request.target.address.spec_path}/{version_file}\n{version_file_contents}" - ) - # Hardcode certain kwargs and validate that they weren't already set. hardcoded_kwargs = PROJECT_METADATA.copy() hardcoded_kwargs["project_urls"] = FrozenDict(PROJECT_URLS) - hardcoded_kwargs["version"] = version_match.group(1) + hardcoded_kwargs["version"] = version.value long_description = ( readme_digest_contents[0].content.decode() if readme_digest_contents else "" From 6b508a2980b4d70f25cf18ab0a7930e78f39249b Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Thu, 9 Jan 2025 21:30:08 -0600 Subject: [PATCH 3/5] pants-plugins/release: Inject version for nfpm packages --- pants-plugins/release/rules.py | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/pants-plugins/release/rules.py b/pants-plugins/release/rules.py index 2bdc6931eb..8ee338b57a 100644 --- a/pants-plugins/release/rules.py +++ b/pants-plugins/release/rules.py @@ -23,11 +23,17 @@ import re from dataclasses import dataclass +from pants.backend.nfpm.fields.version import NfpmVersionField, NfpmVersionSchemaField +from pants.backend.nfpm.util_rules.inject_config import ( + InjectedNfpmPackageFields, + InjectNfpmPackageFieldsRequest, +) from pants.backend.python.util_rules.package_dists import ( SetupKwargs, SetupKwargsRequest, ) from pants.engine.fs import DigestContents, GlobMatchErrorBehavior, PathGlobs +from pants.engine.internals.native_engine import Field from pants.engine.target import Target from pants.engine.rules import collect_rules, Get, MultiGet, rule, UnionRule from pants.util.frozendict import FrozenDict @@ -187,8 +193,43 @@ async def setup_kwargs_plugin(request: StackStormSetupKwargsRequest) -> SetupKwa return SetupKwargs(kwargs, address=request.target.address) +class StackStormNfpmPackageFieldsRequest(InjectNfpmPackageFieldsRequest): + @classmethod + def is_applicable(cls, _: Target) -> bool: + return True + + +@rule +async def inject_package_fields( + request: StackStormNfpmPackageFieldsRequest, +) -> InjectedNfpmPackageFields: + address = request.target.address + + version_file = "st2common/st2common/__init__.py" + extracted_version = await Get( + StackStormVersion, + StackStormVersionRequest( + version_file=version_file, + description_of_origin=f"StackStorm version file: {version_file}", + ), + ) + + version: str = extracted_version.value + if version.endswith("dev") and version[-4] != "-": + # nfpm parses this into version[-version_prerelease][+version_metadata] + # that dash is required to be a valid semver version. + version = version.replace("dev", "-dev") + + fields: list[Field] = [ + NfpmVersionSchemaField("semver", address=address), + NfpmVersionField(version, address=address), + ] + return InjectedNfpmPackageFields(fields, address=address) + + def rules(): return [ *collect_rules(), UnionRule(SetupKwargsRequest, StackStormSetupKwargsRequest), + UnionRule(InjectNfpmPackageFieldsRequest, StackStormNfpmPackageFieldsRequest), ] From 5cbff1f7169eedc272f3b543985fd91db8eb83ef Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Wed, 19 Mar 2025 18:29:56 -0500 Subject: [PATCH 4/5] add merge conflict magnet --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 49ecc1744c..0f079026e1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -79,7 +79,7 @@ Added to pants' use of PEX lockfiles. This is not a user-facing addition. #6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237 #6229 #6240 #6241 #6244 #6251 #6253 #6254 #6258 #6259 #6260 #6269 #6275 #6279 #6278 #6282 #6283 #6273 #6287 #6306 #6307 - #6311 #6314 #6315 #6317 #6319 #6312 + #6311 #6314 #6315 #6317 #6319 #6312 #6321 Contributed by @cognifloyd * Build of ST2 EL9 packages #6153 Contributed by @amanda11 From 1370f9743d1d2be823901a876f700f1f49d98100 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Mon, 24 Mar 2025 10:35:30 -0500 Subject: [PATCH 5/5] fix CircleCI build by constraining setuptools version --- contrib/runners/orquesta_runner/in-requirements.txt | 1 + contrib/runners/orquesta_runner/requirements.txt | 1 + fixed-requirements.txt | 3 +++ requirements.txt | 1 + st2actions/in-requirements.txt | 3 +++ st2actions/requirements.txt | 1 + 6 files changed, 10 insertions(+) diff --git a/contrib/runners/orquesta_runner/in-requirements.txt b/contrib/runners/orquesta_runner/in-requirements.txt index 3197648c25..637e8a8ba6 100644 --- a/contrib/runners/orquesta_runner/in-requirements.txt +++ b/contrib/runners/orquesta_runner/in-requirements.txt @@ -1 +1,2 @@ orquesta@ git+https://github.com/StackStorm/orquesta.git@5ba1467614b2ef8b4709b2ca89e68baa671e8975 +setuptools diff --git a/contrib/runners/orquesta_runner/requirements.txt b/contrib/runners/orquesta_runner/requirements.txt index bc32b16e29..a93eba892d 100644 --- a/contrib/runners/orquesta_runner/requirements.txt +++ b/contrib/runners/orquesta_runner/requirements.txt @@ -6,3 +6,4 @@ # in-requirements.txt for that component and then run 'make requirements' to # update the component requirements.txt orquesta@ git+https://github.com/StackStorm/orquesta.git@5ba1467614b2ef8b4709b2ca89e68baa671e8975 +setuptools<78 diff --git a/fixed-requirements.txt b/fixed-requirements.txt index 185b0d3fcb..2c601455b1 100644 --- a/fixed-requirements.txt +++ b/fixed-requirements.txt @@ -72,6 +72,9 @@ tooz==6.3.0 # virtualenv==20.29.2 (<21) has pip==25.0.1 wheel==0.45.1 setuptools==75.3.0 # lockfiles/st2.lock has pip==25.0.1 wheel==0.45.1 setuptools==75.3.0 virtualenv==20.29.2 +# This setuptools version number is in the Makefile, but CircleCI builds are pulling a version +# that is incompatible with our logshipper fork. +setuptools<78 webob==1.8.9 webtest==3.0.1 zake==0.2.2 diff --git a/requirements.txt b/requirements.txt index 976c39a2ea..425dd728d5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -62,6 +62,7 @@ requests==2.32.3 retrying==1.3.4 routes==2.5.1 semver==3.0.4 +setuptools<78 simplejson six==1.17.0 sseclient-py==1.8.0 diff --git a/st2actions/in-requirements.txt b/st2actions/in-requirements.txt index 601589e424..0d5630871e 100644 --- a/st2actions/in-requirements.txt +++ b/st2actions/in-requirements.txt @@ -19,6 +19,9 @@ lockfile # needed by core "linux" pack - TODO: create virtualenv for linux pack on postinst pyinotify logshipper@ git+https://github.com/StackStorm/logshipper.git@stackstorm_patched ; platform_system=="Linux" +# logshipper has metadata in setup.cfg that is not supported by setuptools 78, so we need +# an explicit dep (from fixed-requirements.txt) to prevent CircleCI from pulling that in. +setuptools # required by pack_mgmt/setup_virtualenv.py#L135 virtualenv # needed by requests diff --git a/st2actions/requirements.txt b/st2actions/requirements.txt index d19d898601..556124bcfc 100644 --- a/st2actions/requirements.txt +++ b/st2actions/requirements.txt @@ -22,5 +22,6 @@ python-dateutil==2.9.0.post0 python-json-logger pyyaml==6.0.2 requests==2.32.3 +setuptools<78 six==1.17.0 urllib3==2.2.3