make version(...) kwargs explicit (#36998)

- [x] Replace `version(ver, checksum=None, **kwargs)` signature with
      `version(ver, checksum=None, *, sha256=..., ...)` explicitly listing all arguments.
- [x] Fix various issues in packages:
  - `tags` instead of `tag`
  - `default` instead of `preferred`
  - `sha26` instead of `sha256`
  - etc

Also, use `sha256=...` consistently.

Note: setting `sha256` currently doesn't validate the checksum length, so you could do
`sha256="a"*32` and it would get checked as `md5`... but that's something for another PR.
This commit is contained in:
Harmen Stoppels
2023-04-19 23:17:47 +02:00
committed by GitHub
parent c7508dc216
commit d51af675ef
308 changed files with 661 additions and 580 deletions

View File

@@ -807,7 +807,7 @@ def get_versions(args, name):
# Default version with hash
hashed_versions = """\
# FIXME: Add proper versions and checksums here.
# version("1.2.3", "0123456789abcdef0123456789abcdef")"""
# version("1.2.3", md5="0123456789abcdef0123456789abcdef")"""
# Default version without hash
unhashed_versions = """\

View File

@@ -32,7 +32,7 @@ class OpenMpi(Package):
import functools
import os.path
import re
from typing import List, Set
from typing import List, Optional, Set
import llnl.util.lang
import llnl.util.tty.color
@@ -317,34 +317,100 @@ def remove_directives(arg):
@directive("versions")
def version(ver, checksum=None, **kwargs):
def version(
ver: str,
# this positional argument is deprecated, use sha256=... instead
checksum: Optional[str] = None,
*,
# generic version options
preferred: Optional[bool] = None,
deprecated: Optional[bool] = None,
no_cache: Optional[bool] = None,
# url fetch options
url: Optional[str] = None,
extension: Optional[str] = None,
expand: Optional[bool] = None,
fetch_options: Optional[dict] = None,
# url archive verification options
md5: Optional[str] = None,
sha1: Optional[str] = None,
sha224: Optional[str] = None,
sha256: Optional[str] = None,
sha384: Optional[str] = None,
sha512: Optional[str] = None,
# git fetch options
git: Optional[str] = None,
commit: Optional[str] = None,
tag: Optional[str] = None,
branch: Optional[str] = None,
get_full_repo: Optional[bool] = None,
submodules: Optional[bool] = None,
submodules_delete: Optional[bool] = None,
# other version control
svn: Optional[str] = None,
hg: Optional[str] = None,
cvs: Optional[str] = None,
revision: Optional[str] = None,
date: Optional[str] = None,
):
"""Adds a version and, if appropriate, metadata for fetching its code.
The ``version`` directives are aggregated into a ``versions`` dictionary
attribute with ``Version`` keys and metadata values, where the metadata
is stored as a dictionary of ``kwargs``.
The ``dict`` of arguments is turned into a valid fetch strategy for
The (keyword) arguments are turned into a valid fetch strategy for
code packages later. See ``spack.fetch_strategy.for_package_version()``.
Keyword Arguments:
deprecated (bool): whether or not this version is deprecated
"""
def _execute_version(pkg):
if checksum is not None:
if hasattr(pkg, "has_code") and not pkg.has_code:
raise VersionChecksumError(
"{0}: Checksums not allowed in no-code packages"
"(see '{1}' version).".format(pkg.name, ver)
)
if (
any((sha256, sha384, sha512, md5, sha1, sha224, checksum))
and hasattr(pkg, "has_code")
and not pkg.has_code
):
raise VersionChecksumError(
"{0}: Checksums not allowed in no-code packages "
"(see '{1}' version).".format(pkg.name, ver)
)
kwargs["checksum"] = checksum
kwargs = {
key: value
for key, value in (
("sha256", sha256),
("sha384", sha384),
("sha512", sha512),
("preferred", preferred),
("deprecated", deprecated),
("expand", expand),
("url", url),
("extension", extension),
("no_cache", no_cache),
("fetch_options", fetch_options),
("git", git),
("svn", svn),
("hg", hg),
("cvs", cvs),
("get_full_repo", get_full_repo),
("branch", branch),
("submodules", submodules),
("submodules_delete", submodules_delete),
("commit", commit),
("tag", tag),
("revision", revision),
("date", date),
("md5", md5),
("sha1", sha1),
("sha224", sha224),
("checksum", checksum),
)
if value is not None
}
# Store kwargs for the package to later with a fetch_strategy.
version = Version(ver)
if isinstance(version, GitVersion):
if not hasattr(pkg, "git") and "git" not in kwargs:
if git is None and not hasattr(pkg, "git"):
msg = "Spack version directives cannot include git hashes fetched from"
msg += " URLs. Error in package '%s'\n" % pkg.name
msg += " version('%s', " % version.string

View File

@@ -25,7 +25,7 @@ class {name}(Package):
homepage = "http://www.example.com"
url = "http://www.example.com/test-1.0.tar.gz"
version('1.0', '0123456789abcdef0123456789abcdef')
version("1.0", md5="0123456789abcdef0123456789abcdef")
def install(self, spec, prefix):
pass