From 454e838dfd1de1235547be86256660c93a6cd3ee Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Sat, 1 Jul 2023 23:57:52 -0700 Subject: [PATCH 1/2] Use pyproject.toml --- .coveragerc | 1 - .pre-commit-config.yaml | 2 +- pyproject.toml | 78 ++++++++++++++++++++++++++++++++++++++ setup.cfg | 9 ----- setup.py | 83 ----------------------------------------- 5 files changed, 79 insertions(+), 94 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.coveragerc b/.coveragerc index 251f5155..84a30f78 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,6 +2,5 @@ branch = True source = numpydoc omit = - */setup.py numpydoc/tests/* numpydoc/templates/* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dd3fbc93..c852963c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: rev: v2.7.1 hooks: - id: prettier - files: \.(html|md|yml|yaml) + files: \.(html|md|toml|yml|yaml) args: [--prose-wrap=preserve] - repo: https://github.com/adamchainz/blacken-docs diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..ecfe7f26 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,78 @@ +[build-system] +build-backend = 'setuptools.build_meta' +requires = ['setuptools>=61.2'] + +[project] +name = 'numpydoc' +description = 'Sphinx extension to support docstrings in Numpy format' +readme = 'README.rst' +requires-python = '>=3.8' +dynamic = ['version'] +keywords = [ + 'sphinx', + 'numpy', +] +classifiers = [ + 'Development Status :: 4 - Beta', + 'Environment :: Plugins', + 'License :: OSI Approved :: BSD License', + 'Topic :: Documentation', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', +] +dependencies = [ + 'sphinx>=5', + 'Jinja2>=2.10', + 'tabulate>=0.8.10', + "tomli>=1.1.0;python_version<'3.11'", +] + +[[project.authors]] +name = 'Pauli Virtanen and others' +email = 'pav@iki.fi' + +[project.license] +file = 'LICENSE.txt' + +[project.urls] +Homepage = 'https://numpydoc.readthedocs.io' + +[project.optional-dependencies] +doc = [ + 'numpy>=1.22', + 'matplotlib>=3.5', + 'pydata-sphinx-theme>=0.13', + 'sphinx>=6', +] +test = [ + 'pytest', + 'pytest-cov', + 'matplotlib', +] + +[project.scripts] +validate-docstrings = 'numpydoc.hooks.validate_docstrings:main' +[tool.setuptools] +include-package-data = false +packages = [ + 'numpydoc', + 'numpydoc.hooks', +] + +[tool.setuptools.package-data] +numpydoc = [ + 'tests/test_*.py', + 'tests/tinybuild/Makefile', + 'tests/tinybuild/index.rst', + 'tests/tinybuild/*.py', + 'templates/*.rst', +] +[tool.pytest.ini_options] +addopts = ''' +--showlocals --doctest-modules -ra --cov-report= --cov=numpydoc +--junit-xml=junit-results.xml --ignore=doc/''' +junit_family = 'xunit2' diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 8ce12840..00000000 --- a/setup.cfg +++ /dev/null @@ -1,9 +0,0 @@ -[tool:pytest] -addopts = - --showlocals --doctest-modules -ra --cov-report= --cov=numpydoc - --junit-xml=junit-results.xml --ignore=doc/ -junit_family = xunit2 - -[options.entry_points] -console_scripts = - validate-docstrings = numpydoc.hooks.validate_docstrings:main diff --git a/setup.py b/setup.py deleted file mode 100644 index e7bec9fb..00000000 --- a/setup.py +++ /dev/null @@ -1,83 +0,0 @@ -import sys -import os - -from setuptools import setup - -# Adapted from MNE-Python (BSD) -version = None -with open(os.path.join("numpydoc", "_version.py")) as fid: - for line in (line.strip() for line in fid): - if line.startswith("__version__"): - version = line.split("=")[1].strip().strip('"') - break -if version is None: - raise RuntimeError("Could not determine version") - -if sys.version_info < (3, 8): - raise RuntimeError("Python version >= 3.8 required.") - - -def read(fname): - """Utility function to get README.rst into long_description. - - ``long_description`` is what ends up on the PyPI front page. - """ - with open(os.path.join(os.path.dirname(__file__), fname)) as f: - contents = f.read() - - return contents - - -setup( - name="numpydoc", - packages=["numpydoc", "numpydoc.hooks"], - version=version, - description="Sphinx extension to support docstrings in Numpy format", - long_description=read("README.rst"), - # classifiers from http://pypi.python.org/pypi?%3Aaction=list_classifiers - classifiers=[ - "Development Status :: 4 - Beta", - "Environment :: Plugins", - "License :: OSI Approved :: BSD License", - "Topic :: Documentation", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - ], - keywords="sphinx numpy", - author="Pauli Virtanen and others", - author_email="pav@iki.fi", - url="https://numpydoc.readthedocs.io", - license="BSD", - install_requires=[ - "sphinx>=5", - "Jinja2>=2.10", - "tabulate>=0.8.10", - "tomli>=1.1.0;python_version<'3.11'", - ], - python_requires=">=3.8", - extras_require={ - "testing": [ - req - for req in read("requirements/test.txt").split("\n") - if not req.startswith("#") - ], - "doc": [ - req - for req in read("requirements/doc.txt").split("\n") - if not req.startswith("#") - ], - }, - package_data={ - "numpydoc": [ - "tests/test_*.py", - "tests/tinybuild/Makefile", - "tests/tinybuild/index.rst", - "tests/tinybuild/*.py", - "templates/*.rst", - ] - }, -) From 47277ec67bb810607e4b2d693eecdf8c6e021efe Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Sun, 2 Jul 2023 07:36:44 -0700 Subject: [PATCH 2/2] Update pyproject.toml with requirements --- .github/workflows/lint.yml | 21 ++++++++-- .pre-commit-config.yaml | 8 ++++ pyproject.toml | 12 +++++- requirements/developer.txt | 1 + tools/generate_pyproject.toml.py | 52 +++++++++++++++++++++++++ tools/pyproject.toml.in | 67 ++++++++++++++++++++++++++++++++ 6 files changed, 157 insertions(+), 4 deletions(-) create mode 100755 tools/generate_pyproject.toml.py create mode 100644 tools/pyproject.toml.in diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 78d425f3..be57ed97 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,9 +4,24 @@ on: [push, pull_request] jobs: pre-commit: - name: Linting runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.11"] + steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - - uses: pre-commit/action@v3.0.0 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install packages + run: | + pip install --upgrade pip + pip install -r requirements/developer.txt + pip list + + - name: Lint + run: pre-commit run --all-files --show-diff-on-failure --color always diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c852963c..bd9d7e4d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,3 +38,11 @@ repos: hooks: - id: pyupgrade args: [--py38-plus] + + - repo: local + hooks: + - id: pyproject.toml + name: pyproject.toml + language: system + entry: python tools/generate_pyproject.toml.py + files: "pyproject.toml|requirements/.*\\.txt|tools/.*pyproject.*" diff --git a/pyproject.toml b/pyproject.toml index ecfe7f26..7c903670 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,13 @@ +################################################################################ +# DO NOT EDIT +# AUTOGENERATED BY +# +# $ python tools/generate_pyproject.toml.py +# +# EDIT tools/pyproject.toml.in AND RUN THAT SCRIPT. +# +################################################################################ + [build-system] build-backend = 'setuptools.build_meta' requires = ['setuptools>=61.2'] @@ -74,5 +84,5 @@ numpydoc = [ [tool.pytest.ini_options] addopts = ''' --showlocals --doctest-modules -ra --cov-report= --cov=numpydoc ---junit-xml=junit-results.xml --ignore=doc/''' +--junit-xml=junit-results.xml --ignore=doc/ --ignore=tools/''' junit_family = 'xunit2' diff --git a/requirements/developer.txt b/requirements/developer.txt index ff8f63cc..832c8cbe 100644 --- a/requirements/developer.txt +++ b/requirements/developer.txt @@ -1 +1,2 @@ pre-commit>=3.3 +rtoml diff --git a/tools/generate_pyproject.toml.py b/tools/generate_pyproject.toml.py new file mode 100755 index 00000000..bc7d9671 --- /dev/null +++ b/tools/generate_pyproject.toml.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +import os +import sys + +try: + import rtoml as toml +except ImportError: + print("Please install `rtoml` first: `pip install rtoml`") + sys.exit(1) + + +if not os.path.isfile("pyproject.toml"): + print("Please run this script from the skimage repository root:") + print(" python tools/generate_pyproject.toml.py") + sys.exit(1) + + +def parse_requirements_file(filename): + with open(filename) as fid: + requires = [l.strip() for l in fid.readlines() if not l.startswith("#")] + requires = [l for l in requires if l] + + return requires + + +with open("tools/pyproject.toml.in") as f: + pyproject = toml.load(f) + +# pyproject['project']['dependencies'] = \ +# parse_requirements_file("requirements/default.txt") + +pyproject["project"]["optional-dependencies"] = { + dep: parse_requirements_file(f"requirements/{dep}.txt") for dep in ["doc", "test"] +} + +banner = f"""\ +{"#" * 80} +# DO NOT EDIT +# AUTOGENERATED BY +# +# $ python tools/generate_pyproject.toml.py +# +# EDIT tools/pyproject.toml.in AND RUN THAT SCRIPT. +# +{"#" * 80} + +""" + +with open("pyproject.toml", "w") as f: + f.write(banner) + toml.dump(pyproject, f, pretty=True) diff --git a/tools/pyproject.toml.in b/tools/pyproject.toml.in new file mode 100644 index 00000000..7b43e025 --- /dev/null +++ b/tools/pyproject.toml.in @@ -0,0 +1,67 @@ +[build-system] +requires = [ + "setuptools>=61.2", +] +build-backend = "setuptools.build_meta" + +[project] +name = "numpydoc" +description = "Sphinx extension to support docstrings in Numpy format" +license = {file = "LICENSE.txt"} +dynamic = ['version'] +keywords = [ + "sphinx", + "numpy", +] +readme = "README.rst" +classifiers = [ + "Development Status :: 4 - Beta", + "Environment :: Plugins", + "License :: OSI Approved :: BSD License", + "Topic :: Documentation", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", +] +requires-python = ">=3.8" +dependencies = [ + "sphinx>=5", + "Jinja2>=2.10", + "tabulate>=0.8.10", + "tomli>=1.1.0;python_version<'3.11'", +] + +[[project.authors]] +name = "Pauli Virtanen and others" +email = "pav@iki.fi" + +[project.urls] +Homepage = "https://numpydoc.readthedocs.io" + +[project.optional-dependencies] + +[project.scripts] +validate-docstrings = "numpydoc.hooks.validate_docstrings:main" + +[tool.setuptools] +packages = [ + "numpydoc", + "numpydoc.hooks", +] +include-package-data = false + +[tool.setuptools.package-data] +numpydoc = [ + "tests/test_*.py", + "tests/tinybuild/Makefile", + "tests/tinybuild/index.rst", + "tests/tinybuild/*.py", + "templates/*.rst", +] + +[tool.pytest.ini_options] +addopts = "--showlocals --doctest-modules -ra --cov-report= --cov=numpydoc\n--junit-xml=junit-results.xml --ignore=doc/ --ignore=tools/" +junit_family = "xunit2"