Skip to content

Commit

Permalink
YAML config files for compilers and mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
mplegendre authored and tgamblin committed May 18, 2015
1 parent cd1ca36 commit 46b91dd
Show file tree
Hide file tree
Showing 12 changed files with 395 additions and 541 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*~
.DS_Store
.idea
/etc/spack/*
/etc/spackconfig
/share/spack/dotkit
/share/spack/modules
2 changes: 1 addition & 1 deletion lib/spack/spack/cmd/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def compiler_add(args):
spack.compilers.add_compilers_to_config('user', *compilers)
n = len(compilers)
tty.msg("Added %d new compiler%s to %s" % (
n, 's' if n > 1 else '', spack.config.get_filename('user')))
n, 's' if n > 1 else '', spack.config.get_config_scope_filename('user', 'compilers')))
colify(reversed(sorted(c.spec for c in compilers)), indent=4)
else:
tty.msg("Found no new compilers")
Expand Down
31 changes: 8 additions & 23 deletions lib/spack/spack/cmd/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,27 @@ def setup_parser(subparser):

sp = subparser.add_subparsers(metavar='SUBCOMMAND', dest='config_command')

set_parser = sp.add_parser('set', help='Set configuration values.')
set_parser.add_argument('key', help="Key to set value for.")
set_parser.add_argument('value', nargs='?', default=None,
help="Value to associate with key")

get_parser = sp.add_parser('get', help='Get configuration values.')
get_parser.add_argument('key', help="Key to get value for.")
get_parser = sp.add_parser('get', help='Print configuration values.')
get_parser.add_argument('category', help="Configuration category to print.")

edit_parser = sp.add_parser('edit', help='Edit configuration file.')


def config_set(args):
# default scope for writing is 'user'
if not args.scope:
args.scope = 'user'

config = spack.config.get_config(args.scope)
config.set_value(args.key, args.value)
config.write()
edit_parser.add_argument('category', help="Configuration category to edit")


def config_get(args):
config = spack.config.get_config(args.scope)
print config.get_value(args.key)
spack.config.print_category(args.category)


def config_edit(args):
if not args.scope:
args.scope = 'user'
config_file = spack.config.get_filename(args.scope)
if not args.category:
args.category = None
config_file = spack.config.get_config_scope_filename(args.scope, args.category)
spack.editor(config_file)


def config(parser, args):
action = { 'set' : config_set,
'get' : config_get,
action = { 'get' : config_get,
'edit' : config_edit }
action[args.config_command](args)

18 changes: 6 additions & 12 deletions lib/spack/spack/cmd/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,36 +75,30 @@ def mirror_add(args):
if url.startswith('/'):
url = 'file://' + url

config = spack.config.get_config('user')
config.set_value('mirror', args.name, 'url', url)
config.write()
mirror_dict = { args.name : url }
spack.config.add_to_mirror_config({ args.name : url })


def mirror_remove(args):
"""Remove a mirror by name."""
config = spack.config.get_config('user')
name = args.name

if not config.has_named_section('mirror', name):
rmd_something = spack.config.remove_from_config('mirrors', name)
if not rmd_something:
tty.die("No such mirror: %s" % name)
config.remove_named_section('mirror', name)
config.write()


def mirror_list(args):
"""Print out available mirrors to the console."""
config = spack.config.get_config()
sec_names = config.get_section_names('mirror')

sec_names = spack.config.get_mirror_config()
if not sec_names:
tty.msg("No mirrors configured.")
return

max_len = max(len(s) for s in sec_names)
fmt = "%%-%ds%%s" % (max_len + 4)

for name in sec_names:
val = config.get_value('mirror', name, 'url')
for name, val in sec_names.iteritems():
print fmt % (name, val)


Expand Down
43 changes: 21 additions & 22 deletions lib/spack/spack/compilers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,25 @@ def _get_config():
first."""
# If any configuration file has compilers, just stick with the
# ones already configured.
config = spack.config.get_config()
config = spack.config.get_compilers_config()
existing = [spack.spec.CompilerSpec(s)
for s in config.get_section_names('compiler')]
for s in config]
if existing:
return config

compilers = find_compilers(*get_path('PATH'))
new_compilers = [
c for c in compilers if c.spec not in existing]
add_compilers_to_config('user', *new_compilers)
add_compilers_to_config('user', *compilers)

# After writing compilers to the user config, return a full config
# from all files.
return spack.config.get_config(refresh=True)
return spack.config.get_compilers_config()


@memoized
_cached_default_compiler = None
def default_compiler():
global _cached_default_compiler
if _cached_default_compiler:
return _cached_default_compiler
versions = []
for name in _default_order: # TODO: customize order.
versions = find(name)
Expand All @@ -86,7 +87,8 @@ def default_compiler():
if not versions:
raise NoCompilersError()

return sorted(versions)[-1]
_cached_default_compiler = sorted(versions)[-1]
return _cached_default_compiler


def find_compilers(*path):
Expand Down Expand Up @@ -122,19 +124,17 @@ def find_compilers(*path):


def add_compilers_to_config(scope, *compilers):
config = spack.config.get_config(scope)
compiler_config_tree = {}
for compiler in compilers:
add_compiler(config, compiler)
config.write()


def add_compiler(config, compiler):
def setup_field(cspec, name, exe):
path = exe if exe else "None"
config.set_value('compiler', cspec, name, path)
compiler_entry = {}
for c in _required_instance_vars:
val = getattr(compiler, c)
if not val:
val = "None"
compiler_entry[c] = val
compiler_config_tree[str(compiler.spec)] = compiler_entry
spack.config.add_to_compiler_config(compiler_config_tree, scope)

for c in _required_instance_vars:
setup_field(compiler.spec, c, getattr(compiler, c))


def supported_compilers():
Expand All @@ -157,8 +157,7 @@ def all_compilers():
available to build with. These are instances of CompilerSpec.
"""
configuration = _get_config()
return [spack.spec.CompilerSpec(s)
for s in configuration.get_section_names('compiler')]
return [spack.spec.CompilerSpec(s) for s in configuration]


@_auto_compiler_spec
Expand All @@ -176,7 +175,7 @@ def compilers_for_spec(compiler_spec):
config = _get_config()

def get_compiler(cspec):
items = dict((k,v) for k,v in config.items('compiler "%s"' % cspec))
items = config[str(cspec)]

if not all(n in items for n in _required_instance_vars):
raise InvalidCompilerConfigurationError(cspec)
Expand Down
Loading

0 comments on commit 46b91dd

Please sign in to comment.