From ab5d4244c8c5bad5478d992dee92ba111c5897c0 Mon Sep 17 00:00:00 2001 From: "Marten H. van Kerkwijk" Date: Thu, 19 Sep 2024 17:18:35 -0400 Subject: [PATCH] Move to using pyproject.toml --- .gitignore | 2 +- baseband/_astropy_init.py | 2 +- baseband/data/__init__.py | 8 ++- docs/conf.py | 78 ++++++++++-------------- pyproject.toml | 119 +++++++++++++++++++++++++++++++++++-- setup.cfg | 121 -------------------------------------- setup.py | 75 +---------------------- 7 files changed, 154 insertions(+), 251 deletions(-) delete mode 100644 setup.cfg diff --git a/.gitignore b/.gitignore index 7c60f757..cbae66e0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ __pycache__ *.c # Other generated files -*/version.py +*/_version.py */cython_version.py htmlcov .coverage diff --git a/baseband/_astropy_init.py b/baseband/_astropy_init.py index bd453245..60bb6e10 100644 --- a/baseband/_astropy_init.py +++ b/baseband/_astropy_init.py @@ -4,7 +4,7 @@ __all__ = ['__version__', 'test'] try: - from .version import version as __version__ + from ._version import version as __version__ except ImportError: __version__ = '' diff --git a/baseband/data/__init__.py b/baseband/data/__init__.py index 0b4bd790..de3692f0 100644 --- a/baseband/data/__init__.py +++ b/baseband/data/__init__.py @@ -123,9 +123,11 @@ def _full_path(name, dirname=_path.dirname(_path.abspath(__file__))): SAMPLE_VEGAS = _full_path('sample_vegas.raw') r"""VEGAS sample, npol=2, obsnchan=32. -Created from a Green Bank Telescope observation of TOI 1898 -dd if=vegas_59332_80137_Jade_1898_1_0001.0000.raw \ - of=sample_vegas.raw bs=80 count=178 +Created from a Green Bank Telescope observation of TOI 1898:: + + dd if=vegas_59332_80137_Jade_1898_1_0001.0000.raw \ + of=sample_vegas.raw bs=80 count=178 + Initial frame is >50 MB and truncated. For tests of header functionality only. """ diff --git a/docs/conf.py b/docs/conf.py index 9c3e891c..1eaa1916 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,36 +27,24 @@ import os import sys -import datetime +import tomllib +import warnings +from datetime import UTC, datetime from importlib import import_module +from pathlib import Path -import baseband - -try: +with warnings.catch_warnings(): + # Remove warning about matplotlib - we don't use it. + warnings.filterwarnings("ignore", "matplotlib") from sphinx_astropy.conf.v1 import * # noqa -except ImportError: - print('ERROR: the documentation requires the sphinx-astropy package to be installed') - sys.exit(1) -# Get configuration information from setup.cfg -from configparser import ConfigParser -conf = ConfigParser() -conf.read([os.path.join(os.path.dirname(__file__), '..', 'setup.cfg')]) -setup_cfg = dict(conf.items('metadata')) +# -- Get user configuration from pyproject.toml ------------------------------- +with (Path(__file__).parents[1] / "pyproject.toml").open("rb") as f: + pyproject = tomllib.load(f) # -- General configuration ---------------------------------------------------- -# By default, highlight as Python 3. -highlight_language = 'python3' - -# If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.2' - -# To perform a Sphinx version check that needs to be more specific than -# major.minor, call `check_sphinx_version("x.y.z")` here. -# check_sphinx_version("1.2.1") - # add any custom intersphinx mappings intersphinx_mapping['baseband_tasks'] = ( 'https://baseband.readthedocs.io/projects/baseband-tasks/en/stable/', None) @@ -65,38 +53,36 @@ # directories to ignore when looking for source files. exclude_patterns.append('_templates') -# This is added to the end of RST files - a good place to put substitutions to -# be used globally. -rst_epilog += """ -.. _Python: https://www.python.org/ -.. _Astropy: https://www.astropy.org -.. _NumPy: https://numpy.org -.. _baseband-tasks: https://baseband.readthedocs.io/projects/baseband-tasks/ -.. |minimum_python_version| replace:: {0.__minimum_python_version__} -.. |minimum_astropy_version| replace:: {0.__minimum_astropy_version__} -.. |minimum_numpy_version| replace:: {0.__minimum_numpy_version__} -""".format(baseband) - # -- Project information ------------------------------------------------------ # This does not *have* to match the package name, but typically does -project = setup_cfg['name'] -author = setup_cfg['author'] -copyright = '{0}, {1}'.format( - datetime.datetime.now().year, setup_cfg['author']) +project = pyproject["project"]["name"] +author = " & ".join(auth["name"] for auth in pyproject["project"]["authors"]) +copyright = f"{datetime.now(tz=UTC).year}, {author}" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. -import_module(setup_cfg['name']) -package = sys.modules[setup_cfg['name']] +import_module(project) +package = sys.modules[project] # The short X.Y version. version = package.__version__.split('-', 1)[0] # The full version, including alpha/beta/rc tags. release = package.__version__ +# This is added to the end of RST files - a good place to put substitutions to +# be used globally. +rst_epilog += """ +.. _Python: https://www.python.org/ +.. _Astropy: https://www.astropy.org +.. _NumPy: https://numpy.org +.. _baseband-tasks: https://baseband.readthedocs.io/projects/baseband-tasks/ +.. |minimum_python_version| replace:: {0.__minimum_python_version__} +.. |minimum_astropy_version| replace:: {0.__minimum_astropy_version__} +.. |minimum_numpy_version| replace:: {0.__minimum_numpy_version__} +""".format(package) # -- Options for HTML output -------------------------------------------------- @@ -167,15 +153,13 @@ # -- Options for the edit_on_github extension --------------------------------- -if eval(setup_cfg.get('edit_on_github')): - extensions += ['sphinx_astropy.ext.edit_on_github'] - edit_on_github_project = setup_cfg['github_project'] - edit_on_github_branch = "master" - edit_on_github_source_root = "" - edit_on_github_doc_root = "docs" +extensions += ['sphinx_astropy.ext.edit_on_github'] +edit_on_github_project = pyproject["project"]["urls"]["repository"].replace("https://github.com/", "") +edit_on_github_source_root = "" +edit_on_github_doc_root = "docs" # -- Resolving issue number to links in changelog ----------------------------- -github_issues_url = 'https://github.com/{0}/issues/'.format(setup_cfg['github_project']) +github_issues_url = pyproject["project"]["urls"]["repository"] + "/issues/" # -- Turn on nitpicky mode for sphinx (to warn about references not found) ---- # diff --git a/pyproject.toml b/pyproject.toml index 7e7daea4..395200af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,118 @@ +[project] +name = "baseband" +description = "A package for radio baseband I/O" +readme = { file = "README.rst", content-type = "text/x-rst" } +requires-python = ">=3.10" +license = { text = "GNU GPL v3+" } +authors = [ + { name = "Marten H. van Kerkwijk", email = "mhvk@astro.utoronto.ca"}, + { name = "Chenchong Zhu" }, +] +dynamic = ["version"] +dependencies = [ + "astropy>=5.1", +] + [build-system] +requires = [ + "setuptools>=62.1", + "setuptools_scm[toml]>=6.2", + "wheel", +] +build-backend = "setuptools.build_meta" + +[project.optional-dependencies] +all = ["baseband-tasks[all]"] +test = [ + "pytest-astropy-header", + "pytest-doctestplus", + "pytest-filter-subpackage", + "pytest-remotedata", +] +cov = ["coverage"] +docs = ["sphinx-astropy"] + +[project.urls] +repository = "https://github.com/mhvk/baseband" +documentation = "https://baseband.readthedocs.io" + +[project.entry-points."baseband.io"] +dada = "baseband.dada" +guppi = "baseband.guppi" +mark4 = "baseband.mark4" +mark5b = "baseband.mark5b" +vdif = "baseband.vdif" +gsb = "baseband.gsb" + +[tool.setuptools] +include-package-data = true +license-files = ["LICENSE", "licenses/*.rst"] + +[tool.setuptools.packages.find] +include = ["baseband*"] +exclude = ["baseband._dev*"] + +[tool.setuptools.package-data] +"*" = ["data/*", "data/gsb/*"] + +[tool.setuptools_scm] +write_to = "baseband/_version.py" + +[tool.pytest.ini_options] +testpaths = [ + "baseband", + "docs", +] +astropy_header = true +astropy_header_packages = [ + "astropy", + "numpy", +] +doctest_plus = "enabled" +text_file_format = "rst" +addopts = "--color=yes --doctest-rst" # --doctest-ignore-import-errors? +filterwarnings = [ + "error", + "ignore:::pytest_doctestplus", + "ignore:numpy.ufunc size changed:RuntimeWarning", + "ignore:numpy.ndarray size changed:RuntimeWarning", +] -requires = ["setuptools", - "setuptools_scm", - "wheel"] +[tool.coverage.run] +omit = [ + "baseband/__init*", + "baseband/conftest.py", + "baseband/*setup_package*", + "baseband/tests/*", + "baseband/*/tests/*", + "baseband/extern/*", + "baseband/version*", + "*/baseband/__init*", + "*/baseband/conftest.py", + "*/baseband/*setup_package*", + "*/baseband/tests/*", + "*/baseband/*/tests/*", + "*/baseband/extern/*", + "*/baseband/version*", +] -build-backend = 'setuptools.build_meta' +[tool.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_", + # typing.TYPE_CHECKING is False at runtime + "if TYPE_CHECKING:", + # Ignore typing overloads + "@overload", +] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index ddeb30bc..00000000 --- a/setup.cfg +++ /dev/null @@ -1,121 +0,0 @@ -[metadata] -name = baseband -author = Marten H. van Kerkwijk, Chenchong Zhu -author_email = mhvk@astro.utoronto.ca -license = GNU GPL v3+ -license_file = LICENSE -url = https://github.com/mhvk/baseband -project_urls = - Documentation = https://baseband.readthedocs.io - Source = https://github.com/mhvk/baseband -description = A package for radio baseband I/O -long_description = file: README.rst -long_description_content_type = text/x-rst -edit_on_github = True -github_project = mhvk/baseband - -[options] -zip_safe = False -packages = find: -python_requires = >=3.10 -setup_requires = setuptools_scm -install_requires = - astropy>=5.1 - -[options.entry_points] -baseband.io = - dada = baseband.dada - guppi = baseband.guppi - mark4 = baseband.mark4 - mark5b = baseband.mark5b - vdif = baseband.vdif - gsb = baseband.gsb - -[options.extras_require] -all = - baseband-tasks[all] -test = - pytest-astropy-header - pytest-doctestplus - pytest-filter-subpackage - pytest-remotedata # Allows baseband.test() to work -cov = - pytest-cov -docs = - sphinx-astropy - -[options.package_data] -baseband = data/*, data/gsb/* - -[tool:pytest] -testpaths = "baseband" "docs" -astropy_header = true -astropy_header_packages = - astropy - numpy -doctest_plus = enabled -text_file_format = rst -addopts = --doctest-rst --doctest-ignore-import-errors -filterwarnings = - error - ignore:::pytest_doctestplus - ignore:numpy.ufunc size changed:RuntimeWarning - ignore:numpy.ndarray size changed:RuntimeWarning - -[coverage:run] -omit = - baseband/_astropy_init* - baseband/conftest.py - baseband/*setup_package* - baseband/tests/* - baseband/*/tests/* - baseband/extern/* - baseband/version* - */baseband/_astropy_init* - */baseband/conftest.py - */baseband/*setup_package* - */baseband/tests/* - */baseband/*/tests/* - */baseband/extern/* - */baseband/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_ - -[flake8] -ignore= - # missing whitespace around arithmetic operator - E226, - # line break before binary operator (have to choose before or after), - W503 -exclude = - # part of astropy affilliated package template, not our worry. - baseband/conftest.py,baseband/version.py,baseband/__init__.py, - baseband/_astropy_init.py, - docs/conf.py, - setup.py, - # standard things to ignore - __pycache__,build,dist,htmlcov,licenses - -[pycodestyle] -exclude = - # part of astropy affilliated package template, not our worry. - baseband/conftest.py,baseband/version.py,baseband/__init__.py, - baseband/_astropy_init.py, - docs/conf.py, - setup.py, - # standard things to ignore - __pycache__,build,dist,htmlcov,licenses diff --git a/setup.py b/setup.py index ee74e057..72096a24 100644 --- a/setup.py +++ b/setup.py @@ -1,79 +1,6 @@ #!/usr/bin/env python # Licensed under a 3-clause BSD style license - see LICENSE.rst -# NOTE: The configuration for the package, including the name, version, and -# other information are set in the setup.cfg file. - -import os -import sys - from setuptools import setup -from setuptools.config import read_configuration - - -# First provide helpful messages if contributors try and run legacy commands -# for tests or docs. - -TEST_HELP = """ -Note: running tests is no longer done using 'python setup.py test'. Instead -you will need to run: - - tox -e test - -If you don't already have tox installed, you can install it with: - - pip install tox - -If you only want to run part of the test suite, you can also use pytest -directly with:: - - pip install -e .[test] - pytest - -For more information, see: - - http://docs.astropy.org/en/latest/development/testguide.html#running-tests -""" - -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: - - tox -e build_docs - -If you don't already have tox installed, you can install it with: - - pip install tox - -You can also build the documentation with Sphinx directly using:: - - pip install -e .[docs] - cd docs - make html - -For more information, see: - - http://docs.astropy.org/en/latest/install.html#builddocs -""" - -if 'build_docs' in sys.argv or 'build_sphinx' in sys.argv: - print(DOCS_HELP) - sys.exit(1) - -VERSION_TEMPLATE = """ -# Note that we need to fall back to the hard-coded version if either -# setuptools_scm can't be imported or setuptools_scm can't determine the -# version, so we catch the generic 'Exception'. -try: - from setuptools_scm import get_version - version = get_version(root='..', relative_to=__file__) -except Exception: - version = '{version}' -""".lstrip() -setup(use_scm_version={'write_to': os.path.join('baseband', 'version.py'), - 'write_to_template': VERSION_TEMPLATE}) +setup()