From da7a493bc85c53552fc5a72b21604aff412e5a8b Mon Sep 17 00:00:00 2001 From: Zach Burnett Date: Mon, 24 Apr 2023 15:58:10 -0400 Subject: [PATCH] move build configuration from `setup.cfg` to `pyproject.toml` --- .flake8 | 5 +++ MANIFEST.in | 1 - docs/conf.py | 14 ++++--- pyproject.toml | 110 +++++++++++++++++++++++++++++++++++++++++++++++-- setup.cfg | 78 ----------------------------------- setup.py | 37 ----------------- tox.ini | 4 +- 7 files changed, 123 insertions(+), 126 deletions(-) create mode 100644 .flake8 delete mode 100644 setup.cfg delete mode 100755 setup.py diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..fea065b --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +# flake8 does not support pyproject.toml (https://github.com/PyCQA/flake8/issues/234) + +[flake8] +max-line-length = 79 + diff --git a/MANIFEST.in b/MANIFEST.in index f983433..18a566e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,7 +3,6 @@ include CHANGES.rst include LICENSE.rst include CITATION -include setup.cfg include pyproject.toml recursive-include packagename *.pyx *.c *.pxd diff --git a/docs/conf.py b/docs/conf.py index 90124fc..e0f62a7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -19,15 +19,19 @@ import stsci_rtd_theme +if sys.version_info < (3, 11): + import tomli as tomllib +else: + import tomllib + def setup(app): app.add_css_file("stsci.css") # -- General configuration ------------------------------------------------ -conf = ConfigParser() -conf.read([os.path.join(os.path.dirname(__file__), '..', 'setup.cfg')]) -setup_cfg = dict(conf.items('metadata')) +with open(Path(__file__).parent.parent / "pyproject.toml", "rb") as configuration_file: +metadata = conf['metadata'] # Configuration for intersphinx: refer to the Python standard library. # Uncomment if you cross-ref to API doc from other packages. @@ -68,8 +72,8 @@ def setup(app): master_doc = 'index' # General information about the project -project = setup_cfg['name'] -author = setup_cfg['author'] +project = metadata['project']['name'] +author = metadata['project']['authors'][0]['name'] year = datetime.datetime.now().year copyright = f'{year}, {author}' diff --git a/pyproject.toml b/pyproject.toml index b222b6b..9136edf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,109 @@ +[project] +name = "packagename" +description = "My pretty cool package" +requires-python = ">=3.7" +authors = [ + { name = "STScI", email = "help@stsci.edu" }, +] +keywords = [ + "astronomy", + "astrophysics", +] +classifiers = [ + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: Implementation :: CPython", + "Topic :: Scientific/Engineering :: Astronomy", + "Topic :: Scientific/Engineering :: Physics", +] +dependencies = [ + "numpy>=1.17", + "astropy>=4", +] +dynamic = [ + "version", +] + +[project.readme] +file = "README.rst" +content-type = "text/x-rst" + +[project.license] +file = "LICENSE.rst" +content-type = "text/plain" + +[project.urls] +Homepage = "https://github.com/spacetelescope/stsci-package-template" + +[project.optional-dependencies] +test = [ + "pytest-astropy-header", + "pytest-doctestplus", +] +docs = [ + "sphinx-automodapi", + "stsci_rtd_theme", +] + +[project.scripts] +stsci_package_template_example = "packagename.example_mod:main" + [build-system] -requires = ["setuptools", - "setuptools_scm", - "wheel"] +requires = [ + "setuptools>=61.2", + "setuptools_scm[toml]>=3.4", + "wheel", +] build-backend = "setuptools.build_meta" + +[tool.setuptools] +zip-safe = false +include-package-data = true + +[tool.setuptools.packages.find] +namespaces = false + +[tool.setuptools.package-data] +packagename = [ + "data/*", +] + +[tool.setuptools_scm] +write_to = "packagename/version.py" + +[tool.pytest.ini_options] +minversion = "5.0" +norecursedirs = [ + "build", + "docs/_build", +] +astropy_header = true +doctest_plus = "enabled" + +[tool.coverage.run] +source = [ + "packagename", +] +omit = [ + "packagename/tests/*", + "packagename/version*", + "*/packagename/tests/*", + "*/packagename/version*", +] + +[tool.coverage.report] +exclude_lines = [ + "pragma: no cover", + "except ImportError", + "raise AssertionError", + "raise NotImplementedError", + "def main\\(.*\\):", + "pragma: py{ignore_python_version}", + "def _ipython_key_completions_", +] + +[tool.build_sphinx] +edit-on-github = false +github-project = "spacetelescope/stsci-package-template" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 02d1873..0000000 --- a/setup.cfg +++ /dev/null @@ -1,78 +0,0 @@ -[metadata] -name = packagename -description = My pretty cool package -long_description = A package which contains stuff that do things -long_description_content_type = text/plain -keywords = astronomy, astrophysics -author = STScI -author_email = help@stsci.edu -license = BSD -license_file = LICENSE.rst -url = https://github.com/spacetelescope/stsci-package-template -edit_on_github = False -github_project = spacetelescope/stsci-package-template -classifiers = - Intended Audience :: Science/Research - License :: OSI Approved :: BSD License - Operating System :: OS Independent - Programming Language :: Python :: 3 - Programming Language :: Python :: Implementation :: CPython - Topic :: Scientific/Engineering :: Astronomy - Topic :: Scientific/Engineering :: Physics - -[options] -packages = find: -zip_safe = False -setup_requires = - setuptools_scm -install_requires = - numpy>=1.17 - astropy>=4 -python_requires = >=3.7 - -[options.extras_require] -test = - pytest-astropy-header - pytest-doctestplus -docs = - sphinx-automodapi - stsci_rtd_theme - -[options.package_data] -packagename = data/* - -[entry_points] -stsci-package-template-example = packagename.example_mod:main - -[tool:pytest] -minversion = 5.0 -norecursedirs = build docs/_build -astropy_header = True -doctest_plus = enabled - -[flake8] -max-line-length = 79 - -[coverage:run] -source = packagename -omit = - packagename/tests/* - packagename/version* - */packagename/tests/* - */packagename/version* - -[coverage:report] -exclude_lines = - # Have to re-enable the standard pragma - pragma: no cover - # Don't complain about packages we have installed - except ImportError - # Don't complain if tests don't hit assertions - raise AssertionError - raise NotImplementedError - # Don't complain about script hooks - def main\(.*\): - # Ignore branches that don't pertain to this version of Python - pragma: py{ignore_python_version} - # Don't complain about IPython completion helper - def _ipython_key_completions_ diff --git a/setup.py b/setup.py deleted file mode 100755 index 306e696..0000000 --- a/setup.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python -# Licensed under a 3-clause BSD style license - see LICENSE.rst - -import sys -from setuptools import setup - -TEST_HELP = """ -Note: running tests is no longer done using 'python setup.py test'. Instead -you will need to run: - - pip install -e . - pytest - -""" - -if 'test' in sys.argv: - print(TEST_HELP) - sys.exit(1) - -DOCS_HELP = """ -Note: building the documentation is no longer done using -'python setup.py build_docs'. Instead you will need to run: - - cd docs - make html - -""" - -if 'build_docs' in sys.argv or 'build_sphinx' in sys.argv: - print(DOCS_HELP) - sys.exit(1) - -# Note that requires and provides should not be included in the call to -# ``setup``, since these are now deprecated. See this link for more details: -# https://groups.google.com/forum/#!topic/astropy-dev/urYO8ckB2uM - -setup(use_scm_version={'write_to': 'packagename/version.py'}) diff --git a/tox.ini b/tox.ini index 108b9d2..2ed3901 100644 --- a/tox.ini +++ b/tox.ini @@ -46,14 +46,14 @@ deps = devdeps: git+https://github.com/astropy/astropy.git#egg=astropy -# The following indicates which extras_require from setup.cfg will be installed +# The following indicates which `optional-dependencies` from `pyproject.toml` will be installed extras = test commands = pip freeze !cov: pytest --pyargs packagename {toxinidir}/docs {posargs} - cov: pytest --pyargs packagename {toxinidir}/docs --cov packagename --cov-config={toxinidir}/setup.cfg {posargs} + cov: pytest --pyargs packagename {toxinidir}/docs --cov packagename --cov-config={toxinidir}/pyproject.toml {posargs} cov: coverage xml -o {toxinidir}/coverage.xml [testenv:linkcheck]