Repository: PlasmaPy/PlasmaPy

Issue:
Raise ImportError when installing/importing with old versions of Python, Astropy, & NumPy
We decided that PlasmaPy will only be supported for:
- Python version > 3.6
- Astropy version > 2.0
- NumPy version > 1.13

However, when I try to run:
```ShellSession
python setup.py install
```
from the command line with Python 3.5 then I get a `SyntaxError` for syntax that is new in version 3.6.

When I try to run
```Python
import plasmapy
```
in Python 3.6 with Astropy 1.3.1, then I get an exception since one of the constants imported from Astropy was renamed in 2.0.

We should raise an appropriate exception (probably an `ImportError`) when we try to install or import PlasmaPy with any of the unsupported versions above.  We should also have appropriate and useful error messages for any of these situations.  The pull request to close this issue would involve editing `setup.py`, `requirements/base.txt`, and `plasmapy/__init__.py`.

Thank you!
Nick


Discussion:

Resolving patch:
diff --git a/plasmapy/__init__.py b/plasmapy/__init__.py
--- a/plasmapy/__init__.py
+++ b/plasmapy/__init__.py
@@ -5,16 +5,81 @@
     author as __author__,
 )
 
-from .classes import Plasma
-from . import classes
-from . import constants
-from . import atomic
-from . import math
-from . import physics
-from . import utils
-
 import sys
 import warnings
 
-if sys.version_info[:2] < (3, 6):  # coveralls: ignore
+__minimum_python_version__ = '3.6'
+__minimum_numpy_version__ = '1.13.0'
+__minimum_astropy_version__ = '2.0.0'
+
+
+def _split_version(version):
+    return tuple(int(ver) for ver in version.split('.'))
+
+
+def _min_required_version(required, current):  # coveralls: ignore
+    """ Return `True` if the current version meets the required minimum
+        version and `False` if not/ if not installed.
+
+        Right now `required` and `current` are just '.' separated strings
+        but it would be good to make this more general and accept modules.
+    """
+    return _split_version(current) >= _split_version(required)
+
+
+def _check_numpy_version():  # coveralls: ignore
+    """ Make sure numpy in installed and meets the minimum version requirements
+    """
+    required_version = False
+    np_ver = None
+
+    try:
+        from numpy import __version__ as np_ver
+        required_version = _min_required_version(__minimum_numpy_version__,
+                                                 np_ver)
+    except ImportError:
+        pass
+
+    if not required_version:
+        ver_error = ("Numpy {} or above is required for PlasmaPy. The "
+                     "currently installed version is {}"
+                     ).format(__minimum_numpy_version__, np_ver)
+        raise ImportError(ver_error)
+
+
+def _check_astropy_version():  # coveralls: ignore
+    """ Make sure astropy in installed and meets the minimum version requirements
+    """
+    required_version = False
+    ap_ver = None
+
+    try:
+        from astropy import __version__ as ap_ver
+        required_version = _min_required_version(__minimum_astropy_version__,
+                                                 ap_ver)
+    except ImportError:
+        pass
+
+    if not required_version:
+        ver_error = ("Astropy {} or above is required for PlasmaPy. The "
+                     "currently installed version is {}"
+                     ).format(__minimum_astropy_version__, ap_ver)
+        raise ImportError(ver_error)
+
+
+if (sys.version_info < _split_version(__minimum_python_version__)):  # coveralls: ignore
     warnings.warn("PlasmaPy does not support Python 3.5 and below")
+
+_check_numpy_version()
+_check_astropy_version()
+
+try:
+    from .classes import Plasma
+    from . import classes
+    from . import constants
+    from . import atomic
+    from . import math
+    from . import physics
+    from . import utils
+except Exception:
+    raise ImportError("Unable to load PlasmaPy subpackages.")


Test patch: