summaryrefslogtreecommitdiff
path: root/lib/spack/llnl
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2016-08-09 13:23:53 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2016-08-10 16:33:37 -0700
commitbf1072c9022cd161b9cc4860e5403a463bc0e05b (patch)
tree67c405d88312d151a65111fbece886084c706eef /lib/spack/llnl
parent8061deb883c84016f282f7e388c3c019af86b4ca (diff)
downloadspack-bf1072c9022cd161b9cc4860e5403a463bc0e05b.tar.gz
spack-bf1072c9022cd161b9cc4860e5403a463bc0e05b.tar.bz2
spack-bf1072c9022cd161b9cc4860e5403a463bc0e05b.tar.xz
spack-bf1072c9022cd161b9cc4860e5403a463bc0e05b.zip
Make Spack core PEP8 compliant.
Diffstat (limited to 'lib/spack/llnl')
-rw-r--r--lib/spack/llnl/util/filesystem.py16
-rw-r--r--lib/spack/llnl/util/lang.py79
-rw-r--r--lib/spack/llnl/util/link_tree.py10
-rw-r--r--lib/spack/llnl/util/lock.py3
-rw-r--r--lib/spack/llnl/util/tty/__init__.py12
-rw-r--r--lib/spack/llnl/util/tty/colify.py32
-rw-r--r--lib/spack/llnl/util/tty/color.py29
-rw-r--r--lib/spack/llnl/util/tty/log.py16
8 files changed, 121 insertions, 76 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
index 4cf99163e0..22ca85abf9 100644
--- a/lib/spack/llnl/util/filesystem.py
+++ b/lib/spack/llnl/util/filesystem.py
@@ -106,6 +106,7 @@ def filter_file(regex, repl, *filenames, **kwargs):
class FileFilter(object):
"""Convenience class for calling filter_file a lot."""
+
def __init__(self, *filenames):
self.filenames = filenames
@@ -355,7 +356,8 @@ def traverse_tree(source_root, dest_root, rel_path='', **kwargs):
# When follow_nonexisting isn't set, don't descend into dirs
# in source that do not exist in dest
if follow_nonexisting or os.path.exists(dest_child):
- tuples = traverse_tree(source_root, dest_root, rel_child, **kwargs) # NOQA: ignore=E501
+ tuples = traverse_tree(
+ source_root, dest_root, rel_child, **kwargs)
for t in tuples:
yield t
@@ -422,14 +424,20 @@ def fix_darwin_install_name(path):
libs = glob.glob(join_path(path, "*.dylib"))
for lib in libs:
# fix install name first:
- subprocess.Popen(["install_name_tool", "-id", lib, lib], stdout=subprocess.PIPE).communicate()[0] # NOQA: ignore=E501
- long_deps = subprocess.Popen(["otool", "-L", lib], stdout=subprocess.PIPE).communicate()[0].split('\n') # NOQA: ignore=E501
+ subprocess.Popen(
+ ["install_name_tool", "-id", lib, lib],
+ stdout=subprocess.PIPE).communicate()[0]
+ long_deps = subprocess.Popen(
+ ["otool", "-L", lib],
+ stdout=subprocess.PIPE).communicate()[0].split('\n')
deps = [dep.partition(' ')[0][1::] for dep in long_deps[2:-1]]
# fix all dependencies:
for dep in deps:
for loc in libs:
if dep == os.path.basename(loc):
- subprocess.Popen(["install_name_tool", "-change", dep, loc, lib], stdout=subprocess.PIPE).communicate()[0] # NOQA: ignore=E501
+ subprocess.Popen(
+ ["install_name_tool", "-change", dep, loc, lib],
+ stdout=subprocess.PIPE).communicate()[0]
break
diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py
index 63eb08d803..df32012e2d 100644
--- a/lib/spack/llnl/util/lang.py
+++ b/lib/spack/llnl/util/lang.py
@@ -24,7 +24,6 @@
##############################################################################
import os
import re
-import sys
import functools
import collections
import inspect
@@ -39,14 +38,15 @@ def index_by(objects, *funcs):
Values are used as keys. For example, suppose you have four
objects with attributes that look like this:
- a = Spec(name="boost", compiler="gcc", arch="bgqos_0")
- b = Spec(name="mrnet", compiler="intel", arch="chaos_5_x86_64_ib")
- c = Spec(name="libelf", compiler="xlc", arch="bgqos_0")
- d = Spec(name="libdwarf", compiler="intel", arch="chaos_5_x86_64_ib")
+ a = Spec(name="boost", compiler="gcc", arch="bgqos_0")
+ b = Spec(name="mrnet", compiler="intel", arch="chaos_5_x86_64_ib")
+ c = Spec(name="libelf", compiler="xlc", arch="bgqos_0")
+ d = Spec(name="libdwarf", compiler="intel", arch="chaos_5_x86_64_ib")
- list_of_specs = [a,b,c,d]
- index1 = index_by(list_of_specs, lambda s: s.arch, lambda s: s.compiler)
- index2 = index_by(list_of_specs, lambda s: s.compiler)
+ list_of_specs = [a,b,c,d]
+ index1 = index_by(list_of_specs, lambda s: s.arch,
+ lambda s: s.compiler)
+ index2 = index_by(list_of_specs, lambda s: s.compiler)
``index1'' now has two levels of dicts, with lists at the
leaves, like this:
@@ -137,7 +137,7 @@ def get_calling_module_name():
finally:
del stack
- if not '__module__' in caller_locals:
+ if '__module__' not in caller_locals:
raise RuntimeError("Must invoke get_calling_module_name() "
"from inside a class definition!")
@@ -173,11 +173,11 @@ def has_method(cls, name):
class memoized(object):
"""Decorator that caches the results of a function, storing them
in an attribute of that function."""
+
def __init__(self, func):
self.func = func
self.cache = {}
-
def __call__(self, *args):
if not isinstance(args, collections.Hashable):
# Not hashable, so just call the function.
@@ -187,12 +187,10 @@ class memoized(object):
self.cache[args] = self.func(*args)
return self.cache[args]
-
def __get__(self, obj, objtype):
"""Support instance methods."""
return functools.partial(self.__call__, obj)
-
def clear(self):
"""Expunge cache so that self.func will be called again."""
self.cache.clear()
@@ -237,13 +235,21 @@ def key_ordering(cls):
if not has_method(cls, '_cmp_key'):
raise TypeError("'%s' doesn't define _cmp_key()." % cls.__name__)
- setter('__eq__', lambda s,o: (s is o) or (o is not None and s._cmp_key() == o._cmp_key()))
- setter('__lt__', lambda s,o: o is not None and s._cmp_key() < o._cmp_key())
- setter('__le__', lambda s,o: o is not None and s._cmp_key() <= o._cmp_key())
-
- setter('__ne__', lambda s,o: (s is not o) and (o is None or s._cmp_key() != o._cmp_key()))
- setter('__gt__', lambda s,o: o is None or s._cmp_key() > o._cmp_key())
- setter('__ge__', lambda s,o: o is None or s._cmp_key() >= o._cmp_key())
+ setter('__eq__',
+ lambda s, o:
+ (s is o) or (o is not None and s._cmp_key() == o._cmp_key()))
+ setter('__lt__',
+ lambda s, o: o is not None and s._cmp_key() < o._cmp_key())
+ setter('__le__',
+ lambda s, o: o is not None and s._cmp_key() <= o._cmp_key())
+
+ setter('__ne__',
+ lambda s, o:
+ (s is not o) and (o is None or s._cmp_key() != o._cmp_key()))
+ setter('__gt__',
+ lambda s, o: o is None or s._cmp_key() > o._cmp_key())
+ setter('__ge__',
+ lambda s, o: o is None or s._cmp_key() >= o._cmp_key())
setter('__hash__', lambda self: hash(self._cmp_key()))
@@ -254,10 +260,10 @@ def key_ordering(cls):
class HashableMap(dict):
"""This is a hashable, comparable dictionary. Hash is performed on
a tuple of the values in the dictionary."""
+
def _cmp_key(self):
return tuple(sorted(self.values()))
-
def copy(self):
"""Type-agnostic clone method. Preserves subclass type."""
# Construct a new dict of my type
@@ -336,24 +342,39 @@ def match_predicate(*args):
return match
-
def DictWrapper(dictionary):
"""Returns a class that wraps a dictionary and enables it to be used
like an object."""
class wrapper(object):
- def __getattr__(self, name): return dictionary[name]
- def __setattr__(self, name, value): dictionary[name] = value
- def setdefault(self, *args): return dictionary.setdefault(*args)
- def get(self, *args): return dictionary.get(*args)
- def keys(self): return dictionary.keys()
- def values(self): return dictionary.values()
- def items(self): return dictionary.items()
- def __iter__(self): return iter(dictionary)
+ def __getattr__(self, name):
+ return dictionary[name]
+
+ def __setattr__(self, name, value):
+ dictionary[name] = value
+
+ def setdefault(self, *args):
+ return dictionary.setdefault(*args)
+
+ def get(self, *args):
+ return dictionary.get(*args)
+
+ def keys(self):
+ return dictionary.keys()
+
+ def values(self):
+ return dictionary.values()
+
+ def items(self):
+ return dictionary.items()
+
+ def __iter__(self):
+ return iter(dictionary)
return wrapper()
class RequiredAttributeError(ValueError):
+
def __init__(self, message):
super(RequiredAttributeError, self).__init__(message)
diff --git a/lib/spack/llnl/util/link_tree.py b/lib/spack/llnl/util/link_tree.py
index b6d8796084..d6547e933a 100644
--- a/lib/spack/llnl/util/link_tree.py
+++ b/lib/spack/llnl/util/link_tree.py
@@ -23,12 +23,13 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
"""LinkTree class for setting up trees of symbolic links."""
-__all__ = ['LinkTree']
import os
import shutil
from llnl.util.filesystem import *
+__all__ = ['LinkTree']
+
empty_file_name = '.spack-empty'
@@ -43,13 +44,13 @@ class LinkTree(object):
modified.
"""
+
def __init__(self, source_root):
if not os.path.exists(source_root):
raise IOError("No such file or directory: '%s'", source_root)
self._root = source_root
-
def find_conflict(self, dest_root, **kwargs):
"""Returns the first file in dest that conflicts with src"""
kwargs['follow_nonexisting'] = False
@@ -61,9 +62,9 @@ class LinkTree(object):
return dest
return None
-
def merge(self, dest_root, **kwargs):
- """Link all files in src into dest, creating directories if necessary."""
+ """Link all files in src into dest, creating directories
+ if necessary."""
kwargs['order'] = 'pre'
for src, dest in traverse_tree(self._root, dest_root, **kwargs):
if os.path.isdir(src):
@@ -83,7 +84,6 @@ class LinkTree(object):
assert(not os.path.exists(dest))
os.symlink(src, dest)
-
def unmerge(self, dest_root, **kwargs):
"""Unlink all files in dest that exist in src.
diff --git a/lib/spack/llnl/util/lock.py b/lib/spack/llnl/util/lock.py
index 4a4aec2385..aa8272d5fe 100644
--- a/lib/spack/llnl/util/lock.py
+++ b/lib/spack/llnl/util/lock.py
@@ -47,6 +47,7 @@ class Lock(object):
and recent NFS versions.
"""
+
def __init__(self, file_path):
self._file_path = file_path
self._fd = None
@@ -225,6 +226,7 @@ class LockTransaction(object):
class ReadTransaction(LockTransaction):
+
def _enter(self):
return self._lock.acquire_read(self._timeout)
@@ -233,6 +235,7 @@ class ReadTransaction(LockTransaction):
class WriteTransaction(LockTransaction):
+
def _enter(self):
return self._lock.acquire_write(self._timeout)
diff --git a/lib/spack/llnl/util/tty/__init__.py b/lib/spack/llnl/util/tty/__init__.py
index ee81e11a20..db74aaba6b 100644
--- a/lib/spack/llnl/util/tty/__init__.py
+++ b/lib/spack/llnl/util/tty/__init__.py
@@ -36,6 +36,7 @@ _debug = False
_verbose = False
indent = " "
+
def is_verbose():
return _verbose
@@ -148,7 +149,8 @@ def get_yes_or_no(prompt, **kwargs):
elif default_value is False:
prompt += ' [y/N] '
else:
- raise ValueError("default for get_yes_no() must be True, False, or None.")
+ raise ValueError(
+ "default for get_yes_no() must be True, False, or None.")
result = None
while result is None:
@@ -174,8 +176,9 @@ def hline(label=None, **kwargs):
char = kwargs.pop('char', '-')
max_width = kwargs.pop('max_width', 64)
if kwargs:
- raise TypeError("'%s' is an invalid keyword argument for this function."
- % next(kwargs.iterkeys()))
+ raise TypeError(
+ "'%s' is an invalid keyword argument for this function."
+ % next(kwargs.iterkeys()))
rows, cols = terminal_size()
if not cols:
@@ -200,7 +203,8 @@ def terminal_size():
"""Gets the dimensions of the console: (rows, cols)."""
def ioctl_GWINSZ(fd):
try:
- rc = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
+ rc = struct.unpack('hh', fcntl.ioctl(
+ fd, termios.TIOCGWINSZ, '1234'))
except:
return
return rc
diff --git a/lib/spack/llnl/util/tty/colify.py b/lib/spack/llnl/util/tty/colify.py
index 81a83691d7..67acdfa517 100644
--- a/lib/spack/llnl/util/tty/colify.py
+++ b/lib/spack/llnl/util/tty/colify.py
@@ -27,15 +27,14 @@ Routines for printing columnar output. See colify() for more information.
"""
import os
import sys
-import fcntl
-import termios
-import struct
from StringIO import StringIO
from llnl.util.tty import terminal_size
from llnl.util.tty.color import clen, cextra
+
class ColumnConfig:
+
def __init__(self, cols):
self.cols = cols
self.line_length = 0
@@ -43,7 +42,8 @@ class ColumnConfig:
self.widths = [0] * cols # does not include ansi colors
def __repr__(self):
- attrs = [(a,getattr(self, a)) for a in dir(self) if not a.startswith("__")]
+ attrs = [(a, getattr(self, a))
+ for a in dir(self) if not a.startswith("__")]
return "<Config: %s>" % ", ".join("%s: %r" % a for a in attrs)
@@ -68,7 +68,7 @@ def config_variable_cols(elts, console_width, padding, cols=0):
max_cols = min(len(elts), max_cols)
# Range of column counts to try. If forced, use the supplied value.
- col_range = [cols] if cols else xrange(1, max_cols+1)
+ col_range = [cols] if cols else xrange(1, max_cols + 1)
# Determine the most columns possible for the console width.
configs = [ColumnConfig(c) for c in col_range]
@@ -106,7 +106,6 @@ def config_uniform_cols(elts, console_width, padding, cols=0):
# 'clen' ignores length of ansi color sequences.
max_len = max(clen(e) for e in elts) + padding
- max_clen = max(len(e) for e in elts) + padding
if cols == 0:
cols = max(1, console_width / max_len)
cols = min(len(elts), cols)
@@ -130,17 +129,19 @@ def colify(elts, **options):
output=<stream> A file object to write to. Default is sys.stdout.
indent=<int> Optionally indent all columns by some number of spaces.
padding=<int> Spaces between columns. Default is 2.
- width=<int> Width of the output. Default is 80 if tty is not detected.
+ width=<int> Width of the output. Default is 80 if tty not detected.
cols=<int> Force number of columns. Default is to size to terminal,
or single-column if no tty
tty=<bool> Whether to attempt to write to a tty. Default is to
- autodetect a tty. Set to False to force single-column output.
+ autodetect a tty. Set to False to force
+ single-column output.
- method=<string> Method to use to fit columns. Options are variable or uniform.
- Variable-width columns are tighter, uniform columns are all the
- same width and fit less data on the screen.
+ method=<string> Method to use to fit columns. Options are variable or
+ uniform. Variable-width columns are tighter, uniform
+ columns are all the same width and fit less data on
+ the screen.
"""
# Get keyword arguments or set defaults
cols = options.pop("cols", 0)
@@ -152,8 +153,9 @@ def colify(elts, **options):
console_cols = options.pop("width", None)
if options:
- raise TypeError("'%s' is an invalid keyword argument for this function."
- % next(options.iterkeys()))
+ raise TypeError(
+ "'%s' is an invalid keyword argument for this function."
+ % next(options.iterkeys()))
# elts needs to be an array of strings so we can count the elements
elts = [str(elt) for elt in elts]
@@ -167,7 +169,8 @@ def colify(elts, **options):
r, c = env_size.split('x')
console_rows, console_cols = int(r), int(c)
tty = True
- except: pass
+ except:
+ pass
# Use only one column if not a tty.
if not tty:
@@ -228,6 +231,7 @@ def colify_table(table, **options):
raise ValueError("Table is empty in colify_table!")
columns = len(table[0])
+
def transpose():
for i in xrange(columns):
for row in table:
diff --git a/lib/spack/llnl/util/tty/color.py b/lib/spack/llnl/util/tty/color.py
index 0abcb09b97..b0c00f1502 100644
--- a/lib/spack/llnl/util/tty/color.py
+++ b/lib/spack/llnl/util/tty/color.py
@@ -75,25 +75,27 @@ To output an @, use '@@'. To output a } inside braces, use '}}'.
import re
import sys
+
class ColorParseError(Exception):
"""Raised when a color format fails to parse."""
+
def __init__(self, message):
super(ColorParseError, self).__init__(message)
# Text styles for ansi codes
-styles = {'*' : '1', # bold
- '_' : '4', # underline
- None : '0' } # plain
+styles = {'*': '1', # bold
+ '_': '4', # underline
+ None: '0'} # plain
# Dim and bright ansi colors
-colors = {'k' : 30, 'K' : 90, # black
- 'r' : 31, 'R' : 91, # red
- 'g' : 32, 'G' : 92, # green
- 'y' : 33, 'Y' : 93, # yellow
- 'b' : 34, 'B' : 94, # blue
- 'm' : 35, 'M' : 95, # magenta
- 'c' : 36, 'C' : 96, # cyan
- 'w' : 37, 'W' : 97 } # white
+colors = {'k': 30, 'K': 90, # black
+ 'r': 31, 'R': 91, # red
+ 'g': 32, 'G': 92, # green
+ 'y': 33, 'Y': 93, # yellow
+ 'b': 34, 'B': 94, # blue
+ 'm': 35, 'M': 95, # magenta
+ 'c': 36, 'C': 96, # cyan
+ 'w': 37, 'W': 97} # white
# Regex to be used for color formatting
color_re = r'@(?:@|\.|([*_])?([a-zA-Z])?(?:{((?:[^}]|}})*)})?)'
@@ -104,6 +106,7 @@ _force_color = False
class match_to_ansi(object):
+
def __init__(self, color=True):
self.color = color
@@ -179,12 +182,14 @@ def cprint(string, stream=sys.stdout, color=None):
"""Same as cwrite, but writes a trailing newline to the stream."""
cwrite(string + "\n", stream, color)
+
def cescape(string):
"""Replace all @ with @@ in the string provided."""
return str(string).replace('@', '@@')
class ColorStream(object):
+
def __init__(self, stream, color=None):
self._stream = stream
self._color = color
@@ -196,7 +201,7 @@ class ColorStream(object):
color = self._color
if self._color is None:
if raw:
- color=True
+ color = True
else:
color = self._stream.isatty() or _force_color
raw_write(colorize(string, color=color))
diff --git a/lib/spack/llnl/util/tty/log.py b/lib/spack/llnl/util/tty/log.py
index ca82da7b17..b67edcf9cc 100644
--- a/lib/spack/llnl/util/tty/log.py
+++ b/lib/spack/llnl/util/tty/log.py
@@ -36,6 +36,7 @@ import llnl.util.tty.color as color
# Use this to strip escape sequences
_escape = re.compile(r'\x1b[^m]*m|\x1b\[?1034h')
+
def _strip(line):
"""Strip color and control characters from a line."""
return _escape.sub('', line)
@@ -58,10 +59,10 @@ class keyboard_input(object):
When the with block completes, this will restore settings before
canonical and echo were disabled.
"""
+
def __init__(self, stream):
self.stream = stream
-
def __enter__(self):
self.old_cfg = None
@@ -86,10 +87,9 @@ class keyboard_input(object):
# Apply new settings for terminal
termios.tcsetattr(fd, termios.TCSADRAIN, self.new_cfg)
- except Exception, e:
+ except Exception:
pass # Some OS's do not support termios, so ignore.
-
def __exit__(self, exc_type, exception, traceback):
# If termios was avaialble, restore old settings after the
# with block
@@ -114,6 +114,7 @@ class log_output(object):
Closes the provided stream when done with the block.
If echo is True, also prints the output to stdout.
"""
+
def __init__(self, stream, echo=False, force_color=False, debug=False):
self.stream = stream
@@ -122,7 +123,7 @@ class log_output(object):
self.force_color = force_color
self.debug = debug
- # Default is to try file-descriptor reassignment unless the system
+ # Default is to try file-descriptor reassignment unless the system
# out/err streams do not have an associated file descriptor
self.directAssignment = False
@@ -130,7 +131,6 @@ class log_output(object):
"""Jumps to __exit__ on the child process."""
raise _SkipWithBlock()
-
def __enter__(self):
"""Redirect output from the with block to a file.
@@ -154,7 +154,8 @@ class log_output(object):
with self.stream as log_file:
with keyboard_input(sys.stdin):
while True:
- rlist, w, x = select.select([read_file, sys.stdin], [], [])
+ rlist, w, x = select.select(
+ [read_file, sys.stdin], [], [])
if not rlist:
break
@@ -211,7 +212,6 @@ class log_output(object):
if self.debug:
tty._debug = True
-
def __exit__(self, exc_type, exception, traceback):
"""Exits on child, handles skipping the with block on parent."""
# Child should just exit here.
@@ -235,7 +235,7 @@ class log_output(object):
sys.stderr = self._stderr
else:
os.dup2(self._stdout, sys.stdout.fileno())
- os.dup2(self._stderr, sys.stderr.fileno())
+ os.dup2(self._stderr, sys.stderr.fileno())
return False