diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2019-04-20 21:08:41 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2019-06-05 06:11:18 -0700 |
commit | 87e6cb9f723e0e44b2eddfa7b32e9b6b763e3d35 (patch) | |
tree | 73fbce410510be7f53960722d638c1be8bfb2668 /lib | |
parent | 3f5141d629c18ac47562480ef57df42c98297a1a (diff) | |
download | spack-87e6cb9f723e0e44b2eddfa7b32e9b6b763e3d35.tar.gz spack-87e6cb9f723e0e44b2eddfa7b32e9b6b763e3d35.tar.bz2 spack-87e6cb9f723e0e44b2eddfa7b32e9b6b763e3d35.tar.xz spack-87e6cb9f723e0e44b2eddfa7b32e9b6b763e3d35.zip |
refactor: make Package.name consistent with other class attributes
- 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`
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/directives.py | 5 | ||||
-rw-r--r-- | lib/spack/spack/package.py | 24 |
2 files changed, 18 insertions, 11 deletions
diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py index 26f43171b8..a3bdee0336 100644 --- a/lib/spack/spack/directives.py +++ b/lib/spack/spack/directives.py @@ -100,11 +100,6 @@ class DirectiveMeta(type): # 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: diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index d20a6d8e88..bf406ed742 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -229,6 +229,19 @@ class PackageMeta( """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""" @@ -472,12 +485,6 @@ class PackageBase(with_metaclass(PackageMeta, PackageViewMixin, object)): # 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 @@ -586,6 +593,11 @@ class PackageBase(with_metaclass(PackageMeta, PackageViewMixin, object)): 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 packages are stored.""" |