Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ruff, pre-commit, and format existing files #182

Merged
merged 10 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
113 changes: 113 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
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.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 -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 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.

138 changes: 30 additions & 108 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,122 +1,44 @@
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 }
- { os: ubuntu-latest, py: "3.10", doc: 1, whl: 1 }
- { os: windows-latest, py: "3.10", whl: 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

- 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

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]
python setup.py 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