Skip to content

Commit

Permalink
move build configuration from setup.cfg to pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyburnett committed Jan 8, 2024
1 parent 60469c6 commit b4cca5b
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 126 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# flake8 does not support pyproject.toml (https://github.com/PyCQA/flake8/issues/234)

[flake8]
max-line-length = 79

1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ include CHANGES.rst
include LICENSE.rst
include CITATION

include setup.cfg
include pyproject.toml

recursive-include packagename *.pyx *.c *.pxd
Expand Down
14 changes: 9 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}'

Expand Down
110 changes: 107 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,109 @@
[project]
name = "packagename"
description = "My pretty cool package"
requires-python = ">=3.7"
authors = [
{ name = "STScI", email = "[email protected]" },
]
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"
78 changes: 0 additions & 78 deletions setup.cfg

This file was deleted.

37 changes: 0 additions & 37 deletions setup.py

This file was deleted.

4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ deps =
devdeps: numpy>=0.0.dev0
devdeps: astropy>=0.0.dev0

# 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]
Expand Down

0 comments on commit b4cca5b

Please sign in to comment.