Spec versions: allow git. references for branches with / (#38239)

This commit is contained in:
Peter Scheibel 2023-08-09 00:07:04 -07:00 committed by GitHub
parent ee243b84eb
commit 3453259c98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 3 deletions

View File

@ -76,7 +76,9 @@
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_VERSION = rf"((git\.({DOTTED_IDENTIFIER}|{IDENTIFIER}))|({GIT_HASH}))"
#: 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}))"
NAME = r"[a-zA-Z_0-9][a-zA-Z_0-9\-.]*"
@ -128,6 +130,7 @@ 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})"
@ -364,8 +367,10 @@ 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) or self.ctx.accept(
TokenType.VERSION_HASH_PAIR
elif (
self.ctx.accept(TokenType.VERSION_HASH_PAIR)
or self.ctx.accept(TokenType.GIT_VERSION)
or self.ctx.accept(TokenType.VERSION)
):
self.hash_not_parsed_or_raise(initial_spec, self.ctx.current_token.value)
if self.has_version:

View File

@ -517,6 +517,14 @@ 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):

View File

@ -676,6 +676,26 @@ 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",
[