diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index b391d2c563b..cf5c56f31a7 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -2866,7 +2866,7 @@ def _validate_version(self): v.ref_version except vn.VersionLookupError: before = self.cformat("{name}{@version}{/hash:7}") - v._ref_version = vn.StandardVersion.from_string("develop") + v.std_version = vn.StandardVersion.from_string("develop") tty.debug( f"the git sha of {before} could not be resolved to spack version; " f"it has been replaced by {self.cformat('{name}{@version}{/hash:7}')}." @@ -4428,7 +4428,7 @@ def attach_git_version_lookup(self): if not self.name: return for v in self.versions: - if isinstance(v, vn.GitVersion) and v._ref_version is None: + if isinstance(v, vn.GitVersion) and v.std_version is None: v.attach_lookup(spack.version.git_ref_lookup.GitRefLookup(self.fullname)) diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py index 775985ccc03..863cb1c5249 100644 --- a/lib/spack/spack/test/conftest.py +++ b/lib/spack/spack/test/conftest.py @@ -154,7 +154,7 @@ def mock_git_version_info(git, tmpdir, override_git_repos_cache_path): o second commit (v1.0) o first commit - The repo consists of a single file, in which the GitVersion._ref_version representation + The repo consists of a single file, in which the GitVersion.std_version representation of each commit is expressed as a string. Important attributes of the repo for test coverage are: multiple branches, diff --git a/lib/spack/spack/test/versions.py b/lib/spack/spack/test/versions.py index de8377b9328..f78d61632fd 100644 --- a/lib/spack/spack/test/versions.py +++ b/lib/spack/spack/test/versions.py @@ -832,13 +832,13 @@ def test_git_versions_store_ref_requests(pre_equal, post_equal): v = Version(vstring) assert isinstance(v, GitVersion) - assert v.requested_ref == pre_equal + assert v.ref == pre_equal if post_equal: assert v.std_version == Version(post_equal) if v.is_commit: - assert v.requested_ref == v.commit_sha + assert v.ref == v.commit_sha @pytest.mark.parametrize( "vstring, eq_vstring, is_commit", diff --git a/lib/spack/spack/version/version_types.py b/lib/spack/spack/version/version_types.py index 53f10b722f5..e2a7f26b35f 100644 --- a/lib/spack/spack/version/version_types.py +++ b/lib/spack/spack/version/version_types.py @@ -548,20 +548,20 @@ class GitVersion(ConcreteVersion): sufficient. """ - __slots__ = ["ref", "has_git_prefix", "is_commit", "_ref_lookup", "_ref_version"] + __slots__ = ["has_git_prefix", "commit_sha", "ref", "std_version", "_ref_lookup"] def __init__(self, string: str): - # WIP refactor - self.requested_ref: Optional[String] = None + + # TODO will be required for concrete specs when commit lookup added self.commit_sha: Optional[String] = None self.std_version: Optional[StandardVersion] = None + # optional user supplied git ref + self.ref: Optional[String] = None + # An object that can lookup git refs to compare them to versions self._ref_lookup: Optional[AbstractRefLookup] = None - # This is the effective version. - self._ref_version: Optional[StandardVersion] - self.has_git_prefix = string.startswith("git.") # Drop `git.` prefix @@ -570,28 +570,27 @@ def __init__(self, string: str): if "=" in normalized_string: # Store the git reference, and parse the user provided version. self.ref, spack_version = normalized_string.split("=") - self._ref_version = StandardVersion( + self.std_version = StandardVersion( spack_version, *parse_string_components(spack_version) ) else: # The ref_version is lazily attached after parsing, since we don't know what # package it applies to here. - self._ref_version = None + self.std_version = None self.ref = normalized_string # Used by fetcher self.is_commit: bool = len(self.ref) == 40 and bool(COMMIT_VERSION.match(self.ref)) - self.requested_ref = self.ref - self.std_version = self._ref_version + # translations if self.is_commit: self.commit_sha = self.ref @property def ref_version(self) -> StandardVersion: # Return cached version if we have it - if self._ref_version is not None: - return self._ref_version + if self.std_version is not None: + return self.std_version if self.ref_lookup is None: raise VersionLookupError( @@ -604,10 +603,10 @@ def ref_version(self) -> StandardVersion: # Add a -git. suffix when we're not exactly on a tag if distance > 0: version_string += f"-git.{distance}" - self._ref_version = StandardVersion( + self.std_version = StandardVersion( version_string, *parse_string_components(version_string) ) - return self._ref_version + return self.std_version def intersects(self, other: VersionType) -> bool: # For concrete things intersects = satisfies = equality