From d7dff7a6580259bf993140c7581c5abae823820d Mon Sep 17 00:00:00 2001 From: Josh Cannon Date: Mon, 22 Jan 2024 09:08:58 -0500 Subject: [PATCH] Add version/local scheme fields to `vcs_version` (#20446) This change adds the `version_scheme` and `local_scheme` fields to `vcs_verison` target to be passed through to the config. --- .../pants/backend/python/target_types.py | 22 +++++++++++++++++++ .../python/util_rules/vcs_versioning.py | 9 ++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/python/pants/backend/python/target_types.py b/src/python/pants/backend/python/target_types.py index d6c6ae36512..049b9729ae2 100644 --- a/src/python/pants/backend/python/target_types.py +++ b/src/python/pants/backend/python/target_types.py @@ -1674,11 +1674,33 @@ class VersionTemplateField(StringField): ) +class VersionVersionSchemeField(StringField): + alias = "version_scheme" + help = help_text( + """ + The version scheme to configure `setuptools_scm` to use. + See https://setuptools-scm.readthedocs.io/en/latest/extending/#available-implementations + """ + ) + + +class VersionLocalSchemeField(StringField): + alias = "local_scheme" + help = help_text( + """ + The local scheme to configure `setuptools_scm` to use. + See https://setuptools-scm.readthedocs.io/en/latest/extending/#available-implementations_1 + """ + ) + + class VCSVersion(Target): alias = "vcs_version" core_fields = ( *COMMON_TARGET_FIELDS, VersionTagRegexField, + VersionVersionSchemeField, + VersionLocalSchemeField, VCSVersionDummySourceField, VersionGenerateToField, VersionTemplateField, diff --git a/src/python/pants/backend/python/util_rules/vcs_versioning.py b/src/python/pants/backend/python/util_rules/vcs_versioning.py index 0a0ea5016f4..5279744ee06 100644 --- a/src/python/pants/backend/python/util_rules/vcs_versioning.py +++ b/src/python/pants/backend/python/util_rules/vcs_versioning.py @@ -23,8 +23,10 @@ VCSVersion, VCSVersionDummySourceField, VersionGenerateToField, + VersionLocalSchemeField, VersionTagRegexField, VersionTemplateField, + VersionVersionSchemeField, ) from pants.backend.python.util_rules.pex import PexRequest, VenvPex, VenvPexProcess from pants.core.util_rules.stripped_source_files import StrippedFileName, StrippedFileNameRequest @@ -78,9 +80,12 @@ async def generate_python_from_setuptools_scm( # directory" and "where should I write output to". config: dict[str, dict[str, dict[str, str]]] = {} tool_config = config.setdefault("tool", {}).setdefault("setuptools_scm", {}) - tag_regex = request.protocol_target[VersionTagRegexField].value - if tag_regex: + if tag_regex := request.protocol_target[VersionTagRegexField].value: tool_config["tag_regex"] = tag_regex + if version_scheme := request.protocol_target[VersionVersionSchemeField].value: + tool_config["version_scheme"] = version_scheme + if local_scheme := request.protocol_target[VersionLocalSchemeField].value: + tool_config["local_scheme"] = local_scheme config_path = "pyproject.synthetic.toml" input_digest_get = Get(