summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoralalazo <massimiliano.culpo@googlemail.com>2016-08-11 09:08:00 +0200
committeralalazo <massimiliano.culpo@googlemail.com>2016-08-11 09:08:00 +0200
commitf5433477b9f7c98ca00947cf1b1fdc106cca1080 (patch)
tree84e321e6b3eccfaac4c59aa8dba3bf71bdfa8c12 /lib
parentb4b9ebe7d718d169dd5f2ab41d4cbc00fed88641 (diff)
downloadspack-f5433477b9f7c98ca00947cf1b1fdc106cca1080.tar.gz
spack-f5433477b9f7c98ca00947cf1b1fdc106cca1080.tar.bz2
spack-f5433477b9f7c98ca00947cf1b1fdc106cca1080.tar.xz
spack-f5433477b9f7c98ca00947cf1b1fdc106cca1080.zip
qa : flake8 issues
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/llnl/util/tty/log.py17
-rw-r--r--lib/spack/spack/build_environment.py13
-rw-r--r--lib/spack/spack/cmd/setup.py7
-rw-r--r--lib/spack/spack/package.py68
4 files changed, 66 insertions, 39 deletions
diff --git a/lib/spack/llnl/util/tty/log.py b/lib/spack/llnl/util/tty/log.py
index 25ed5254a5..a4ba2a9bdf 100644
--- a/lib/spack/llnl/util/tty/log.py
+++ b/lib/spack/llnl/util/tty/log.py
@@ -24,12 +24,11 @@
##############################################################################
"""Utility classes for logging the output of blocks of code.
"""
-import sys
+import multiprocessing
import os
import re
import select
-import inspect
-import multiprocessing
+import sys
import llnl.util.tty as tty
import llnl.util.tty.color as color
@@ -117,9 +116,10 @@ class log_output(object):
# do things ... output will be logged
# and also printed to stdout.
- Opens a stream in 'w' mode at daemon spawning and closes it at daemon joining.
- If echo is True, also prints the output to stdout.
+ Opens a stream in 'w' mode at daemon spawning and closes it at
+ daemon joining. If echo is True, also prints the output to stdout.
"""
+
def __init__(self, filename, echo=False, force_color=False, debug=False):
self.filename = filename
# Various output options
@@ -133,7 +133,11 @@ class log_output(object):
self.read, self.write = os.pipe()
# Sets a daemon that writes to file what it reads from a pipe
- self.p = multiprocessing.Process(target=self._spawn_writing_daemon, args=(self.read,), name='logger_daemon')
+ self.p = multiprocessing.Process(
+ target=self._spawn_writing_daemon,
+ args=(self.read,),
+ name='logger_daemon'
+ )
self.p.daemon = True
# Needed to un-summon the daemon
self.parent_pipe, self.child_pipe = multiprocessing.Pipe()
@@ -186,6 +190,7 @@ class log_output(object):
os.close(self.read)
class OutputRedirection(object):
+
def __init__(self, other):
self.__dict__.update(other.__dict__)
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index f9d795845e..03b044567f 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -51,16 +51,14 @@ There are two parts to the build environment:
Skimming this module is a nice way to get acquainted with the types of
calls you can make from within the install() function.
"""
+import multiprocessing
import os
-import sys
import shutil
-import multiprocessing
-import platform
+import sys
import llnl.util.tty as tty
-from llnl.util.filesystem import *
-
import spack
+from llnl.util.filesystem import *
from spack.environment import EnvironmentModifications, validate
from spack.util.environment import *
from spack.util.executable import Executable, which
@@ -502,7 +500,10 @@ def fork(pkg, function, dirty=False):
child_connection.close()
parent_connection, child_connection = multiprocessing.Pipe()
- p = multiprocessing.Process(target=child_execution, args=(child_connection,))
+ p = multiprocessing.Process(
+ target=child_execution,
+ args=(child_connection,)
+ )
p.start()
exc_type, exception, traceback = parent_connection.recv()
p.join()
diff --git a/lib/spack/spack/cmd/setup.py b/lib/spack/spack/cmd/setup.py
index 9553942017..652c08354f 100644
--- a/lib/spack/spack/cmd/setup.py
+++ b/lib/spack/spack/cmd/setup.py
@@ -58,8 +58,6 @@ def spack_transitive_include_path():
def write_spconfig(package):
- spec = package.spec
- prefix = spec.prefix
# Set-up the environment
spack.build_environment.setup_package(package)
@@ -79,7 +77,7 @@ def write_spconfig(package):
setup_fname = 'spconfig.py'
with open(setup_fname, 'w') as fout:
fout.write(
-r"""#!%s
+ r"""#!%s
#
import sys
@@ -108,8 +106,7 @@ env = dict(os.environ)
fout.write(' %s\n' % part)
fout.write('"""))\n')
- fout.write(
- "env['CMAKE_TRANSITIVE_INCLUDE_PATH'] = env['SPACK_TRANSITIVE_INCLUDE_PATH'] # Deprecated\n")
+ fout.write("env['CMAKE_TRANSITIVE_INCLUDE_PATH'] = env['SPACK_TRANSITIVE_INCLUDE_PATH'] # Deprecated\n") # NOQA: ignore=E501
fout.write('\ncmd = cmdlist("""\n')
fout.write('%s\n' % cmd[0])
for arg in cmd[1:]:
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
index 0d9067a955..3e25dddb0e 100644
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -75,12 +75,13 @@ _ALLOWED_URL_SCHEMES = ["http", "https", "ftp", "file", "git"]
class InstallPhase(object):
"""Manages a single phase of the installation
- This descriptor stores at creation time the name of the method it should search
- for execution. The method is retrieved at __get__ time, so that it can be overridden
- by subclasses of whatever class declared the phases.
+ This descriptor stores at creation time the name of the method it should
+ search for execution. The method is retrieved at __get__ time, so that
+ it can be overridden by subclasses of whatever class declared the phases.
It also provides hooks to execute prerequisite and sanity checks.
"""
+
def __init__(self, name):
self.name = name
self.preconditions = []
@@ -94,6 +95,7 @@ class InstallPhase(object):
# If instance is there the caller wants to execute the
# install phase, thus return a properly set wrapper
phase = getattr(instance, self.name)
+
@functools.wraps(phase)
def phase_wrapper(spec, prefix):
# Check instance attributes at the beginning of a phase
@@ -101,7 +103,8 @@ class InstallPhase(object):
# Execute phase pre-conditions,
# and give them the chance to fail
for check in self.preconditions:
- check(instance) # Do something sensible at some point
+ # Do something sensible at some point
+ check(instance)
phase(spec, prefix)
# Execute phase sanity_checks,
# and give them the chance to fail
@@ -147,8 +150,8 @@ class PackageMeta(type):
# Check if phases is in attr dict, then set
# install phases wrappers
if 'phases' in attr_dict:
- _InstallPhase_phases = [PackageMeta.phase_fmt.format(x) for x in attr_dict['phases']]
- for phase_name, callback_name in zip(_InstallPhase_phases, attr_dict['phases']):
+ _InstallPhase_phases = [PackageMeta.phase_fmt.format(x) for x in attr_dict['phases']] # NOQA: ignore=E501
+ for phase_name, callback_name in zip(_InstallPhase_phases, attr_dict['phases']): # NOQA: ignore=E501
attr_dict[phase_name] = InstallPhase(callback_name)
attr_dict['_InstallPhase_phases'] = _InstallPhase_phases
@@ -160,15 +163,22 @@ class PackageMeta(type):
for phase_name, funcs in checks.items():
try:
# Search for the phase in the attribute dictionary
- phase = attr_dict[PackageMeta.phase_fmt.format(phase_name)]
+ phase = attr_dict[
+ PackageMeta.phase_fmt.format(phase_name)]
except KeyError:
# If it is not there it's in the bases
# and we added a check. We need to copy
# and extend
for base in bases:
- phase = getattr(base, PackageMeta.phase_fmt.format(phase_name), None)
- attr_dict[PackageMeta.phase_fmt.format(phase_name)] = phase.copy()
- phase = attr_dict[PackageMeta.phase_fmt.format(phase_name)]
+ phase = getattr(
+ base,
+ PackageMeta.phase_fmt.format(phase_name),
+ None
+ )
+ attr_dict[PackageMeta.phase_fmt.format(
+ phase_name)] = phase.copy()
+ phase = attr_dict[
+ PackageMeta.phase_fmt.format(phase_name)]
getattr(phase, check_name).extend(funcs)
# Clear the attribute for the next class
setattr(meta, attr_name, {})
@@ -190,8 +200,9 @@ class PackageMeta(type):
def _execute_under_condition(func):
@functools.wraps(func)
def _wrapper(instance):
- # If all the attributes have the value we require, then execute
- if all([getattr(instance, key, None) == value for key, value in attrs.items()]):
+ # If all the attributes have the value we require, then
+ # execute
+ if all([getattr(instance, key, None) == value for key, value in attrs.items()]): # NOQA: ignore=E501
func(instance)
return _wrapper
return _execute_under_condition
@@ -1081,7 +1092,8 @@ class PackageBase(object):
else:
self.do_stage()
- tty.msg("Building {0} [{1}]".format(self.name, type(self).__base__ ))
+ tty.msg("Building {0} [{1}]".format(
+ self.name, type(self).__base__))
self.stage.keep = keep_stage
self.build_directory = join_path(self.stage.path, 'spack-build')
@@ -1106,13 +1118,22 @@ class PackageBase(object):
self.log_path = log_path
self.env_path = env_path
dump_environment(env_path)
- # Spawn a daemon that reads from a pipe and redirects everything to log_path
- with log_output(log_path, verbose, sys.stdout.isatty(), True) as log_redirection:
- for phase_name, phase in zip(self.phases, self._InstallPhase_phases):
- tty.msg('Executing phase : \'{0}\''.format(phase_name))
+ # Spawn a daemon that reads from a pipe and redirects
+ # everything to log_path
+ redirection_context = log_output(
+ log_path, verbose,
+ sys.stdout.isatty(),
+ True
+ )
+ with redirection_context as log_redirection:
+ for phase_name, phase in zip(self.phases, self._InstallPhase_phases): # NOQA: ignore=E501
+ tty.msg(
+ 'Executing phase : \'{0}\''.format(phase_name) # NOQA: ignore=E501
+ )
# Redirect stdout and stderr to daemon pipe
with log_redirection:
- getattr(self, phase)(self.spec, self.prefix)
+ getattr(self, phase)(
+ self.spec, self.prefix)
self.log()
# Run post install hooks before build stage is removed.
spack.hooks.post_install(self)
@@ -1174,7 +1195,7 @@ class PackageBase(object):
"""
self.last_phase = kwargs.pop('stop_at', None)
if self.last_phase is not None and self.last_phase not in self.phases:
- tty.die('\'{0.last_phase}\' is not among the allowed phases for package {0.name}'.format(self))
+ tty.die('\'{0.last_phase}\' is not among the allowed phases for package {0.name}'.format(self)) # NOQA: ignore=E501
def log(self):
# Copy provenance into the install directory on success
@@ -1188,7 +1209,8 @@ class PackageBase(object):
# Remove first if we're overwriting another build
# (can happen with spack setup)
try:
- shutil.rmtree(packages_dir) # log_install_path and env_install_path are inside this
+ # log_install_path and env_install_path are inside this
+ shutil.rmtree(packages_dir)
except Exception:
# FIXME : this potentially catches too many things...
pass
@@ -1609,7 +1631,8 @@ class AutotoolsPackage(PackageBase):
@PackageBase.sanity_check('autoreconf')
def is_configure_or_die(self):
if not os.path.exists('configure'):
- raise RuntimeError('configure script not found in {0}'.format(os.getcwd()))
+ raise RuntimeError(
+ 'configure script not found in {0}'.format(os.getcwd()))
def configure_args(self):
return list()
@@ -1668,7 +1691,8 @@ class CMakePackage(PackageBase):
return list()
def cmake(self, spec, prefix):
- options = [self.root_cmakelists_dir()] + self.std_cmake_args + self.cmake_args()
+ options = [self.root_cmakelists_dir()] + self.std_cmake_args + \
+ self.cmake_args()
create = not os.path.exists(self.wdir())
with working_dir(self.wdir(), create=create):
inspect.getmodule(self).cmake(*options)