init: convert spack.dirty global to config option

This commit is contained in:
Todd Gamblin 2018-04-15 22:45:40 -07:00 committed by scheibelp
parent 278933e824
commit 2ab7b7a5a0
4 changed files with 12 additions and 34 deletions

View File

@ -44,11 +44,6 @@
binary_cache_retrieved_specs = set() binary_cache_retrieved_specs = set()
# If this is True, spack will not clean the environment to remove
# potentially harmful variables before builds.
dirty = spack.config.get('config:dirty', False)
#: The number of jobs to use when building in parallel. #: The number of jobs to use when building in parallel.
#: By default, use all cores on the machine. #: By default, use all cores on the machine.
build_jobs = spack.config.get('config:build_jobs', multiprocessing.cpu_count()) build_jobs = spack.config.get('config:build_jobs', multiprocessing.cpu_count())

View File

@ -26,6 +26,7 @@
import argparse import argparse
import spack.cmd import spack.cmd
import spack.config
import spack.modules import spack.modules
import spack.spec import spack.spec
import spack.store import spack.store
@ -52,7 +53,7 @@ def add_common_arguments(parser, list_of_arguments):
class ConstraintAction(argparse.Action): class ConstraintAction(argparse.Action):
"""Constructs a list of specs based on a constraint given on the command line """Constructs a list of specs based on constraints from the command line
An instance of this class is supposed to be used as an argument action An instance of this class is supposed to be used as an argument action
in a parser. It will read a constraint and will attach a function to the in a parser. It will read a constraint and will attach a function to the
@ -82,23 +83,6 @@ def _specs(self, **kwargs):
return sorted(specs) return sorted(specs)
class CleanOrDirtyAction(argparse.Action):
"""Sets the dirty flag in the current namespace"""
def __init__(self, *args, **kwargs):
kwargs['default'] = spack.dirty
super(CleanOrDirtyAction, self).__init__(*args, **kwargs)
def __call__(self, parser, namespace, values, option_string=None):
if option_string == '--clean':
setattr(namespace, self.dest, False)
elif option_string == '--dirty':
setattr(namespace, self.dest, True)
else:
msg = 'expected "--dirty" or "--clean" [got {0} instead]'
raise argparse.ArgumentError(msg.format(option_string))
_arguments['constraint'] = Args( _arguments['constraint'] = Args(
'constraint', nargs=argparse.REMAINDER, action=ConstraintAction, 'constraint', nargs=argparse.REMAINDER, action=ConstraintAction,
help='constraint to select a subset of installed packages') help='constraint to select a subset of installed packages')
@ -107,7 +91,7 @@ def __call__(self, parser, namespace, values, option_string=None):
'-m', '--module-type', '-m', '--module-type',
choices=spack.modules.module_types.keys(), choices=spack.modules.module_types.keys(),
action='append', action='append',
help='type of module file. More than one choice is allowed [default: tcl]') # NOQA: ignore=E501 help='type of module file. More than one choice is allowed [default: tcl]')
_arguments['yes_to_all'] = Args( _arguments['yes_to_all'] = Args(
'-y', '--yes-to-all', action='store_true', dest='yes_to_all', '-y', '--yes-to-all', action='store_true', dest='yes_to_all',
@ -119,18 +103,17 @@ def __call__(self, parser, namespace, values, option_string=None):
_arguments['clean'] = Args( _arguments['clean'] = Args(
'--clean', '--clean',
action=CleanOrDirtyAction, action='store_false',
default=spack.config.get('config:dirty'),
dest='dirty', dest='dirty',
help='sanitize the environment from variables that can affect how ' + help='unset harmful variables in the build environment (default)')
' packages find libraries or headers',
nargs=0)
_arguments['dirty'] = Args( _arguments['dirty'] = Args(
'--dirty', '--dirty',
action=CleanOrDirtyAction, action='store_true',
default=spack.config.get('config:dirty'),
dest='dirty', dest='dirty',
help='maintain the current environment without trying to sanitize it', help='preserve user environment in the spack build environment (danger!)')
nargs=0)
_arguments['long'] = Args( _arguments['long'] = Args(
'-l', '--long', action='store_true', '-l', '--long', action='store_true',

View File

@ -31,7 +31,6 @@
import spack.cmd.common.arguments as arguments import spack.cmd.common.arguments as arguments
description = "patch expanded archive sources in preparation for install" description = "patch expanded archive sources in preparation for install"
section = "build" section = "build"
level = "long" level = "long"

View File

@ -31,8 +31,9 @@
import llnl.util.filesystem as fs import llnl.util.filesystem as fs
import spack import spack
import spack.cmd.install import spack.config
import spack.package import spack.package
import spack.cmd.install
from spack.error import SpackError from spack.error import SpackError
from spack.spec import Spec from spack.spec import Spec
from spack.main import SpackCommand from spack.main import SpackCommand
@ -125,7 +126,7 @@ def test_install_package_already_installed(
@pytest.mark.parametrize('arguments,expected', [ @pytest.mark.parametrize('arguments,expected', [
([], spack.dirty), # The default read from configuration file ([], spack.config.get('config:dirty')), # default from config file
(['--clean'], False), (['--clean'], False),
(['--dirty'], True), (['--dirty'], True),
]) ])