Skip to content

Commit

Permalink
Add ruff, pre-commit, and format existing files (#184)
Browse files Browse the repository at this point in the history
* Add ruff, pre-commit, and format existing files

* oops, we use bumps@master now

* Run formatting

* move deps into optional dev group, add webview optional group, update workflows

* add back python -m

* update gitignore

* remove ref webview

* update workflows a bit

* remove python 3.7 from publish

* add extra versions to test against

* add build

* update min to python 3.9

* update min to python 3.9

---------

Co-authored-by: glass-ships <glass.ships@outlook.com>
  • Loading branch information
mdoucet and glass-ships committed Sep 12, 2024
1 parent 4f3963a commit 00cfbeb
Show file tree
Hide file tree
Showing 162 changed files with 10,154 additions and 10,843 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/build-change-of-basis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ jobs:
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install wheel setuptools
python -m pip install numpy scipy matplotlib periodictable scikit-learn pytest pytest-cov numba
pip install git+https://github.com/bumps/bumps.git
python -m pip install .[dev,webview]
python setup.py build
mkdir unstable
Expand Down Expand Up @@ -92,7 +90,7 @@ jobs:
- name: Update release assets and text
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const { owner, repo } = context.repo;
Expand Down
112 changes: 112 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Publish to PyPI

on:
push:
branches: [master]
pull_request:
branches: [master]
release:
types: [published]

jobs:
build:
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- { os: ubuntu-latest, py: 3.9 }
- { os: ubuntu-latest, py: "3.10" }
- { os: ubuntu-latest, py: "3.11", doc: 1, whl: 1 }
- { os: ubuntu-latest, py: "3.12" }
- { os: windows-latest, py: "3.11", exe: 1 }
# pure python wheels

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.config.py }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.config.py }}

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[dev,webview]
mkdir release
mkdir dist
- name: Check that the docs build (linux only)
if: matrix.config.doc == 1
run: |
python -m pip install sphinx
make -j 4 -C doc SPHINXOPTS="-W --keep-going" html
- name: Build binary wheel
if: matrix.config.whl == 1
run: |
python -m pip install build setuptools wheel
python -m build
- name: Build installer
if: matrix.config.exe == 1
run: |
pwsh -command ".\$GITHUB_WORKSPACE\extra\build_win_installer.ps1"
mv dist\Refl1D*.zip release\
# See the following for how to upload to a release
# https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.config.os }}-${{ matrix.config.py }}
path: |
dist/*.whl
dist/*.zip
dist/*.tar.gz
release/*.zip
publish:
needs: build
runs-on: ubuntu-latest
steps:
- name: Retrieve all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
pattern: artifacts-*
merge-multiple: true

- name: show files
run: |
ls -R artifacts
echo "WINDOWS_INSTALLER=$(ls artifacts/release/*.zip)" >> $GITHUB_ENV
echo "SRC_DIST=$(ls artifacts/dist/*.tar.gz)" >> $GITHUB_ENV
echo "PY3_WHL=$(ls artifacts/dist/*.whl)" >> $GITHUB_ENV
- name: Update current release
if: startsWith(github.ref, 'refs/tags')
uses: johnwbyrd/update-release@v1.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: |
${{ env.WINDOWS_INSTALLER }}
${{ env.PY3_WHL }}
- name: publish distribution to Test PyPI
env:
TEST_PYPI_API_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }}
if: env.TEST_PYPI_API_TOKEN != null
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
packages-dir: artifacts/dist/

- name: Publish distribution to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: artifacts/dist/
51 changes: 0 additions & 51 deletions .github/workflows/test-webview.yml

This file was deleted.

135 changes: 31 additions & 104 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,122 +1,49 @@
name: Test
name: Test Refl1D

on:
push:
branches: [ master_v0 ]
branches: [master]
pull_request:
branches: [ master_v0 ]
release:
types: [ published ]
branches: [master]
workflow_dispatch:

jobs:
test_and_build:
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- { os: ubuntu-latest, py: 3.7 }
- { os: ubuntu-latest, py: 3.8 }
- { os: ubuntu-latest, py: 3.9 }
- { os: ubuntu-latest, py: "3.10" }
- { os: ubuntu-latest, py: "3.11", doc: 1, whl: 1 }
- { os: ubuntu-latest, py: "3.12" }
- { os: windows-latest, py: "3.11", exe: 1 }
# pure python wheels

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.config.py }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.config.py }}

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install wheel setuptools build
python -m pip install numpy scipy matplotlib bumps periodictable scikit-learn pytest pytest-cov numba
pip install -e .
mkdir release
mkdir dist
- name: Run tests
run: |
pytest -v
python check_examples.py --chisq
env:
MPLBACKEND: agg

- name: Check that the docs build (linux only)
if: matrix.config.doc == 1
run: |
python -m pip install sphinx
make -j 4 -C doc SPHINXOPTS="-W --keep-going" html
- { os: windows-latest, py: "3.12", whl: 1 }
- { os: macos-latest, py: "3.12" }

- name: Build binary wheel
if: matrix.config.whl == 1
run: |
python -m build
- name: Build installer
if: matrix.config.exe == 1
run: |
pwsh -command ".\$GITHUB_WORKSPACE\extra\build_win_installer.ps1"
mv dist\Refl1D*.zip release\
# See the following for how to upload to a release
# https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.config.os }}-${{ matrix.config.py }}
path: |
dist/*.whl
dist/*.zip
dist/*.tar.gz
release/*.zip
# pure python wheels

publish:
needs: test_and_build
runs-on: ubuntu-latest
steps:
- name: Retrieve all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
pattern: artifacts-*
merge-multiple: true

- name: show files
run: |
ls -R artifacts
echo "WINDOWS_INSTALLER=$(ls artifacts/release/*.zip)" >> $GITHUB_ENV
echo "SRC_DIST=$(ls artifacts/dist/*.tar.gz)" >> $GITHUB_ENV
echo "PY3_WHL=$(ls artifacts/dist/*.whl)" >> $GITHUB_ENV
- name: Update current release
if: startsWith(github.ref, 'refs/tags')
uses: johnwbyrd/update-release@v1.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: |
${{ env.WINDOWS_INSTALLER }}
${{ env.PY3_WHL }}
- name: publish distribution to Test PyPI
env:
TEST_PYPI_API_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }}
if: env.TEST_PYPI_API_TOKEN != null
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
packages-dir: artifacts/dist/

- name: Publish distribution to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: artifacts/dist/
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.config.py }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.config.py }}

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .[dev,webview] build setuptools wheel
python -m build
- name: Run tests
run: |
pytest -v
python check_examples.py --chisq
env:
MPLBACKEND: agg

- name: Check that the docs build (linux only)
if: matrix.config.doc == 1
run: |
pip install sphinx
make -j 4 -C doc SPHINXOPTS="-W --keep-going" html
6 changes: 2 additions & 4 deletions .github/workflows/unstable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ jobs:

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install wheel setuptools
python -m pip install numpy scipy matplotlib periodictable scikit-learn pytest pytest-cov numba
pip install git+https://github.com/bumps/bumps.git
pip install --upgrade pip
pip install .[dev,webview]
python setup.py build
mkdir unstable
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ refl1d-webview-client*.tgz
/refl1d-*
/bumps-*
/Refl1D.pdf
/output-*

# Build
*.so
Expand Down
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
args: [--maxkb=8192]
- id: check-merge-conflict
- id: check-yaml
args: [--allow-multiple-documents]
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
hooks:
# - id: ruff
# args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
# args: [--line-length=120]
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ROOTDIR = $(shell pwd)

# This nifty perl one-liner collects all comments headed by the double "#" symbols next to each target and recycles them as comments
.PHONY: help
help: ## Print this help message
@perl -nle'print $& if m{^[/a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'


.PHONY: lint
lint: ## Run ruff linting
@ruff check --fix refl1d/ tests/ setup.py

.PHONY: format
format: ## Run ruff formatting
@ruff format refl1d/ tests/ setup.py
Loading

0 comments on commit 00cfbeb

Please sign in to comment.