Commit 34a0fb91 authored by Stephan Rave's avatar Stephan Rave
Browse files

[config] require_dependency -> config.require

parent 18325c2b
......@@ -3,8 +3,8 @@
# Copyright 2013-2016 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
from pymor.core.config import require_dependency
require_dependency('DUNEGDT')
from pymor.core.config import config
config.require('DUNEGDT')
import numpy as np
......
......@@ -2,8 +2,8 @@
# Copyright 2013-2021 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)
from pymor.core.config import require_dependency
require_dependency('FENICS')
from pymor.core.config import config
config.require('FENICS')
import dolfin as df
......
......@@ -3,8 +3,8 @@
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)
from pathlib import Path
from pymor.core.config import require_dependency
require_dependency('NGSOLVE')
from pymor.core.config import config
config.require('NGSOLVE')
from pymor.core.defaults import defaults
......
......@@ -2,8 +2,8 @@
# Copyright 2013-2021 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)
from pymor.core.config import require_dependency
require_dependency('PYMESS')
from pymor.core.config import config
config.require('PYMESS')
import numpy as np
......
......@@ -2,8 +2,8 @@
# Copyright 2013-2021 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)
from pymor.core.config import require_dependency
require_dependency('SLYCOT')
from pymor.core.config import config
config.require('SLYCOT')
import numpy as np
......
......@@ -11,17 +11,6 @@ import warnings
from pymor.core.exceptions import DependencyMissing, QtMissing, TorchMissing
def require_dependency(dependency):
dependency = dependency.upper()
if not getattr(config, f'HAVE_{dependency}'):
if dependency == 'QT':
raise QtMissing
elif dependency == 'TORCH':
raise TorchMissing
else:
raise DependencyMissing(dependency)
def _can_import(module):
def _can_import_single(m):
try:
......@@ -179,6 +168,16 @@ class Config:
from pymor import __version__
return __version__
def require(self, dependency):
dependency = dependency.upper()
if not getattr(self, f'HAVE_{dependency}'):
if dependency == 'QT':
raise QtMissing
elif dependency == 'TORCH':
raise TorchMissing
else:
raise DependencyMissing(dependency)
def __getattr__(self, name):
if name.startswith('HAVE_'):
package = name[len('HAVE_'):]
......
......@@ -2,8 +2,8 @@
# Copyright 2013-2021 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)
from pymor.core.config import require_dependency
require_dependency('VTKIO')
from pymor.core.config import config
config.require('VTKIO')
from pymor.discretizers.builtin.grids.io import to_meshio
......
......@@ -11,10 +11,10 @@ intended to be used directly. Instead, use
:class:`~pymor.discretizers.builtin.gui.qt.PatchVisualizer`.
"""
from pymor.core.config import require_dependency
require_dependency('QT')
require_dependency('QTOPENGL')
require_dependency('GL')
from pymor.core.config import config
config.require('QT')
config.require('QTOPENGL')
config.require('GL')
import math as m
......
......@@ -8,9 +8,9 @@ This module provides widgets for displaying plots of
scalar data assigned to one- and two-dimensional grids using
:mod:`matplotlib`. These widgets are not intended to be used directly.
"""
from pymor.core.config import require_dependency
require_dependency('MATPLOTLIB')
require_dependency('QT')
from pymor.core.config import config
config.require('MATPLOTLIB')
config.require('QT')
import numpy as np
from qtpy.QtWidgets import QSizePolicy
......
......@@ -8,8 +8,8 @@ This module provides widgets for displaying plots of
scalar data assigned to one- and two-dimensional grids using
:mod:`matplotlib`. These widgets are not intended to be used directly.
"""
from pymor.core.config import require_dependency
require_dependency('MATPLOTLIB')
from pymor.core.config import config
config.require('MATPLOTLIB')
import numpy as np
......
......@@ -8,8 +8,8 @@ This module provides a few methods and classes for visualizing data
associated to grids. We use the `Qt <http://www.qt-project.org>`_ widget
toolkit for the GUI.
"""
from pymor.core.config import require_dependency
require_dependency('QT')
from pymor.core.config import config
config.require('QT')
import math as m
from tempfile import NamedTemporaryFile
......
......@@ -2,8 +2,9 @@
# Copyright 2013-2021 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)
from pymor.core.config import require_dependency
require_dependency('SCIKIT_FEM')
from pymor.core.config import config
config.require('SCIKIT_FEM')
import numpy as np
from skfem import Basis, BoundaryFacetBasis, BilinearForm, LinearForm, asm, enforce, projection
......
......@@ -2,8 +2,8 @@
# Copyright 2013-2021 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)
from pymor.core.config import require_dependency
require_dependency('SCIKIT_FEM')
from pymor.core.config import config
config.require('SCIKIT_FEM')
import numpy as np
......
......@@ -10,8 +10,8 @@ and `FullyConnectedNN` do not appear in the documentation,
see https://github.com/pymor/pymor/issues/1343.
"""
from pymor.core.config import require_dependency
require_dependency('TORCH')
from pymor.core.config import config
config.require('TORCH')
import numpy as np
......
......@@ -2,8 +2,8 @@
# Copyright 2013-2021 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)
from pymor.core.config import require_dependency
require_dependency('IPYTHON')
from pymor.core.config import config
config.require('IPYTHON')
from itertools import chain
......
......@@ -10,8 +10,8 @@ Due to an issue in autoapi, the classes `NeuralNetworkStatefreeOutputReductor`,
see https://github.com/pymor/pymor/issues/1343.
"""
from pymor.core.config import require_dependency
require_dependency('TORCH')
from pymor.core.config import config
config.require('TORCH')
from numbers import Number
......
......@@ -2,8 +2,8 @@
# Copyright 2013-2021 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)
from pymor.core.config import require_dependency
require_dependency('VTKIO')
from pymor.core.config import config
config.require('VTKIO')
from pathlib import Path
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment