From 18fc6320e4ece05f4edf7ca7bde093163a6a8f52 Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Fri, 24 Feb 2023 14:54:50 +0100 Subject: [PATCH] Synchronize sat_semver.py (#4) --- README.md | 10 ++-- diff.py | 57 +++++++++++++++++-- .../WORKSPACE | 2 +- .../resolved.bzl | 4 +- .../WORKSPACE | 2 +- .../resolved.bzl | 4 +- sat_semver.py | 45 ++++++++++++--- test.sh | 2 +- 8 files changed, 102 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 63f7f76..c87b821 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "bazel_upgradable", - strip_prefix = "bazel_upgradable-0.2.1", - url = "https://github.com/fenollp/bazel_upgradable/archive/0.2.1.zip", + strip_prefix = "bazel_upgradable-0.3.0", + url = "https://github.com/fenollp/bazel_upgradable/archive/0.3.0.zip", ) load("@bazel_upgradable//:rule.bzl", "upgradable_repository") @@ -37,7 +37,7 @@ load("@bazel_upgradable//:rule.bzl", "upgradable_repository") ```python upgradable_repository( name = "bazel_skylib", - remote = "git://github.com/bazelbuild/bazel-skylib.git", + remote = "https://github.com/bazelbuild/bazel-skylib.git", ) ``` @@ -46,7 +46,7 @@ upgradable_repository( # Locking on major of a GitHub tag upgradable_repository( name = "bazel_skylib", - remote = "git://github.com/bazelbuild/bazel-skylib.git", + remote = "https://github.com/bazelbuild/bazel-skylib.git", tag = "~1", ) @@ -66,7 +66,7 @@ upgradable_repository( build_file = "@//third_party:glfw3_osx.BUILD", # {tag} and {tag_digits} are expanded during dependency resolution release = "glfw-{tag_digits}.bin.MACOS.zip", - remote = "git://github.com/glfw/glfw.git", + remote = "https://github.com/glfw/glfw.git", tag = "~3", ) ``` diff --git a/diff.py b/diff.py index 5e25f5d..1cd31ad 100644 --- a/diff.py +++ b/diff.py @@ -8,6 +8,7 @@ import after IGNORED = [ + "android_gmaven_r8", "android_tools", "local_config_cc", "local_config_cc_toolchains", @@ -15,6 +16,7 @@ "local_config_xcode", "local_jdk", "remote_coverage_tools", + "remote_java_tools", "remote_java_tools_darwin", "remote_java_tools_linux", "remote_java_tools_windows", @@ -24,24 +26,70 @@ "remotejdk10_win", "remotejdk11_linux", "remotejdk11_linux_aarch64", + "remotejdk11_linux_aarch64_toolchain_config_repo", "remotejdk11_linux_ppc64le", + "remotejdk11_linux_ppc64le_toolchain_config_repo", "remotejdk11_linux_s390x", + "remotejdk11_linux_s390x_toolchain_config_repo", + "remotejdk11_linux_toolchain_config_repo", "remotejdk11_macos", "remotejdk11_macos_aarch64", + "remotejdk11_macos_aarch64_toolchain_config_repo", + "remotejdk11_macos_toolchain_config_repo", "remotejdk11_win", + "remotejdk11_win_arm64", + "remotejdk11_win_arm64_toolchain_config_repo", + "remotejdk11_win_toolchain_config_repo", "remotejdk14_linux", "remotejdk14_macos", "remotejdk14_win", "remotejdk15_linux", + "remotejdk15_linux_toolchain_config_repo", "remotejdk15_macos", "remotejdk15_macos_aarch64", + "remotejdk15_macos_aarch64_toolchain_config_repo", + "remotejdk15_macos_toolchain_config_repo", "remotejdk15_win", + "remotejdk15_win_toolchain_config_repo", + "remotejdk16_linux", + "remotejdk16_linux_toolchain_config_repo", + "remotejdk16_macos", + "remotejdk16_macos_aarch64", + "remotejdk16_macos_aarch64_toolchain_config_repo", + "remotejdk16_macos_toolchain_config_repo", + "remotejdk16_win", + "remotejdk16_win_toolchain_config_repo", + "remotejdk17_linux", + "remotejdk17_linux_aarch64", + "remotejdk17_linux_aarch64_toolchain_config_repo", + "remotejdk17_linux_toolchain_config_repo", + "remotejdk17_macos", + "remotejdk17_macos_aarch64", + "remotejdk17_macos_aarch64_toolchain_config_repo", + "remotejdk17_macos_toolchain_config_repo", + "remotejdk17_win", + "remotejdk17_win_arm64", + "remotejdk17_win_arm64_toolchain_config_repo", + "remotejdk17_win_toolchain_config_repo", + "remotejdk18_linux", + "remotejdk18_linux_aarch64", + "remotejdk18_linux_aarch64_toolchain_config_repo", + "remotejdk18_linux_toolchain_config_repo", + "remotejdk18_macos", + "remotejdk18_macos_aarch64", + "remotejdk18_macos_aarch64_toolchain_config_repo", + "remotejdk18_macos_toolchain_config_repo", + "remotejdk18_win", + "remotejdk18_win_arm64", + "remotejdk18_win_arm64_toolchain_config_repo", + "remotejdk18_win_toolchain_config_repo", "remotejdk_linux", "remotejdk_linux_aarch64", "remotejdk_macos", "remotejdk_win", "rules_cc", "rules_java", + "rules_license", "rules_proto", ] @@ -76,11 +124,12 @@ xa = a[name] d = {k: xa[k] for k in set(xa) - set(xb)} if d: + dump = lambda x: print(json.dumps(x, indent=4, sort_keys=True)) print(name) print("Before:") - print(json.dumps(xb, indent=4, sort_keys=True)) + dump(xb) print("Before:") - print(json.dumps(xa, indent=4, sort_keys=True)) + dump(xa) print("Difference:") - print(json.dumps(d, indent=4, sort_keys=True)) - exit(len(2)) + dump(d) + exit(2) diff --git a/example_upgradable_github_archive_HEAD/WORKSPACE b/example_upgradable_github_archive_HEAD/WORKSPACE index 1699961..71c6420 100644 --- a/example_upgradable_github_archive_HEAD/WORKSPACE +++ b/example_upgradable_github_archive_HEAD/WORKSPACE @@ -10,7 +10,7 @@ load("@bazel_upgradable//:rule.bzl", "upgradable_repository") upgradable_repository( name = "bazel_skylib", branch = "main", - remote = "git://github.com/bazelbuild/bazel-skylib.git", + remote = "https://github.com/bazelbuild/bazel-skylib.git", ) load("@bazel_skylib//lib:versions.bzl", "versions") diff --git a/example_upgradable_github_archive_HEAD/resolved.bzl b/example_upgradable_github_archive_HEAD/resolved.bzl index ed2eb12..2e8ea2c 100644 --- a/example_upgradable_github_archive_HEAD/resolved.bzl +++ b/example_upgradable_github_archive_HEAD/resolved.bzl @@ -100,7 +100,7 @@ resolved = [ "original_attributes": { "name": "bazel_skylib", "branch": "master", - "remote": "git://github.com/bazelbuild/bazel-skylib.git" + "remote": "https://github.com/bazelbuild/bazel-skylib.git" }, "repositories": [ { @@ -120,7 +120,7 @@ resolved = [ "workspace_file_content": "", "branch": "master", "release": "", - "remote": "git://github.com/bazelbuild/bazel-skylib.git", + "remote": "https://github.com/bazelbuild/bazel-skylib.git", "sha256": "a89898b28fb596ba8df76fe361597d08659dd58b7f54cb5ece5251f522de0691", "strip_prefix": "bazel-skylib-feb52960ebd8797421b599194ad6ac7da3fc7600", "tag": "", diff --git a/example_upgradable_github_archive_constrained/WORKSPACE b/example_upgradable_github_archive_constrained/WORKSPACE index c2e048b..6347085 100644 --- a/example_upgradable_github_archive_constrained/WORKSPACE +++ b/example_upgradable_github_archive_constrained/WORKSPACE @@ -9,7 +9,7 @@ load("@bazel_upgradable//:rule.bzl", "upgradable_repository") upgradable_repository( name = "bazel_skylib", - remote = "git://github.com/bazelbuild/bazel-skylib.git", + remote = "https://github.com/bazelbuild/bazel-skylib.git", tag = "~1", ) diff --git a/example_upgradable_github_archive_constrained/resolved.bzl b/example_upgradable_github_archive_constrained/resolved.bzl index 12ec022..f70a358 100644 --- a/example_upgradable_github_archive_constrained/resolved.bzl +++ b/example_upgradable_github_archive_constrained/resolved.bzl @@ -99,7 +99,7 @@ resolved = [ "original_rule_class": "@bazel_upgradable//:rule.bzl%upgradable_repository", "original_attributes": { "name": "bazel_skylib", - "remote": "git://github.com/bazelbuild/bazel-skylib.git", + "remote": "https://github.com/bazelbuild/bazel-skylib.git", "tag": "~1" }, "repositories": [ @@ -120,7 +120,7 @@ resolved = [ "workspace_file_content": "", "branch": "", "release": "", - "remote": "git://github.com/bazelbuild/bazel-skylib.git", + "remote": "https://github.com/bazelbuild/bazel-skylib.git", "sha256": "839ee2a0ee5b728b7af73eac87b5e207ed2c8651b7bcf7c6142cdf4dd1ea738b", "strip_prefix": "bazel-skylib-e59b620b392a8ebbcf25879fc3fde52b4dc77535", "tag": "~1", diff --git a/sat_semver.py b/sat_semver.py index 6308025..d0114a9 100644 --- a/sat_semver.py +++ b/sat_semver.py @@ -122,6 +122,12 @@ def __init__( self.partial = partial + # Cached precedence keys + # _cmp_precedence_key is used for semver-precedence comparison + self._cmp_precedence_key = self._build_precedence_key(with_build=False) + # _sort_precedence_key is used for self.precedence_key, esp. for sorted(...) + self._sort_precedence_key = self._build_precedence_key(with_build=True) + @classmethod def _coerce(cls, value, allow_none=False): if value is None and allow_none: @@ -294,7 +300,8 @@ def coerce(cls, version_string, partial=False): @classmethod def parse(cls, version_string, partial=False, coerce=False): - """Parse a version string into a Version() object. + """Parse a version string into a tuple of components: + (major, minor, patch, prerelease, build). Args: version_string (str), the version string to parse @@ -411,11 +418,15 @@ def __hash__(self): # at least a field being `None`. return hash((self.major, self.minor, self.patch, self.prerelease, self.build)) - @property - def precedence_key(self): + def _build_precedence_key(self, with_build=False): + """Build a precedence key. + + The "build" component should only be used when sorting an iterable + of versions. + """ if self.prerelease: prerelease_key = tuple( - NumericIdentifier(part) if re.match(r'^[0-9]+$', part) else AlphaIdentifier(part) + NumericIdentifier(part) if part.isdigit() else AlphaIdentifier(part) for part in self.prerelease ) else: @@ -423,13 +434,31 @@ def precedence_key(self): MaxIdentifier(), ) + if not with_build: + return ( + self.major, + self.minor, + self.patch, + prerelease_key, + ) + + build_key = tuple( + NumericIdentifier(part) if part.isdigit() else AlphaIdentifier(part) + for part in self.build or () + ) + return ( self.major, self.minor, self.patch, prerelease_key, + build_key, ) + @property + def precedence_key(self): + return self._sort_precedence_key + def __cmp__(self, other): if not isinstance(other, self.__class__): return NotImplemented @@ -461,22 +490,22 @@ def __ne__(self, other): def __lt__(self, other): if not isinstance(other, self.__class__): return NotImplemented - return self.precedence_key < other.precedence_key + return self._cmp_precedence_key < other._cmp_precedence_key def __le__(self, other): if not isinstance(other, self.__class__): return NotImplemented - return self.precedence_key <= other.precedence_key + return self._cmp_precedence_key <= other._cmp_precedence_key def __gt__(self, other): if not isinstance(other, self.__class__): return NotImplemented - return self.precedence_key > other.precedence_key + return self._cmp_precedence_key > other._cmp_precedence_key def __ge__(self, other): if not isinstance(other, self.__class__): return NotImplemented - return self.precedence_key >= other.precedence_key + return self._cmp_precedence_key >= other._cmp_precedence_key class SpecItem(object): diff --git a/test.sh b/test.sh index e1bf922..e32c058 100755 --- a/test.sh +++ b/test.sh @@ -58,7 +58,7 @@ for workspace in example_*; do cp $L after.py set +e - python ../diff.py "$PWD" + python3 ../diff.py "$PWD" diffed=$? set -e rm before.py after.py