Also update CI to install qsymm on relevant platforms, and update
pytest config to skip kwant.qsymm tests when qsymm is not installed
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-# Copyright 2011-2017 Kwant authors. |
|
1 |
+# Copyright 2011-2018 Kwant authors. |
|
2 | 2 |
# |
3 | 3 |
# This file is part of Kwant. It is subject to the license terms in the file |
4 | 4 |
# LICENSE.rst found in the top-level directory of this distribution and at |
... | ... |
@@ -17,7 +17,8 @@ import importlib |
17 | 17 |
|
18 | 18 |
# map from subpackage to sequence of dependency module names |
19 | 19 |
subpackage_dependencies = { |
20 |
- 'kwant/continuum': ['sympy'] |
|
20 |
+ 'kwant/continuum': ['sympy'], |
|
21 |
+ 'kwant/tests/test_qsymm': ['qsymm', 'sympy'], |
|
21 | 22 |
} |
22 | 23 |
|
23 | 24 |
|
Previously the testing/importing 'continuum' would fail if sympy was not
installed. Now we do the following:
* add sympy as an optional dependency in 'extras_require'
* force pytest to ignore tests in packages that have uninstalled
dependencies by defining a hook in 'conftest.py'
* use the 'class as a module' hack when importing 'continuum'.
When sympy is not installed the continuum module will be replaced
with an instance of 'ExtensionUnavailable' that will raise a runtime
error on attribute access.
* no warning is raised if sympy is not installed (it is an
optional dependency).
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,42 @@ |
1 |
+# Copyright 2011-2017 Kwant authors. |
|
2 |
+# |
|
3 |
+# This file is part of Kwant. It is subject to the license terms in the file |
|
4 |
+# LICENSE.rst found in the top-level directory of this distribution and at |
|
5 |
+# http://kwant-project.org/license. A list of Kwant authors can be found in |
|
6 |
+# the file AUTHORS.rst at the top-level directory of this distribution and at |
|
7 |
+# http://kwant-project.org/authors. |
|
8 |
+"""Pytest plugin to ignore packages that have uninstalled dependencies. |
|
9 |
+ |
|
10 |
+This ignores packages on test collection, which is required when the |
|
11 |
+tests reside in a package that itself requires the dependency to be |
|
12 |
+installed. |
|
13 |
+""" |
|
14 |
+ |
|
15 |
+import importlib |
|
16 |
+ |
|
17 |
+ |
|
18 |
+# map from subpackage to sequence of dependency module names |
|
19 |
+subpackage_dependencies = { |
|
20 |
+ 'kwant/continuum': ['sympy'] |
|
21 |
+} |
|
22 |
+ |
|
23 |
+ |
|
24 |
+# map from subpackage to sequence of dependency modules that are not installed |
|
25 |
+dependencies_not_installed = {} |
|
26 |
+for package, dependencies in subpackage_dependencies.items(): |
|
27 |
+ not_installed = [] |
|
28 |
+ for dep in dependencies: |
|
29 |
+ try: |
|
30 |
+ importlib.import_module(dep) |
|
31 |
+ except ImportError: |
|
32 |
+ not_installed.append(dep) |
|
33 |
+ if len(not_installed) != 0: |
|
34 |
+ dependencies_not_installed[package] = not_installed |
|
35 |
+ |
|
36 |
+ |
|
37 |
+def pytest_ignore_collect(path, config): |
|
38 |
+ for subpackage, not_installed in dependencies_not_installed.items(): |
|
39 |
+ if subpackage in path.strpath: |
|
40 |
+ print('ignoring {} because the following dependencies are not ' |
|
41 |
+ 'installed: {}'.format(subpackage, ', '.join(not_installed))) |
|
42 |
+ return True |