From 5a1fbba9fea31a5aee881cb37067ee10c8f6641d Mon Sep 17 00:00:00 2001 From: Sebastian Heimann Date: Mon, 8 May 2023 09:47:18 +0200 Subject: [PATCH] installation: improve compatibility with legacy systems - downgrade requirements on pyqt, scipy, pyqtgraph, setuptools, setuptools_scm and gdal - add a fallback to setup.py so that it is possible to install when setuptools lacks support for pep621 - update installation docs --- docs/source/installation.rst | 34 ++++++++++++-------- pyproject.toml | 12 +++---- setup.py | 61 +++++++++++++++++++++++++++++++++++- 3 files changed, 87 insertions(+), 20 deletions(-) diff --git a/docs/source/installation.rst b/docs/source/installation.rst index 515169e..4964cbb 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -3,35 +3,43 @@ Installation Kite is written for `Python 3 `_, the installation has been tested on Debian based distributions (e.g. Ubuntu and Mint), MacOSX, and `Anaconda `_. -Debian / Ubuntu ---------------- +System-wide installation on Debian / Ubuntu +------------------------------------------- As a mandatory prerequisite you have to install Pyrocko, visit `Pyrocko installation instructions `_ for details. .. code-block :: sh :caption: Installation from source and ``apt-get`` - sudo apt-get install python3-dev python3-pyqt5 python3-pyqt5 python3-pyqt5.qtopengl python3-scipy python3-numpy python3-pyqtgraph + # satisfy Kite's requirements with system packages + sudo apt-get install python3-dev python3-pyqt5 python3-pyqt5 python3-pyqt5.qtopengl python3-scipy python3-numpy python3-pyqtgraph python3-geojson python3-setuptools python3-setuptools-scm - git clone https://github.com/Turbo87/utm - cd utm - sudo python3 setup.py install + # install the utm package with pip (no system package available) + sudo pip3 install utm + # get Kite's source code with git git clone https://github.com/pyrocko/kite cd kite - sudo python3 setup.py install + # compile and install with pip, but disable automatic dependency resolution (--no-deps) + sudo pip3 install . --no-build-isolation --no-deps -PIP ---- -An installation through ``pip`` requires the same prerequisites as above: +Installation with ``pip`` into virtual environment ``venv`` +----------------------------------------------------------- .. code-block :: sh - :caption: Installation through pip + :caption: Installation into venv - sudo pip3 install utm - sudo pip3 install git+https://github.com/pyrocko/kite + # create and activate venv + python3 -m venv venv + source venv/bin/activate + + # get Kite's source code with git + git clone https://github.com/pyrocko/kite + cd kite + # install prerequisites with pip, compile and install Kite + pip install . MacOS (Sierra, MacPorts) diff --git a/pyproject.toml b/pyproject.toml index f33fac1..d64cb22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,9 @@ [build-system] requires = [ "wheel", - "setuptools >= 61.0.0", + "setuptools >= 52.0.0", "oldest-supported-numpy", - "setuptools_scm[toml]>=6.2", + "setuptools_scm[toml]>=5.0", ] build-backend = "setuptools.build_meta" @@ -34,9 +34,9 @@ classifiers = [ ] dependencies = [ "numpy>=1.17.3", - "scipy>=1.8.0", - "PyQt5>=5.15.7", - "pyqtgraph==0.12.4", + "scipy>=1.6.0", + "PyQt5>=5.15.0", + "pyqtgraph==0.11.0", "pyrocko>=2022.06.10", "utm>=0.7.0", "geojson>=2.5.0", @@ -48,7 +48,7 @@ GitHub = "https://github.com/pyrocko/kite" Issues = "https://github.com/pyrocko/kite/issues" [project.optional-dependencies] -gdal = ["gdal>=3.5.0"] +gdal = ["gdal>=3.2.0"] development = ["flake8", "black", "pre-commit"] tests = ["pytest"] diff --git a/setup.py b/setup.py index 05a754a..2c9e218 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,16 @@ #!/usr/bin/env python3 import os import platform +import sys import tempfile from distutils.sysconfig import get_python_inc from os.path import join as pjoin +from pkg_resources import parse_version from setuptools import Extension, setup +from setuptools import __version__ as setuptools_version + +have_pep621_support = parse_version(setuptools_version) >= parse_version("61.0.0") try: import numpy @@ -117,6 +122,59 @@ def _have_openmp(): omp_lib = [] +if not have_pep621_support: + try: + import toml + except ImportError: + sys.exit( + """Your setuptools version is too old to support PEP621-compliant + installs. You may either update setuptools or, if this is not + possible, install the "toml" package (python3-toml package on + deb-based systems) to enable a fallback mechanism.""" + ) + + tomldata = toml.load( + open(os.path.join(os.path.dirname(__file__), "pyproject.toml")) + ) + metadata = dict( + use_scm_version=True, + package_data={"kite": ["spool/res/*", "talpa/res/*"]}, + ext_package="kite", + ) + metadata["setup_requires"] = tomldata["build-system"]["requires"] + metadata["packages"] = tomldata["tool"]["setuptools"]["packages"] + + for k in ["classifiers", "description", "name", "keywords"]: + metadata[k] = tomldata["project"][k] + + metadata["license"] = tomldata["project"]["license"]["text"] + + metadata["python_requires"] = tomldata["project"]["requires-python"] + first_author = list(tomldata["project"]["authors"])[0] + metadata["author"] = ", ".join( + author["name"] for author in tomldata["project"]["authors"] + ) + metadata["author_email"] = first_author["email"] + + metadata["extras_require"] = {} + for k_opt in tomldata["project"]["optional-dependencies"]: + metadata["extras_require"][k_opt] = tomldata["project"][ + "optional-dependencies" + ][k_opt] + + metadata["install_requires"] = tomldata["project"]["dependencies"] + metadata["entry_points"] = { + "console_scripts": [ + "%s = %s" % (k, v) for (k, v) in tomldata["project"]["scripts"].items() + ], + "gui_scripts": [ + "%s = %s" % (k, v) for (k, v) in tomldata["project"]["gui-scripts"].items() + ], + } +else: + metadata = {} + + setup( ext_modules=[ Extension( @@ -135,5 +193,6 @@ def _have_openmp(): extra_link_args=omp_lib, language="c", ), - ] + ], + **metadata, )