summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2017-08-20 15:34:35 -0700
committerGitHub <noreply@github.com>2017-08-20 15:34:35 -0700
commite77c1a20c5964c169d0ac557e13fd071804f68ed (patch)
treea1d1c5650e396de376001b272d469ec8704c3281 /lib
parent99fb394ac18b7ef1bc4f9ee34242a69b42781ab8 (diff)
downloadspack-e77c1a20c5964c169d0ac557e13fd071804f68ed.tar.gz
spack-e77c1a20c5964c169d0ac557e13fd071804f68ed.tar.bz2
spack-e77c1a20c5964c169d0ac557e13fd071804f68ed.tar.xz
spack-e77c1a20c5964c169d0ac557e13fd071804f68ed.zip
Fix issue with color formatting regular expression. (#5171)
- Fix issue with color formatting regular expression. - _separators regex in spec.py could be constructed such that '^' came first in the character matcher, e.g. '[^@#/]'. This inverts the match and causes transient KeyErrors. - Fixed to escape all characters in the constructed regex. - This bug comes up in Python3 due to its more randomized hash iteration order, but it could probably also happen in a Python 2 implementation. - also clean up variable docstrings in spec.py
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/spec.py39
1 files changed, 20 insertions, 19 deletions
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 05db84806f..43d57f2b98 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -165,21 +165,20 @@ __all__ = [
'NoSuchHashError',
'RedundantSpecError']
-# Valid pattern for an identifier in Spack
+#: Valid pattern for an identifier in Spack
identifier_re = r'\w[\w-]*'
-# Convenient names for color formats so that other things can use them
-compiler_color = '@g'
-version_color = '@c'
-architecture_color = '@m'
-enabled_variant_color = '@B'
-disabled_variant_color = '@r'
-dependency_color = '@.'
-hash_color = '@K'
-
-"""This map determines the coloring of specs when using color output.
- We make the fields different colors to enhance readability.
- See spack.color for descriptions of the color codes. """
+compiler_color = '@g' #: color for highlighting compilers
+version_color = '@c' #: color for highlighting versions
+architecture_color = '@m' #: color for highlighting architectures
+enabled_variant_color = '@B' #: color for highlighting enabled variants
+disabled_variant_color = '@r' #: color for highlighting disabled varaints
+dependency_color = '@.' #: color for highlighting dependencies
+hash_color = '@K' #: color for highlighting package hashes
+
+#: This map determines the coloring of specs when using color output.
+#: We make the fields different colors to enhance readability.
+#: See spack.color for descriptions of the color codes.
color_formats = {'%': compiler_color,
'@': version_color,
'=': architecture_color,
@@ -188,17 +187,19 @@ color_formats = {'%': compiler_color,
'^': dependency_color,
'#': hash_color}
-"""Regex used for splitting by spec field separators."""
-_separators = '[%s]' % ''.join(color_formats.keys())
+#: Regex used for splitting by spec field separators.
+#: These need to be escaped to avoid metacharacters in
+#: ``color_formats.keys()``.
+_separators = '[\\%s]' % '\\'.join(color_formats.keys())
-"""Versionlist constant so we don't have to build a list
- every time we call str()"""
+#: Versionlist constant so we don't have to build a list
+#: every time we call str()
_any_version = VersionList([':'])
-"""Types of dependencies that Spack understands."""
+#: Types of dependencies that Spack understands.
alldeps = ('build', 'link', 'run')
-"""Max integer helps avoid passing too large a value to cyaml."""
+#: Max integer helps avoid passing too large a value to cyaml.
maxint = 2 ** (ctypes.sizeof(ctypes.c_int) * 8 - 1) - 1