summary refs log tree commit diff
path: root/synapse/python_dependencies.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-09-01 16:47:26 +0100
committerMark Haines <mark.haines@matrix.org>2015-09-01 16:47:26 +0100
commit3cdfd37d95484b9ebca012a8169b8d6613385656 (patch)
tree5f04080c6fe565e4fe49fdcbd5a1eae9ecb7f8d6 /synapse/python_dependencies.py
parentMerge pull request #264 from matrix-org/markjh/syweb_on_pypi (diff)
downloadsynapse-3cdfd37d95484b9ebca012a8169b8d6613385656.tar.xz
Print an example "pip install" line for a missing requirement
Diffstat (limited to 'synapse/python_dependencies.py')
-rw-r--r--synapse/python_dependencies.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/synapse/python_dependencies.py b/synapse/python_dependencies.py
index 795ef27182..387183b50b 100644
--- a/synapse/python_dependencies.py
+++ b/synapse/python_dependencies.py
@@ -60,7 +60,10 @@ DEPENDENCY_LINKS = {
 
 
 class MissingRequirementError(Exception):
-    pass
+    def __init__(self, message, module_name, dependency):
+        super(MissingRequirementError, self).__init__(message)
+        self.module_name = module_name
+        self.dependency = dependency
 
 
 def check_requirements(config=None):
@@ -88,7 +91,7 @@ def check_requirements(config=None):
                 )
                 raise MissingRequirementError(
                     "Can't import %r which is part of %r"
-                    % (module_name, dependency)
+                    % (module_name, dependency), module_name, dependency
                 )
             version = getattr(module, "__version__", None)
             file_path = getattr(module, "__file__", None)
@@ -101,23 +104,25 @@ def check_requirements(config=None):
                 if version is None:
                     raise MissingRequirementError(
                         "Version of %r isn't set as __version__ of module %r"
-                        % (dependency, module_name)
+                        % (dependency, module_name), module_name, dependency
                     )
                 if LooseVersion(version) < LooseVersion(required_version):
                     raise MissingRequirementError(
                         "Version of %r in %r is too old. %r < %r"
-                        % (dependency, file_path, version, required_version)
+                        % (dependency, file_path, version, required_version),
+                        module_name, dependency
                     )
             elif version_test == "==":
                 if version is None:
                     raise MissingRequirementError(
                         "Version of %r isn't set as __version__ of module %r"
-                        % (dependency, module_name)
+                        % (dependency, module_name), module_name, dependency
                     )
                 if LooseVersion(version) != LooseVersion(required_version):
                     raise MissingRequirementError(
                         "Unexpected version of %r in %r. %r != %r"
-                        % (dependency, file_path, version, required_version)
+                        % (dependency, file_path, version, required_version),
+                        module_name, dependency
                     )