From f4fac971c87643943eb3abb73c32dc7cc205535d Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 19 Aug 2022 23:53:34 +0800 Subject: [PATCH] Migrate project metadata from setup.py to pyproject.toml following PEP621 (#1848) Delete setup.py and move all project metadata to pyproject.toml as per https://peps.python.org/pep-0621. * Migrate project metadata from setup.py to pyproject.toml following PEP621 * Add docstrings to setup.py * Use the new email address for pygmt team * Update the link for development mode * Set include-package-data to include baseline and data files * Remove setup.py completely. Requires setuptools>=64.0.0 * Fix the minimum required numpy version to 1.20 * Add package data * Update the command to check README syntax * Run tests in editable mode * Multi-line dependencies Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- .github/workflows/ci_tests.yaml | 4 +- .github/workflows/ci_tests_dev.yaml | 4 +- Makefile | 8 ++-- doc/maintenance.md | 4 +- pyproject.toml | 49 +++++++++++++++++++++++- setup.py | 59 ----------------------------- 6 files changed, 56 insertions(+), 72 deletions(-) delete mode 100644 setup.py diff --git a/.github/workflows/ci_tests.yaml b/.github/workflows/ci_tests.yaml index 523af17f832..498360a71ba 100644 --- a/.github/workflows/ci_tests.yaml +++ b/.github/workflows/ci_tests.yaml @@ -126,9 +126,7 @@ jobs: # Install the package that we want to test - name: Install the package - run: | - python -m build --sdist - pip install dist/* + run: make install # Run the regular tests - name: Run tests diff --git a/.github/workflows/ci_tests_dev.yaml b/.github/workflows/ci_tests_dev.yaml index 2e236e91611..12e339b4383 100644 --- a/.github/workflows/ci_tests_dev.yaml +++ b/.github/workflows/ci_tests_dev.yaml @@ -150,9 +150,7 @@ jobs: # Install the package that we want to test - name: Install the package - run: | - python -m build --sdist - pip install dist/* + run: make install - name: Add GMT's bin to PATH (Linux/macOS) run: echo ${GITHUB_WORKSPACE}/gmt-install-dir/bin >> $GITHUB_PATH diff --git a/Makefile b/Makefile index 0ce1377ec6b..0b1e28ef1ab 100644 --- a/Makefile +++ b/Makefile @@ -4,12 +4,12 @@ TESTDIR=tmp-test-dir-with-unique-name PYTEST_COV_ARGS=--cov=$(PROJECT) --cov-config=../pyproject.toml \ --cov-report=term-missing --cov-report=xml --cov-report=html \ --pyargs ${PYTEST_EXTRA} -BLACK_FILES=$(PROJECT) setup.py doc/conf.py examples +BLACK_FILES=$(PROJECT) doc/conf.py examples BLACKDOC_OPTIONS=--line-length 79 -DOCFORMATTER_FILES=$(PROJECT) setup.py doc/conf.py examples +DOCFORMATTER_FILES=$(PROJECT) doc/conf.py examples DOCFORMATTER_OPTIONS=--recursive --pre-summary-newline --make-summary-multi-line --wrap-summaries 79 --wrap-descriptions 79 -FLAKEHEAVEN_FILES=$(PROJECT) setup.py doc/conf.py examples -LINT_FILES=$(PROJECT) setup.py doc/conf.py +FLAKEHEAVEN_FILES=$(PROJECT) doc/conf.py examples +LINT_FILES=$(PROJECT) doc/conf.py help: @echo "Commands:" diff --git a/doc/maintenance.md b/doc/maintenance.md index f4202a16b96..a78784e5bdf 100644 --- a/doc/maintenance.md +++ b/doc/maintenance.md @@ -167,7 +167,7 @@ alongside the rest of the Scientific Python ecosystem, and therefore supports: * All minor versions of NumPy released in the 24 months prior to the project, and at minimum the last three minor versions. -In `setup.py`, the `python_requires` variable should be set to the minimum +In `pyproject.toml`, the `requires-python` key should be set to the minimum supported version of Python. Minimum Python and NumPy version support should be adjusted upward on every major and minor release, but never on a patch release. @@ -277,7 +277,7 @@ So slightly broken RST can cause the PyPI page to not render the correct content using the `rst2html.py` script that comes with docutils: ``` -python setup.py --long-description | rst2html.py --no-raw > index.html +rst2html.py --no-raw README.rst > index.html ``` Open `index.html` and check for any flaws or error messages. diff --git a/pyproject.toml b/pyproject.toml index a74b65d7345..66b60280c6d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,54 @@ [build-system] -requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"] +requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2"] build-backend = "setuptools.build_meta" +[project] +name = "pygmt" +description = "A Python interface for the Generic Mapping Tools" +readme = "README.rst" +requires-python = ">=3.8" +license = {text = "BSD License"} +authors = [{name = "The PyGMT Developers", email = "pygmt.team@gmail.com"}] +maintainers = [{name = "The PyGMT Developers", email = "pygmt.team@gmail.com"}] +keywords = [] +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Science/Research", + "Intended Audience :: Developers", + "Intended Audience :: Education", + "Topic :: Scientific/Engineering", + "Topic :: Software Development :: Libraries", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "License :: OSI Approved :: BSD License", +] +dependencies = [ + "numpy>=1.20", + "pandas", + "xarray", + "netCDF4", + "packaging" +] +dynamic = ["version"] + +[project.urls] +homepage = "https://www.pygmt.org" +documentation = "https://www.pygmt.org" +repository = "https://github.com/GenericMappingTools/pygmt" +changelog = "https://www.pygmt.org/latest/changes.html" + +[tool.setuptools] +platforms = ["Any"] +include-package-data = true + +[tool.setuptools.packages.find] +include = ["pygmt*"] +exclude = ["doc"] + +[tool.setuptools.package-data] +tests = ["data/*", "baseline/*"] + [tool.setuptools_scm] local_scheme = "node-and-date" fallback_version = "999.999.999+unknown" diff --git a/setup.py b/setup.py deleted file mode 100644 index de7d307869d..00000000000 --- a/setup.py +++ /dev/null @@ -1,59 +0,0 @@ -""" -Build and install the project. -""" -from setuptools import find_packages, setup - -NAME = "pygmt" -FULLNAME = "PyGMT" -AUTHOR = "The PyGMT Developers" -AUTHOR_EMAIL = "leouieda@gmail.com" -MAINTAINER = AUTHOR -MAINTAINER_EMAIL = AUTHOR_EMAIL -LICENSE = "BSD License" -URL = "https://github.com/GenericMappingTools/pygmt" -DESCRIPTION = "A Python interface for the Generic Mapping Tools" -KEYWORDS = "" -with open("README.rst", "r", encoding="utf8") as f: - LONG_DESCRIPTION = "".join(f.readlines()) - -PACKAGES = find_packages(exclude=["doc"]) -SCRIPTS = [] -PACKAGE_DATA = {"pygmt.tests": ["data/*", "baseline/*"]} - -CLASSIFIERS = [ - "Development Status :: 4 - Beta", - "Intended Audience :: Science/Research", - "Intended Audience :: Developers", - "Intended Audience :: Education", - "Topic :: Scientific/Engineering", - "Topic :: Software Development :: Libraries", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - f"License :: OSI Approved :: {LICENSE}", -] -PLATFORMS = "Any" -PYTHON_REQUIRES = ">=3.8" -INSTALL_REQUIRES = ["numpy>=1.20", "pandas", "xarray", "netCDF4", "packaging"] - -if __name__ == "__main__": - setup( - name=NAME, - fullname=FULLNAME, - description=DESCRIPTION, - long_description=LONG_DESCRIPTION, - author=AUTHOR, - author_email=AUTHOR_EMAIL, - maintainer=MAINTAINER, - maintainer_email=MAINTAINER_EMAIL, - license=LICENSE, - url=URL, - platforms=PLATFORMS, - scripts=SCRIPTS, - packages=PACKAGES, - package_data=PACKAGE_DATA, - classifiers=CLASSIFIERS, - keywords=KEYWORDS, - python_requires=PYTHON_REQUIRES, - install_requires=INSTALL_REQUIRES, - )