diff --git a/CHANGELOG.md b/CHANGELOG.md index 17a80ef7..d845316e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. ## latest +* `packaging` and `pip` are now optional dependencies. https://github.com/precice/python-bindings/pull/63 * Feature: Bindings are now available via Spack. https://github.com/spack/spack/pull/19558 * Bugfix: Bindings also support empty read/write data for block read/write operations (like C++ preCICE API). https://github.com/precice/python-bindings/pull/69 diff --git a/README.md b/README.md index c3d597fc..6fe0b37f 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,8 @@ This package provides python language bindings for the C++ library [preCICE](htt # Installing the package -We recommend using pip3 (version 19.0 or newer) for the sake of simplicity. You can check your pip3 version via `pip3 --version`. To update pip3, use the following line: +We recommend using pip3 (version 19.0.0 or newer required) for the sake of simplicity. You can check your pip3 version via `pip3 --version`. To update pip3, use the following line: + ``` $ pip3 install --upgrade pip ``` @@ -171,39 +172,6 @@ There are two possible reasons, why preCICE is not found: In case the compilation fails with `shared_ptr.pxd not found` messages, check if you use the latest version of Cython. -### Version of pip3 is too old - -If you see the following error -``` -error: option --single-version-externally-managed not recognized -``` -your version of pip might be too old. Please update pip and try again. One possible way for updating pip is to run the following commands: -``` -wget -q https://bootstrap.pypa.io/get-pip.py -O get-pip.py && python3 get-pip.py -``` -*Be aware that `python3 get-pip.py` might require root privileges.* - -Check your version of pip via `pip3 --version`. For version 8.1.1 and 9.0.1 we know that this problem occurs. *Remark:* you get versions 8.1.1 of pip if you use `sudo apt install python3-pip` on Ubuntu 16.04 (pip version 9.0.1 on Ubuntu 18.04) - -### Build-time dependencies (Cython, numpy...) defined in `pyproject.toml` are not installed automatically - -If you see the following error -``` -Collecting pyprecice - Using cached https://files.pythonhosted.org/packages/a6/fb/66f78168394afa2adca62ecd9079a98e741fbf3c6a96845719641ea27912/pyprecice-2.0.0.1.tar.gz - Complete output from command python setup.py egg_info: - Traceback (most recent call last): - File "", line 1, in - File "/tmp/pip-build-ebyoc0sq/pyprecice/setup.py", line 7, in - from Cython.Distutils.extension import Extension - ModuleNotFoundError: No module named 'Cython' -``` -your pip might be too old and therefore it does not use the information from `pyproject.toml`. You can update your pip via -``` -pip3 install --upgrade pip -``` -then try to install `pyprecice`, again. - ### `Python.h` missing ``` diff --git a/pyproject.toml b/pyproject.toml index 571b4aad..0e050577 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] # PEP 518 - minimum build system requirements -requires = ["setuptools", "wheel", "Cython>=0.29", "packaging", "pip", "numpy", "mpi4py"] +requires = ["setuptools", "wheel", "Cython>=0.29", "packaging", "pip>=19.0.0", "numpy", "mpi4py"] diff --git a/setup.py b/setup.py index 14aa80fa..18a48c48 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,45 @@ import os +import sys import warnings -from packaging import version import versioneer -import pip + +uses_pip = "pip" in __file__ + +# check whether pip is used for installation. If pip is not used, dependencies defined in pyproject.toml might be +# missing. +if not uses_pip: + warnings.warn("It looks like you are not using pip for installation. Installing the package via 'pip3 install " + "--user .' is recommended. You can still use 'python3 setup.py install --user', if you want and if " + "the bindings work correctly, you do not have to worry. However, if you face problems during " + "installation or running pyprecice, this means that you have to make sure that all dependencies are " + "installed correctly and repeat the installation of pyprecice. Refer to pyproject.toml for a list " + "of dependencies.") + +if uses_pip: + # If installed with pip we need to check its version + try: + import pip + except ModuleNotFoundError: + raise Exception("It looks like you are trying to use pip for installation of the package, but pip is not " + "installed on your system (or cannot be found). This can lead to problems with missing " + "dependencies. Please make sure that pip is discoverable. Try python3 -c 'import pip'. " + "Alternatively, you can also run python3 setup.py install --user.") + try: + from packaging import version + except ModuleNotFoundError: + warnings.warn("It looks like you are trying to use pip for installation of the package. Please install, " + "the module packaging by running 'pip3 install --user packaging', since it is needed to perform " + "additional security checks. You can continue installation. However, if you face problems when " + "installing or running pyprecice, it might be a good idea to install packaging to enable " + "additional checks.") + if "pip" in sys.modules and "packaging" in sys.modules: + if version.parse(pip.__version__) < version.parse("19.0"): + # version 19.0 is required, since we are using pyproject.toml for definition of build-time depdendencies. + # See https://pip.pypa.io/en/stable/news/#id209 + raise Exception("You are using pip version {}. However, pip version >= 19.0 is required. Please upgrade " + "your pip installation via 'pip3 install --upgrade pip'. You might have to add the --user" + " flag.".format(pip.__version__)) + from setuptools import setup from setuptools import Command from setuptools.command.test import test @@ -12,22 +49,6 @@ from Cython.Build import cythonize import numpy -if version.parse(pip.__version__) < version.parse("19.0"): - # version 19.0 is required, since we are using pyproject.toml for definition of build-time depdendencies. See - # https://pip.pypa.io/en/stable/news/#id209 - warnings.warn( - "You are using pip version {}. However, pip version > 19.0 is recommended. You can continue with the " - "installation, but installation problems can occour. Please refer to " - "https://github.com/precice/python-bindings#build-time-dependencies-cython-numpy-defined-in-pyprojecttoml-are" - "-not-installed-automatically for help.".format( - pip.__version__)) - -if version.parse(pip.__version__) < version.parse("10.0.1"): - warnings.warn( - "You are using pip version {}. However, pip version > 10.0.1 is required. If you continue with installation " - "it is likely that you will face an error. See " - "https://github.com/precice/python-bindings#version-of-pip3-is-too-old".format( - pip.__version__)) # name of Interfacing API APPNAME = "pyprecice"