From 0dc1b79b2425027ca5d8949968a6ad909561016f Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Mon, 28 Oct 2024 16:15:05 -0700 Subject: [PATCH 1/2] feat: add features.version value This adds a `features.version` value that is populated by git when `git archive` is run. This means it will be expanded when our release action runs to the tag name. Otherwise, it isn't expanded. When it isn't expanded, the value is set to the empty string. --- .gitattributes | 1 + CHANGELOG.md | 1 + python/features.bzl | 3 +++ 3 files changed, 5 insertions(+) diff --git a/.gitattributes b/.gitattributes index e4e5d4bc3e..eae260e931 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ +python/features.bzl export-subst tools/publish/*.txt linguist-generated=true diff --git a/CHANGELOG.md b/CHANGELOG.md index a1a2edc134..e85cfb46f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ A brief description of the categories of changes: `requirements_linux.txt`, `requirements_windows.txt` for each respective OS and one extra file `requirements_universal.txt` if you prefer a single file. The `requirements.txt` file may be removed in the future. +* The rules_python version is now reported in `//python/features.bzl#features.version` {#v0-0-0-removed} ### Removed diff --git a/python/features.bzl b/python/features.bzl index 3a10532c6e..6b15594000 100644 --- a/python/features.bzl +++ b/python/features.bzl @@ -13,6 +13,9 @@ # limitations under the License. """Allows detecting of rules_python features that aren't easily detected.""" +_VERSION_PRIVATE = "$Format:%(describe:tags=true)$" + features = struct( + version = _VERSION_PRIVATE if '$Format' not in _VERSION_PRIVATE else '' precompile = True, ) From 1140a063bf19bbe26fb13586c2ec2f43833d7c2e Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Mon, 28 Oct 2024 23:18:12 -0700 Subject: [PATCH 2/2] address review comments --- python/features.bzl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/features.bzl b/python/features.bzl index 6b15594000..90a1121909 100644 --- a/python/features.bzl +++ b/python/features.bzl @@ -13,9 +13,11 @@ # limitations under the License. """Allows detecting of rules_python features that aren't easily detected.""" +# This is a magic string expanded by `git archive`, as set by `.gitattributes` +# See https://git-scm.com/docs/git-archive/2.29.0#Documentation/git-archive.txt-export-subst _VERSION_PRIVATE = "$Format:%(describe:tags=true)$" features = struct( - version = _VERSION_PRIVATE if '$Format' not in _VERSION_PRIVATE else '' + version = _VERSION_PRIVATE if "$Format" not in _VERSION_PRIVATE else "", precompile = True, )