Skip to content

Commit

Permalink
refactor: make Package.name consistent with other class attributes
Browse files Browse the repository at this point in the history
- The 'name' attribute for packages was being set in DirectiveMeta, which
  wasn't consistent with other class properties (like fullname, etc.)

- Move it to be a class property of `PackageMeta`, and add the
  corresponding property method wrapper on `PackageBase`
  • Loading branch information
tgamblin committed Jun 5, 2019
1 parent 3f5141d commit 87e6cb9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
5 changes: 0 additions & 5 deletions lib/spack/spack/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ def __init__(cls, name, bases, attr_dict):
# that the directives are called on the class to set it up

if 'spack.pkg' in cls.__module__:
# Package name as taken
# from llnl.util.lang.get_calling_module_name
pkg_name = cls.__module__.split('.')[-1]
setattr(cls, 'name', pkg_name)

# Ensure the presence of the dictionaries associated
# with the directives
for d in DirectiveMeta._directive_names:
Expand Down
24 changes: 18 additions & 6 deletions lib/spack/spack/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,19 @@ def fullname(self):
"""Name of this package, including the namespace"""
return '%s.%s' % (self.namespace, self.name)

@property
def name(self):
"""The name of this package.
The name of a package is the name of its Python module, without
the containing module names.
"""
if not hasattr(self, '_name'):
self._name = self.module.__name__
if '.' in self._name:
self._name = self._name[self._name.rindex('.') + 1:]
return self._name


def run_before(*phases):
"""Registers a method of a package to be run before a given phase"""
Expand Down Expand Up @@ -472,12 +485,6 @@ def __init__(self, spec):
# this determines how the package should be built.
self.spec = spec

# Name of package is the name of its module, without the
# containing module names.
self.name = self.module.__name__
if '.' in self.name:
self.name = self.name[self.name.rindex('.') + 1:]

# Allow custom staging paths for packages
self.path = None

Expand Down Expand Up @@ -585,6 +592,11 @@ def fullname(self):
"""Name of this package, including namespace: namespace.name."""
return type(self).fullname

@property
def name(self):
"""Name of this package (the module without parent modules)."""
return type(self).name

@property
def global_license_dir(self):
"""Returns the directory where global license files for all
Expand Down

0 comments on commit 87e6cb9

Please sign in to comment.