From fc3251f52aef148ef07c1aadf541a01b3cd31027 Mon Sep 17 00:00:00 2001 From: Mihai Cara Date: Sun, 3 Dec 2023 20:19:01 -0500 Subject: [PATCH] Switch to CI --- .bandit.yaml | 2 + .coveragerc | 4 +- .github/workflows/ci.yml | 68 ++++++++++++++++++++++++++++ .gitignore | 3 ++ azure-pipelines.yml | 58 ------------------------ azure-templates.yml | 75 ------------------------------- pyproject.toml | 7 ++- tox.ini | 95 +++++++++++++++++++++++++++++++++++++++ tweakwcs/tests/coveragerc | 13 ------ 9 files changed, 174 insertions(+), 151 deletions(-) create mode 100644 .bandit.yaml create mode 100644 .github/workflows/ci.yml delete mode 100644 azure-pipelines.yml delete mode 100644 azure-templates.yml create mode 100644 tox.ini delete mode 100644 tweakwcs/tests/coveragerc diff --git a/.bandit.yaml b/.bandit.yaml new file mode 100644 index 0000000..cc20e9d --- /dev/null +++ b/.bandit.yaml @@ -0,0 +1,2 @@ +exclude_dirs: + - tweakwcs/tests diff --git a/.coveragerc b/.coveragerc index 9968f44..7a63cb7 100644 --- a/.coveragerc +++ b/.coveragerc @@ -8,9 +8,11 @@ exclude_lines = pragma: no cover raise NotImplementedError if __name__ == .__main__.: + @(abc\\.)?abstractmethod + raise AssertionError + raise NotImplementedError ignore_errors = True omit = - conftest.py setup.py tests/* tweakwcs/tests/* diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..54ab28b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,68 @@ +name: CI + +on: + push: + branches: + - master + - '*.x' + tags: + - "*" + pull_request: + schedule: + - cron: '0 6 * * 1' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + check: + uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1 + with: + envs: | + - linux: check-style + - linux: check-security + - linux: check-build + test: + uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1 + with: + envs: | + - linux: test-xdist + python-version: 3.8 + - macos: test-xdist + python-version: 3.8 + - windows: test-xdist + python-version: 3.8 + - linux: test-numpy121-xdist + python-version: 3.9 + - linux: test-numpy123-xdist + python-version: 3.9 + - linux: test-numpy125-xdist + python-version: 3.9 + - macos: test-numpy121-xdist + python-version: 3.10 + - linux: test-numpy125-xdist + python-version: 3.10 + - linux: test-xdist + python-version: 3.11 + pytest-results-summary: true + - macos: test-xdist + python-version: 3.11 + pytest-results-summary: true + - windows: test-xdist + python-version: 3.11 + pytest-results-summary: true + - linux: test-pyargs-xdist + python-version: 3.11 + - linux: test-cov-xdist + python-version: 3.12 + coverage: codecov + pytest-results-summary: true + - macos: test-xdist + python-version: 3.12 + pytest-results-summary: true + - windows: test-xdist + python-version: 3.12 + pytest-results-summary: true + - linux: test-dev-xdist + python-version: 3.12 diff --git a/.gitignore b/.gitignore index af9fb88..a690bac 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ tweakwcs/_version.py htmlcov .coverage MANIFEST +coveragerc # Sphinx docs/api @@ -45,6 +46,7 @@ docs/_build/ # Packages/installer info *.egg *.egg-info +.tox dist/ build/ eggs @@ -61,6 +63,7 @@ pip-wheel-metadata # codecov .coverage *.coverage.* +**/coverage.xml # Other *~ diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index e996104..0000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,58 +0,0 @@ -# Python package -# Create and test a Python package on multiple Python versions. -# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more: -# https://docs.microsoft.com/azure/devops/pipelines/languages/python - -trigger: -- master - -variables: - PYTHONUNBUFFERED: '1' - -jobs: -- template: azure-templates.yml - parameters: - name: Linux - os: linux - -- template: azure-templates.yml - parameters: - name: MacOS - os: macos - -- template: azure-templates.yml - parameters: - name: Windows - os: windows - -- job: 'PEP8' - pool: - vmImage: 'ubuntu-latest' - - steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: '3.x' - architecture: 'x64' - - - script: | - python -m pip install --upgrade flake8 - flake8 - displayName: 'Run check' - - -- job: 'Publish' - dependsOn: 'Linux' - pool: - vmImage: 'ubuntu-latest' - - steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: '3.x' - architecture: 'x64' - - - script: | - python -m pip install astropy build - python -m build --sdist . - displayName: 'Build sdist' diff --git a/azure-templates.yml b/azure-templates.yml deleted file mode 100644 index 0fd57d8..0000000 --- a/azure-templates.yml +++ /dev/null @@ -1,75 +0,0 @@ -jobs: -- job: ${{ format(parameters.name) }} - pool: - ${{ if eq(parameters.os, 'windows') }}: - vmImage: windows-latest - ${{ if eq(parameters.os, 'macos') }}: - vmImage: macOS-latest - ${{ if eq(parameters.os, 'linux') }}: - vmImage: ubuntu-latest - - strategy: - matrix: - Python38: - python.version: '3.8' - Python39: - python.version: '3.9' - Python310: - python.version: '3.10' - Python311: - python.version: '3.11' - Python312: - python.version: '3.12' - maxParallel: 4 - - steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: '$(python.version)' - architecture: 'x64' - - - bash: | - export PIP_INSTALL='pip install --upgrade' - echo "##vso[task.setvariable variable=PIP_INSTALL]$PIP_INSTALL" - condition: ne( variables['Agent.OS'], 'Windows_NT' ) - displayName: Pip on Linux/Darwin - - - powershell: | - Set-Variable -Name PIP_INSTALL -Value 'python -m pip install --upgrade' - Write-Host "##vso[task.setvariable variable=PIP_INSTALL]$PIP_INSTALL" - condition: eq( variables['Agent.OS'], 'Windows_NT' ) - displayName: Pip on Windows - - - script: | - $(PIP_INSTALL) -e .[test] - displayName: build package - - - script: | - python -m pip freeze - displayName: freeze output - - - script: | - pytest --cov=./ -v --junitxml=junit/test-results.xml - displayName: run test - - - bash: | - curl -Os https://uploader.codecov.io/latest/${{parameters.os}}/codecov - chmod +x codecov - ./codecov -t $codecov_token - env: - codecov_token: $(CODECOV_TOKEN) - condition: ne( variables['Agent.OS'], 'Windows_NT' ) - displayName: codecov upload on Linux/Darwin - - - powershell: | - $ProgressPreference = 'SilentlyContinue' - Invoke-WebRequest -Uri https://uploader.codecov.io/latest/windows/codecov.exe -Outfile codecov.exe - .\codecov.exe -t ${CODECOV_TOKEN} - condition: eq( variables['Agent.OS'], 'Windows_NT' ) - displayName: codecov upload on Windows - - - task: PublishTestResults@2 - condition: succeededOrFailed() - inputs: - testResultsFiles: '**/test-*.xml' - testRunTitle: 'Python $(python.version)-${{ format(parameters.name) }}' diff --git a/pyproject.toml b/pyproject.toml index 0b4e632..8b78fbe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,6 @@ Documentation = "http://spacetelescope.github.io/tweakwcs/" test = [ "pytest", "pytest-cov", - "coverage", "scipy", ] docs = [ @@ -72,18 +71,18 @@ include-package-data = true license-files = ["LICENSE.rst"] [tool.setuptools.packages.find] -namespaces = false +namespaces = true [tool.setuptools.package-data] "*" = [ - 'tweakwcs/tests/data/*', - 'notebooks/*', + 'notebooks/*.ipynb', ] "tweakwcs" = [ 'README.rst', 'LICENSE.txt', 'CHANGELOG.rst', ] +"tweakwcs.tests.data" = ["tweakwcs/tests/data/*"] [tool.setuptools_scm] write_to = "tweakwcs/_version.py" diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..cb814bb --- /dev/null +++ b/tox.ini @@ -0,0 +1,95 @@ +[tox] +envlist = + check-{style,security,build} + test{,-dev}{,-pyargs,-cov} + test-numpy{120,122,125} + build-{docs,dist} + +# tox environments are constructed with so-called 'factors' (or terms) +# separated by hyphens, e.g. test-devdeps-cov. Lines below starting with factor: +# will only take effect if that factor is included in the environment name. To +# see a list of example environments that can be run, along with a description, +# run: +# +# tox -l -v +# + +[testenv:check-style] +description = check code style, e.g. with flake8 +skip_install = true +deps = + flake8 +commands = + flake8 . {posargs} + +[testenv:check-security] +description = run bandit to check security compliance +skip_install = true +deps = + bandit>=1.7 +commands = + bandit -r -ll -c .bandit.yaml tweakwcs + +[testenv:check-build] +description = check build sdist/wheel and a strict twine check for metadata +skip_install = true +deps = + twine>=3.3 + build +commands = + python -m build . + twine check --strict dist/* + +[testenv] +description = + run tests + dev: with the latest developer version of key dependencies + pyargs: with --pyargs on installed package + warnings: treating warnings as errors + cov: with coverage + xdist: using parallel processing +passenv = + HOME + GITHUB_* + TOXENV + CI + CODECOV_* + DISPLAY +set_env = + dev: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/astropy/simple https://pypi.anaconda.org/liberfa/simple https://pypi.anaconda.org/scientific-python-nightly-wheels/simple + +args_are_paths = false +change_dir = pyargs: {env:HOME} +extras = + test + alldeps: all +deps = + xdist: pytest-xdist + cov: pytest-cov + numpy121: numpy==1.21.* + numpy123: numpy==1.23.* + numpy125: numpy==1.25.* +commands_pre = + dev: pip install -r requirements-dev.txt -U --upgrade-strategy eager + pip freeze +commands = + pytest \ + warnings: -W error \ + xdist: -n auto \ + pyargs: {toxinidir}/docs --pyargs tweakwcs \ + cov: --cov=. --cov-config=pyproject.toml --cov-report=term-missing --cov-report=xml \ + {posargs} + +[testenv:build-docs] +description = invoke sphinx-build to build the HTML docs +extras = docs +commands = + sphinx-build -W docs docs/_build + +[testenv:build-dist] +description = build wheel and sdist +skip_install = true +deps = + build +commands = + python -m build . diff --git a/tweakwcs/tests/coveragerc b/tweakwcs/tests/coveragerc deleted file mode 100644 index 9018eee..0000000 --- a/tweakwcs/tests/coveragerc +++ /dev/null @@ -1,13 +0,0 @@ -[run] -source = tweakwcs -omit = - tweakwcs/conftest* - tweakwcs/tests/* - -[report] -exclude_lines = - # Have to re-enable the standard pragma - pragma: no cover - - # Ignore branches that don't pertain to this version of Python - pragma: py{ignore_python_version}