diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/llnl/util/filesystem.py | 27 | ||||
-rw-r--r-- | lib/spack/spack/__init__.py | 4 | ||||
-rw-r--r-- | lib/spack/spack/cmd/checksum.py | 6 | ||||
-rw-r--r-- | lib/spack/spack/compilers/gcc.py | 2 | ||||
-rw-r--r-- | lib/spack/spack/package.py | 2 | ||||
-rw-r--r-- | lib/spack/spack/url.py | 20 |
6 files changed, 49 insertions, 12 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index 3782aefcce..a70111b915 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -38,7 +38,7 @@ import llnl.util.tty as tty from spack.util.compression import ALLOWED_ARCHIVE_TYPES -def filter_file(regex, repl, *filenames): +def filter_file(regex, repl, *filenames, **kwargs): """Like sed, but uses python regular expressions. Filters every line of file through regex and replaces the file @@ -49,16 +49,31 @@ def filter_file(regex, repl, *filenames): return a suitable replacement string. If it is a string, it can contain ``\1``, ``\2``, etc. to represent back-substitution as sed would allow. + + Keyword Options: + string[=False] If True, treat regex as a plain string. + backup[=True] Make a backup files suffixed with ~ + ignore_absent[=False] Ignore any files that don't exist. """ - # Keep callables intact - if not hasattr(repl, '__call__'): - # Allow strings to use \1, \2, etc. for replacement, like sed + string = kwargs.get('string', False) + backup = kwargs.get('backup', True) + ignore_absent = kwargs.get('ignore_absent', False) + + # Allow strings to use \1, \2, etc. for replacement, like sed + if not callable(repl): unescaped = repl.replace(r'\\', '\\') repl = lambda m: re.sub( r'\\([0-9])', lambda x: m.group(int(x.group(1))), unescaped) + if string: + regex = re.escape(regex) + for filename in filenames: backup = filename + "~" + + if ignore_absent and not os.path.exists(filename): + continue + shutil.copy(filename, backup) try: with closing(open(backup)) as infile: @@ -71,6 +86,10 @@ def filter_file(regex, repl, *filenames): shutil.move(backup, filename) raise + finally: + if not backup: + shutil.rmtree(backup, ignore_errors=True) + def change_sed_delimiter(old_delim, new_delim, *filenames): """Find all sed search/replace commands and change the delimiter. diff --git a/lib/spack/spack/__init__.py b/lib/spack/spack/__init__.py index bf91a885ca..da7088640f 100644 --- a/lib/spack/spack/__init__.py +++ b/lib/spack/spack/__init__.py @@ -137,9 +137,9 @@ sys_type = None # TODO: it's not clear where all the stuff that needs to be included in packages # should live. This file is overloaded for spack core vs. for packages. # -__all__ = ['Package', 'Version', 'when'] +__all__ = ['Package', 'Version', 'when', 'ver'] from spack.package import Package -from spack.version import Version +from spack.version import Version, ver from spack.multimethod import when import llnl.util.filesystem diff --git a/lib/spack/spack/cmd/checksum.py b/lib/spack/spack/cmd/checksum.py index 5a8109b70f..8a52178833 100644 --- a/lib/spack/spack/cmd/checksum.py +++ b/lib/spack/spack/cmd/checksum.py @@ -117,7 +117,5 @@ def checksum(parser, args): if not version_hashes: tty.die("Could not fetch any available versions for %s." % pkg.name) - dict_string = [" '%s' : '%s'," % (v, h) for v, h in version_hashes] - dict_string = ['{'] + dict_string + ["}"] - - tty.msg("Checksummed new versions of %s:" % pkg.name, *dict_string) + version_lines = [" version('%s', '%s')" % (v, h) for v, h in version_hashes] + tty.msg("Checksummed new versions of %s:" % pkg.name, *version_lines) diff --git a/lib/spack/spack/compilers/gcc.py b/lib/spack/spack/compilers/gcc.py index 097b24bb87..f0d27d590e 100644 --- a/lib/spack/spack/compilers/gcc.py +++ b/lib/spack/spack/compilers/gcc.py @@ -56,7 +56,7 @@ class Gcc(Compiler): return get_compiler_version( fc, '-dumpversion', # older gfortran versions don't have simple dumpversion output. - r'(?:GNU Fortran \(GCC\))?(\d+\.\d+\.\d+)') + r'(?:GNU Fortran \(GCC\))?(\d+\.\d+(?:\.\d+)?)') @classmethod diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 9644aa43d3..0d6c400bd8 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -859,7 +859,7 @@ def find_versions_of_archive(archive_url, **kwargs): list_depth = kwargs.get('list_depth', 1) if not list_url: - list_url = os.path.dirname(archive_url) + list_url = url.find_list_url(archive_url) # This creates a regex from the URL with a capture group for the # version part of the URL. The capture group is converted to a diff --git a/lib/spack/spack/url.py b/lib/spack/spack/url.py index 902ce9817d..e2fbb19f5d 100644 --- a/lib/spack/spack/url.py +++ b/lib/spack/spack/url.py @@ -78,6 +78,26 @@ class UndetectableNameError(UrlParseError): "Couldn't parse package name in: " + path, path) +def find_list_url(url): + """Finds a good list URL for the supplied URL. This depends on + the site. By default, just assumes that a good list URL is the + dirname of an archive path. For github URLs, this returns the + URL of the project's releases page. + """ + + url_types = [ + # e.g. https://github.com/scalability-llnl/callpath/archive/v1.0.1.tar.gz + (r'^(https://github.com/[^/]+/[^/]+)/archive/', lambda m: m.group(1) + '/releases') + ] + + for pattern, fun in url_types: + match = re.search(pattern, url) + if match: + return fun(match) + else: + return os.path.dirname(url) + + def parse_version_string_with_indices(path): """Try to extract a version string from a filename or URL. This is taken largely from Homebrew's Version class.""" |