From 65a5a89ff496fabe1d22d4b831987daef3a82a1c Mon Sep 17 00:00:00 2001 From: Zach Burnett Date: Mon, 10 Jun 2024 15:25:19 -0400 Subject: [PATCH] consolidate build metadata in `pyproject.toml` (PEP621) (#241) * apply `peppyproject` for PEP621 * remove deprecated codecov package * flake8 -> ruff * use pathlib to match filenames * run build workflow on PR, and do import check on C extension * use packages.find * change wheel-built numpy version to match runtime numpy version (below 2.0) --- .github/workflows/build.yml | 28 +++++++++ .github/workflows/publish-to-pypi.yml | 41 ------------ pyproject.toml | 81 +++++++++++++++++++++++- setup.cfg | 13 ---- setup.py | 89 ++++++--------------------- 5 files changed, 125 insertions(+), 127 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/publish-to-pypi.yml delete mode 100644 setup.cfg diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..bda7256 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,28 @@ +name: build + +on: + release: + types: [ released ] + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish.yml@v1 + with: + targets: | + # Linux wheels + - cp3*-manylinux_x86_64 + # MacOS wheels + - cp3*-macosx_x86_64 + # Until we have arm64 runners, we can't automatically test arm64 wheels + - cp3*-macosx_arm64 + sdist: true + test_command: python -c "from calcos import ccos" + upload_to_pypi: ${{ (github.event_name == 'release') && (github.event.action == 'released') }} + secrets: + pypi_token: ${{ secrets.PYPI_PASSWORD_STSCI_MAINTAINER }} diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml deleted file mode 100644 index eada94e..0000000 --- a/.github/workflows/publish-to-pypi.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Publish to PyPI - -on: - release: - types: [released] - -jobs: - validate: - name: Validate metadata - runs-on: ubuntu-latest - steps: - - uses: spacetelescope/action-publish_to_pypi/validate@master - - build_wheels: - name: Build wheels on ${{ matrix.os }} - needs: [validate] - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - - steps: - - uses: spacetelescope/action-publish_to_pypi/build-wheel@master - - build_sdist: - name: Build source distribution - needs: [validate] - runs-on: ubuntu-latest - steps: - - uses: spacetelescope/action-publish_to_pypi/build-sdist@master - - upload_pypi: - needs: [build_wheels, build_sdist] - runs-on: ubuntu-latest - steps: - - uses: spacetelescope/action-publish_to_pypi/publish@master - with: - test: ${{ secrets.PYPI_TEST }} - user: ${{ secrets.PYPI_USERNAME_STSCI_MAINTAINER }} - password: ${{ secrets.PYPI_PASSWORD_STSCI_MAINTAINER }} # WARNING: Do not hardcode secret values here! If you want to use a different user or password, you can override this secret by creating one with the same name in your Github repository settings. - test_password: ${{ secrets.PYPI_PASSWORD_STSCI_MAINTAINER_TEST }} diff --git a/pyproject.toml b/pyproject.toml index 9599e2b..c03da33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,85 @@ +[project] +name = "calcos" +description = "Calibration software for COS (Cosmic Origins Spectrograph)" +requires-python = ">=3.9" +authors = [ + { name = "Phil Hodge", email="help@stsci.edu" }, + { name = "Robert Jedrzejewski" }, +] +classifiers = [ + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "Programming Language :: C", + "Topic :: Software Development :: Libraries :: Python Modules", +] +dependencies = [ + "astropy>=5.0.4", + "numpy<2.0", + "scipy", + "stsci.tools>=4.0.0", +] +dynamic = [ + "version", +] + +[project.readme] +file = "README.md" +content-type = "text/markdown" + +[project.scripts] +calcos = "calcos:main" + +[project.optional-dependencies] +docs = [ + "sphinx<7", +] +test = [ + "ci-watson", + "pytest", + "pytest-cov", +] + [build-system] requires = [ "setuptools>=42.0", "setuptools_scm[toml]>=3.4", "wheel", - "numpy>=2.0.0rc2", + "oldest-supported-numpy", +] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +include-package-data = false + +[tool.setuptools.packages.find] + +[tool.setuptools.package-data] +calcos = [ + "pars/*", + "*.help", +] + +[tool.setuptools_scm] +version_file = "calcos/version.py" + +[tool.pytest.ini_options] +minversion = "3.0" +norecursedirs = [ + "build", + "doc/build", + "src", +] +junit_family = "xunit2" + +[tool.ruff.lint] +exclude = [ + "setup.py", + "__init__.py", +] +ignore = [ + "E265", + "F821", + "F841", ] -build-backend = 'setuptools.build_meta' diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 8ceb47b..0000000 --- a/setup.cfg +++ /dev/null @@ -1,13 +0,0 @@ -[options] -python_requires = >=3.9 - -[tool:pytest] -minversion = 3.0 -norecursedirs = build doc/build src -junit_family = xunit2 - -[flake8] -# E265: block comment should start with '#' -# F821 undefined name -ignore = E265,F821,F841 -exclude = setup.py,__init__.py diff --git a/setup.py b/setup.py index 15edd3e..4c74b93 100755 --- a/setup.py +++ b/setup.py @@ -1,89 +1,36 @@ #!/usr/bin/env python -import os -from fnmatch import fnmatch -from setuptools import setup, find_packages, Extension +from setuptools import setup, Extension from numpy import get_include as numpy_includes +from pathlib import Path -def c_sources(parent): - sources = [] - for root, _, files in os.walk(parent): - for f in files: - fn = os.path.join(root, f) - if fnmatch(fn, '*.c'): - sources.append(fn) - return sources +def c_sources(parent: str) -> list[str]: + return [str(filename) for filename in Path(parent).glob("*.c")] -def c_includes(parent, depth=1): - includes = [parent] - for root, dirs, _ in os.walk(parent): - for d in dirs: - dn = os.path.join(root, d) - if len(dn.split(os.sep)) - 1 > depth: - continue - includes.append(dn) - return includes + +def c_includes(parent: str, depth: int = 1): + return [ + parent, + *( + str(filename) + for filename in Path(parent).iterdir() + if filename.is_dir() and len(filename.parts) - 1 <= depth + ), + ] -PACKAGENAME = 'calcos' -SOURCES = c_sources('src') -INCLUDES = c_includes('src') + [numpy_includes()] +PACKAGENAME = "calcos" +SOURCES = c_sources("src") +INCLUDES = c_includes("src") + [numpy_includes()] setup( - name=PACKAGENAME, - use_scm_version={'write_to': 'calcos/version.py'}, - setup_requires=['setuptools_scm'], - install_requires=[ - 'astropy>=5.0.4', - 'numpy<2.0', - 'scipy', - 'stsci.tools>=4.0.0', - ], - extras_require={ - 'docs': [ - 'sphinx<7', - ], - 'test': [ - 'ci-watson', - 'pytest', - 'pytest-cov', - 'codecov', - ], - }, - packages=find_packages(), - package_data={ - PACKAGENAME: [ - 'pars/*', - '*.help', - ], - }, ext_modules=[ Extension( - PACKAGENAME + '.ccos', + PACKAGENAME + ".ccos", sources=SOURCES, include_dirs=INCLUDES, ), ], - entry_points={ - 'console_scripts': { - 'calcos = calcos:main', - }, - }, - author='Phil Hodge, Robert Jedrzejewski', - author_email='help@stsci.edu', - description='Calibration software for COS (Cosmic Origins Spectrograph)', - long_description='README.md', - long_description_content_type='text/x-rst', - url='https://github.com/spacetelescope/calcos', - license='BSD', - classifiers=[ - 'Intended Audience :: Science/Research', - 'License :: OSI Approved :: BSD License', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3', - 'Programming Language :: C', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], )