swc-installation-test-2.py: Refactor PythonPackageDependency._get_version
authorW. Trevor King <wking@tremily.us>
Sun, 30 Dec 2012 18:14:37 +0000 (13:14 -0500)
committerW. Trevor King <wking@tremily.us>
Tue, 1 Jan 2013 14:49:47 +0000 (09:49 -0500)
Split it into pieces for easier subclassing.

swc-installation-test-2.py

index 0617550f64f8e0ecd1f41f30d8a3c7f9310ae8c7..e25712a19c27e049b284e499050d570a994b27b5 100755 (executable)
@@ -331,14 +331,20 @@ class PythonPackageDependency (Dependency):
         self.package = package
 
     def _get_version(self):
+        package = self._get_package(self.package)
+        return self._get_version_from_package(package)
+
+    def _get_package(self, package):
         try:
-            package = _importlib.import_module(self.package)
+            return _importlib.import_module(package)
         except ImportError as e:
             raise DependencyError(
                 checker=self,
-                message="could not import the '{0}' package".format(
-                    self.package),
+                message="could not import the '{0}' package for {1}".format(
+                    package, self.full_name()),
                 )# from e
+
+    def _get_version_from_package(self, package):
         try:
             version = package.__version__
         except AttributeError: