From b5979b13e3f9bcf3e151b494bb2a557aaabedeff Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Sat, 14 May 2016 16:03:42 -0700 Subject: complete lua rework, also module path fix This is a complete rework of the lua package, it also allows the environment modification classes to handle paths that are not separated by colons, and uses the support for same in TCL modules as well. The biggest difference is the handling for lua extension packages, which now have their paths set correctly by the lua parent package, and have access to both lua and luarocks as installation tools. See the luaposix package for what should be required for most lua packages after this. --- lib/spack/spack/directives.py | 2 +- lib/spack/spack/environment.py | 21 +++++++++++---------- lib/spack/spack/modules.py | 7 ++++--- 3 files changed, 16 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py index 74ee7b0add..1819f4308c 100644 --- a/lib/spack/spack/directives.py +++ b/lib/spack/spack/directives.py @@ -292,7 +292,7 @@ def resource(pkg, **kwargs): message += "\tdestination : '{dest}\n'".format(dest=destination) raise RuntimeError(message) # Check if the path falls within the main package stage area - test_path = 'stage_folder_root/' + test_path = 'stage_folder_root' normalized_destination = os.path.normpath(join_path(test_path, destination)) # Normalized absolute path if test_path not in normalized_destination: message = "The destination folder of a resource must fall within the main package stage directory.\n" diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index 11998ad8d2..ee5afb15dd 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -39,7 +39,8 @@ class NameValueModifier(object): def __init__(self, name, value, **kwargs): self.name = name self.value = value - self.args = {'name': name, 'value': value} + self.separator = kwargs.get('separator', ':') + self.args = {'name': name, 'value': value, 'delim': self.separator} self.args.update(kwargs) @@ -56,34 +57,34 @@ class UnsetEnv(NameModifier): class SetPath(NameValueModifier): def execute(self): - string_path = concatenate_paths(self.value) + string_path = concatenate_paths(self.value, separator=self.separator) os.environ[self.name] = string_path class AppendPath(NameValueModifier): def execute(self): environment_value = os.environ.get(self.name, '') - directories = environment_value.split(':') if environment_value else [] + directories = environment_value.split(self.separator) if environment_value else [] directories.append(os.path.normpath(self.value)) - os.environ[self.name] = ':'.join(directories) + os.environ[self.name] = self.separator.join(directories) class PrependPath(NameValueModifier): def execute(self): environment_value = os.environ.get(self.name, '') - directories = environment_value.split(':') if environment_value else [] + directories = environment_value.split(self.separator) if environment_value else [] directories = [os.path.normpath(self.value)] + directories - os.environ[self.name] = ':'.join(directories) + os.environ[self.name] = self.separator.join(directories) class RemovePath(NameValueModifier): def execute(self): environment_value = os.environ.get(self.name, '') - directories = environment_value.split(':') if environment_value else [] + directories = environment_value.split(self.separator) if environment_value else [] directories = [os.path.normpath(x) for x in directories if x != os.path.normpath(self.value)] - os.environ[self.name] = ':'.join(directories) + os.environ[self.name] = self.separator.join(directories) class EnvironmentModifications(object): @@ -238,7 +239,7 @@ class EnvironmentModifications(object): x.execute() -def concatenate_paths(paths): +def concatenate_paths(paths, separator=';'): """ Concatenates an iterable of paths into a string of column separated paths @@ -248,7 +249,7 @@ def concatenate_paths(paths): Returns: string """ - return ':'.join(str(item) for item in paths) + return separator.join(str(item) for item in paths) def set_or_unset_not_first(variable, changes, errstream): diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py index a35e21c3db..9b6a019108 100644 --- a/lib/spack/spack/modules.py +++ b/lib/spack/spack/modules.py @@ -485,9 +485,10 @@ class TclModule(EnvModule): path = join_path(spack.share_path, "modules") environment_modifications_formats = { - PrependPath: 'prepend-path {name} \"{value}\"\n', - AppendPath: 'append-path {name} \"{value}\"\n', - RemovePath: 'remove-path {name} \"{value}\"\n', + formats = { + PrependPath: 'prepend-path --delim "{delim}" {name} \"{value}\"\n', + AppendPath: 'append-path --delim "{delim}" {name} \"{value}\"\n', + RemovePath: 'remove-path --delim "{delim}" {name} \"{value}\"\n', SetEnv: 'setenv {name} \"{value}\"\n', UnsetEnv: 'unsetenv {name}\n' } -- cgit v1.2.3-60-g2f50 From 12e36ee0e731e1d76acd129c50e9b8c79af99d27 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Sat, 14 May 2016 16:20:45 -0700 Subject: fix merge error --- lib/spack/spack/modules.py | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py index 9b6a019108..d2b819e80a 100644 --- a/lib/spack/spack/modules.py +++ b/lib/spack/spack/modules.py @@ -485,7 +485,6 @@ class TclModule(EnvModule): path = join_path(spack.share_path, "modules") environment_modifications_formats = { - formats = { PrependPath: 'prepend-path --delim "{delim}" {name} \"{value}\"\n', AppendPath: 'append-path --delim "{delim}" {name} \"{value}\"\n', RemovePath: 'remove-path --delim "{delim}" {name} \"{value}\"\n', -- cgit v1.2.3-60-g2f50 From df30182a10ec98212a85cb2c2a8209b5d837b001 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Sat, 14 May 2016 17:39:59 -0700 Subject: appeasing flake8 in environment --- lib/spack/spack/environment.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index ee5afb15dd..900036441a 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -64,7 +64,8 @@ class SetPath(NameValueModifier): class AppendPath(NameValueModifier): def execute(self): environment_value = os.environ.get(self.name, '') - directories = environment_value.split(self.separator) if environment_value else [] + directories = environment_value.split( + self.separator) if environment_value else [] directories.append(os.path.normpath(self.value)) os.environ[self.name] = self.separator.join(directories) @@ -72,7 +73,8 @@ class AppendPath(NameValueModifier): class PrependPath(NameValueModifier): def execute(self): environment_value = os.environ.get(self.name, '') - directories = environment_value.split(self.separator) if environment_value else [] + directories = environment_value.split( + self.separator) if environment_value else [] directories = [os.path.normpath(self.value)] + directories os.environ[self.name] = self.separator.join(directories) @@ -80,9 +82,9 @@ class PrependPath(NameValueModifier): class RemovePath(NameValueModifier): def execute(self): environment_value = os.environ.get(self.name, '') - directories = environment_value.split(self.separator) if environment_value else [] - directories = [os.path.normpath(x) - for x in directories + directories = environment_value.split( + self.separator) if environment_value else [] + directories = [os.path.normpath(x) for x in directories if x != os.path.normpath(self.value)] os.environ[self.name] = self.separator.join(directories) @@ -257,16 +259,13 @@ def set_or_unset_not_first(variable, changes, errstream): Check if we are going to set or unset something after other modifications have already been requested """ - indexes = [ii - for ii, item in enumerate(changes) + indexes = [ii for ii, item in enumerate(changes) if ii != 0 and type(item) in [SetEnv, UnsetEnv]] if indexes: good = '\t \t{context} at {filename}:{lineno}' nogood = '\t--->\t{context} at {filename}:{lineno}' message = 'Suspicious requests to set or unset the variable \'{var}\' found' # NOQA: ignore=E501 - errstream( - message.format( - var=variable)) + errstream(message.format(var=variable)) for ii, item in enumerate(changes): print_format = nogood if ii in indexes else good errstream(print_format.format(**item.args)) -- cgit v1.2.3-60-g2f50 From a2197f3a417d63f0f13eac64f016abd0528d7748 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Sat, 14 May 2016 17:51:58 -0700 Subject: yet more sacrifices to the god of short-lines --- lib/spack/spack/directives.py | 49 ++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py index 1819f4308c..51b26773e2 100644 --- a/lib/spack/spack/directives.py +++ b/lib/spack/spack/directives.py @@ -45,11 +45,8 @@ The available directives are: * ``resource`` """ -__all__ = ['depends_on', 'extends', 'provides', 'patch', 'version', - 'variant', 'resource'] import re -import inspect import os.path import functools @@ -67,6 +64,9 @@ from spack.spec import Spec, parse_anonymous_spec from spack.resource import Resource from spack.fetch_strategy import from_kwargs +__all__ = ['depends_on', 'extends', 'provides', 'patch', 'version', 'variant', + 'resource'] + # # This is a list of all directives, built up as they are defined in # this file. @@ -122,15 +122,14 @@ class directive(object): def __init__(self, dicts=None): if isinstance(dicts, basestring): - dicts = (dicts,) + dicts = (dicts, ) elif type(dicts) not in (list, tuple): raise TypeError( - "dicts arg must be list, tuple, or string. Found %s" - % type(dicts)) + "dicts arg must be list, tuple, or string. Found %s" % + type(dicts)) self.dicts = dicts - def ensure_dicts(self, pkg): """Ensure that a package has the dicts required by this directive.""" for d in self.dicts: @@ -142,7 +141,6 @@ class directive(object): raise spack.error.SpackError( "Package %s has non-dict %s attribute!" % (pkg, d)) - def __call__(self, directive_function): directives[directive_function.__name__] = self @@ -259,11 +257,12 @@ def variant(pkg, name, default=False, description=""): """Define a variant for the package. Packager can specify a default value (on or off) as well as a text description.""" - default = bool(default) + default = bool(default) description = str(description).strip() if not re.match(spack.spec.identifier_re, name): - raise DirectiveError("Invalid variant name in %s: '%s'" % (pkg.name, name)) + raise DirectiveError("Invalid variant name in %s: '%s'" % + (pkg.name, name)) pkg.variants[name] = Variant(default, description) @@ -271,31 +270,37 @@ def variant(pkg, name, default=False, description=""): @directive('resources') def resource(pkg, **kwargs): """ - Define an external resource to be fetched and staged when building the package. Based on the keywords present in the - dictionary the appropriate FetchStrategy will be used for the resource. Resources are fetched and staged in their - own folder inside spack stage area, and then linked into the stage area of the package that needs them. + Define an external resource to be fetched and staged when building the + package. Based on the keywords present in the dictionary the appropriate + FetchStrategy will be used for the resource. Resources are fetched and + staged in their own folder inside spack stage area, and then linked into + the stage area of the package that needs them. List of recognized keywords: - * 'when' : (optional) represents the condition upon which the resource is needed - * 'destination' : (optional) path where to link the resource. This path must be relative to the main package stage - area. - * 'placement' : (optional) gives the possibility to fine tune how the resource is linked into the main package stage - area. + * 'when' : (optional) represents the condition upon which the resource is + needed + * 'destination' : (optional) path where to link the resource. This path + must be relative to the main package stage area. + * 'placement' : (optional) gives the possibility to fine tune how the + resource is linked into the main package stage area. """ when = kwargs.get('when', pkg.name) destination = kwargs.get('destination', "") placement = kwargs.get('placement', None) # Check if the path is relative if os.path.isabs(destination): - message = "The destination keyword of a resource directive can't be an absolute path.\n" + message = "The destination keyword of a resource directive can't be" + " an absolute path.\n" message += "\tdestination : '{dest}\n'".format(dest=destination) raise RuntimeError(message) # Check if the path falls within the main package stage area test_path = 'stage_folder_root' - normalized_destination = os.path.normpath(join_path(test_path, destination)) # Normalized absolute path + normalized_destination = os.path.normpath(join_path(test_path, destination) + ) # Normalized absolute path if test_path not in normalized_destination: - message = "The destination folder of a resource must fall within the main package stage directory.\n" + message = "The destination folder of a resource must fall within the" + " main package stage directory.\n" message += "\tdestination : '{dest}'\n".format(dest=destination) raise RuntimeError(message) when_spec = parse_anonymous_spec(when, pkg.name) @@ -307,6 +312,7 @@ def resource(pkg, **kwargs): class DirectiveError(spack.error.SpackError): """This is raised when something is wrong with a package directive.""" + def __init__(self, directive, message): super(DirectiveError, self).__init__(message) self.directive = directive @@ -314,6 +320,7 @@ class DirectiveError(spack.error.SpackError): class CircularReferenceError(DirectiveError): """This is raised when something depends on itself.""" + def __init__(self, directive, package): super(CircularReferenceError, self).__init__( directive, -- cgit v1.2.3-60-g2f50 From c6524d0311146e747667126004b5792eee7d3bf4 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Sun, 15 May 2016 09:50:21 -0700 Subject: environment: fixed comment and default separator --- lib/spack/spack/environment.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index 900036441a..af642dcc9b 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -241,12 +241,14 @@ class EnvironmentModifications(object): x.execute() -def concatenate_paths(paths, separator=';'): +def concatenate_paths(paths, separator=':'): """ - Concatenates an iterable of paths into a string of column separated paths + Concatenates an iterable of paths into a string of paths separated by + separator, defaulting to colon Args: paths: iterable of paths + separator: the separator to use, default ':' Returns: string -- cgit v1.2.3-60-g2f50