From 532a37e7baa69e1eb9f5e655295a3a46ff9744dc Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Thu, 10 Aug 2023 08:56:39 +0200 Subject: [PATCH] Revert "Spec versions: allow `git.` references for branches with `/` (#38239)" (#39354) This reverts commit 3453259c98c7d39655b8495ca2e3677c51284b43. --- lib/spack/spack/parser.py | 11 +++-------- lib/spack/spack/test/spec_syntax.py | 8 -------- lib/spack/spack/test/versions.py | 20 -------------------- 3 files changed, 3 insertions(+), 36 deletions(-) diff --git a/lib/spack/spack/parser.py b/lib/spack/spack/parser.py index 29d10a66720..3416f2540bc 100644 --- a/lib/spack/spack/parser.py +++ b/lib/spack/spack/parser.py @@ -76,9 +76,7 @@ IDENTIFIER = r"([a-zA-Z_0-9][a-zA-Z_0-9\-]*)" DOTTED_IDENTIFIER = rf"({IDENTIFIER}(\.{IDENTIFIER})+)" GIT_HASH = r"([A-Fa-f0-9]{40})" -#: Git refs include branch names, and can contain "." and "/" -GIT_REF = r"([a-zA-Z_0-9][a-zA-Z_0-9./\-]*)" -GIT_VERSION = rf"((git\.({GIT_REF}))|({GIT_HASH}))" +GIT_VERSION = rf"((git\.({DOTTED_IDENTIFIER}|{IDENTIFIER}))|({GIT_HASH}))" NAME = r"[a-zA-Z_0-9][a-zA-Z_0-9\-.]*" @@ -130,7 +128,6 @@ class TokenType(TokenBase): DEPENDENCY = r"(\^)" # Version VERSION_HASH_PAIR = rf"(@({GIT_VERSION})=({VERSION}))" - GIT_VERSION = rf"@({GIT_VERSION})" VERSION = rf"(@\s*({VERSION_LIST}))" # Variants PROPAGATED_BOOL_VARIANT = rf"((\+\+|~~|--)\s*{NAME})" @@ -367,10 +364,8 @@ def parse(self, initial_spec: Optional[spack.spec.Spec] = None) -> Optional[spac compiler_name.strip(), compiler_version ) self.has_compiler = True - elif ( - self.ctx.accept(TokenType.VERSION_HASH_PAIR) - or self.ctx.accept(TokenType.GIT_VERSION) - or self.ctx.accept(TokenType.VERSION) + elif self.ctx.accept(TokenType.VERSION) or self.ctx.accept( + TokenType.VERSION_HASH_PAIR ): self.hash_not_parsed_or_raise(initial_spec, self.ctx.current_token.value) if self.has_version: diff --git a/lib/spack/spack/test/spec_syntax.py b/lib/spack/spack/test/spec_syntax.py index 773acd7ce7a..4a55752fddc 100644 --- a/lib/spack/spack/test/spec_syntax.py +++ b/lib/spack/spack/test/spec_syntax.py @@ -517,14 +517,6 @@ def _specfile_for(spec_str, filename): [Token(TokenType.VERSION, value="@:0.4"), Token(TokenType.COMPILER, value="% nvhpc")], "@:0.4%nvhpc", ), - ( - "zlib@git.foo/bar", - [ - Token(TokenType.UNQUALIFIED_PACKAGE_NAME, "zlib"), - Token(TokenType.GIT_VERSION, "@git.foo/bar"), - ], - "zlib@git.foo/bar", - ), ], ) def test_parse_single_spec(spec_str, tokens, expected_roundtrip): diff --git a/lib/spack/spack/test/versions.py b/lib/spack/spack/test/versions.py index e2c5a910978..7d329336aee 100644 --- a/lib/spack/spack/test/versions.py +++ b/lib/spack/spack/test/versions.py @@ -676,26 +676,6 @@ def test_git_ref_comparisons(mock_git_version_info, install_mockery, mock_packag assert str(spec_branch.version) == "git.1.x=1.2" -@pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)") -def test_git_branch_with_slash(): - class MockLookup(object): - def get(self, ref): - assert ref == "feature/bar" - return "1.2", 0 - - v = spack.version.from_string("git.feature/bar") - assert isinstance(v, GitVersion) - v.attach_lookup(MockLookup()) - - # Create a version range - test_number_version = spack.version.from_string("1.2") - v.satisfies(test_number_version) - - serialized = VersionList([v]).to_dict() - v_deserialized = VersionList.from_dict(serialized) - assert v_deserialized[0].ref == "feature/bar" - - @pytest.mark.parametrize( "string,git", [