Skip to content

Commit

Permalink
Add version/local scheme fields to vcs_version (pantsbuild#20446)
Browse files Browse the repository at this point in the history
This change adds the `version_scheme` and `local_scheme` fields to
`vcs_verison` target to be passed through to the config.
  • Loading branch information
thejcannon authored Jan 22, 2024
1 parent ea7e37d commit d7dff7a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/python/pants/backend/python/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions src/python/pants/backend/python/util_rules/vcs_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d7dff7a

Please sign in to comment.