Skip to content

Commit 736dfda

Browse files
authored
Migrate to pyproject.toml, ruff, add build CI (#400)
Closes #209
1 parent 2713858 commit 736dfda

File tree

9 files changed

+300
-103
lines changed

9 files changed

+300
-103
lines changed

.github/workflows/pypi.yaml

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,95 @@
1-
name: Upload Package to PyPI
2-
1+
name: Build and Upload to PyPI
32
on:
43
release:
5-
types: [created]
4+
types:
5+
- published
6+
push:
7+
tags:
8+
- 'v*'
69

710
jobs:
8-
deploy:
11+
build-artifacts:
912
runs-on: ubuntu-latest
13+
if: github.repository == 'xarray-contrib/cf-xarray'
1014
steps:
1115
- uses: actions/checkout@v3
12-
- name: Set up Python
13-
uses: actions/setup-python@v4
1416
with:
15-
python-version: '3.x'
17+
fetch-depth: 0
18+
- uses: actions/setup-python@v4
19+
name: Install Python
20+
with:
21+
python-version: 3.8
22+
1623
- name: Install dependencies
1724
run: |
1825
python -m pip install --upgrade pip
19-
pip install setuptools setuptools-scm wheel twine
20-
- name: Build and publish
21-
env:
22-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
23-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
26+
python -m pip install build twine
27+
28+
- name: Build tarball and wheels
29+
run: |
30+
git clean -xdf
31+
git restore -SW .
32+
python -m build
33+
34+
- name: Check built artifacts
35+
run: |
36+
python -m twine check --strict dist/*
37+
pwd
38+
if [ -f dist/cf_xarray-0.0.0.tar.gz ]; then
39+
echo "❌ INVALID VERSION NUMBER"
40+
exit 1
41+
else
42+
echo "✅ Looks good"
43+
fi
44+
- uses: actions/upload-artifact@v3
45+
with:
46+
name: releases
47+
path: dist
48+
49+
test-built-dist:
50+
needs: build-artifacts
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/setup-python@v4
54+
name: Install Python
55+
with:
56+
python-version: 3.8
57+
- uses: actions/download-artifact@v3
58+
with:
59+
name: releases
60+
path: dist
61+
- name: List contents of built dist
62+
run: |
63+
ls -ltrh
64+
ls -ltrh dist
65+
66+
- name: Verify the built dist/wheel is valid
67+
if: github.event_name == 'push'
2468
run: |
25-
python setup.py sdist bdist_wheel
26-
twine upload dist/*
69+
python -m pip install --upgrade pip
70+
python -m pip install dist/cf_xarray*.whl
71+
python -m cf_xarray.scripts.print_versions
72+
73+
- name: Publish package to TestPyPI
74+
if: github.event_name == 'push'
75+
uses: pypa/[email protected]
76+
with:
77+
password: ${{ secrets.TESTPYPI_TOKEN }}
78+
repository_url: https://test.pypi.org/legacy/
79+
verbose: true
80+
81+
82+
upload-to-pypi:
83+
needs: test-built-dist
84+
if: github.event_name == 'release'
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: actions/download-artifact@v3
88+
with:
89+
name: releases
90+
path: dist
91+
- name: Publish package to PyPI
92+
uses: pypa/[email protected]
93+
with:
94+
password: ${{ secrets.PYPI_PASSWORD }}
95+
verbose: true
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Build and Upload to TestPyPI
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
pull_request:
8+
types: [opened, reopened, synchronize, labeled]
9+
branches:
10+
- "*"
11+
workflow_dispatch:
12+
13+
# no need for concurrency limits
14+
15+
jobs:
16+
build-artifacts:
17+
if: ${{ contains( github.event.pull_request.labels.*.name, 'test-build') && github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
24+
- uses: actions/setup-python@v4
25+
name: Install Python
26+
with:
27+
python-version: "3.10"
28+
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
python -m pip install build twine
33+
python -m pip install tomli tomli_w
34+
35+
# - name: Disable local versions
36+
# run: |
37+
# python .github/workflows/configure-testpypi-version.py pyproject.toml
38+
# git update-index --assume-unchanged pyproject.toml
39+
# cat pyproject.toml
40+
41+
- name: Build tarball and wheels
42+
run: |
43+
git clean -xdf
44+
python -m build
45+
46+
- name: Check built artifacts
47+
run: |
48+
python -m twine check --strict dist/*
49+
if [ -f dist/cf_xarray-0.0.0.tar.gz ]; then
50+
echo "❌ INVALID VERSION NUMBER"
51+
exit 1
52+
else
53+
echo "✅ Looks good"
54+
fi
55+
56+
- uses: actions/upload-artifact@v3
57+
with:
58+
name: releases
59+
path: dist
60+
61+
test-built-dist:
62+
needs: build-artifacts
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/setup-python@v4
66+
name: Install Python
67+
with:
68+
python-version: "3.10"
69+
- uses: actions/download-artifact@v3
70+
with:
71+
name: releases
72+
path: dist
73+
- name: List contents of built dist
74+
run: |
75+
ls -ltrh
76+
ls -ltrh dist
77+
78+
- name: Verify the built dist/wheel is valid
79+
run: |
80+
python -m pip install --upgrade pip
81+
python -m pip install dist/cf_xarray*.whl
82+
python -m cf_xarray.scripts.print_versions
83+
84+
# - name: Publish package to TestPyPI
85+
# uses: pypa/[email protected]
86+
# with:
87+
# password: ${{ secrets.TESTPYPI_TOKEN }}
88+
# repository_url: https://test.pypi.org/legacy/
89+
# verbose: true

.pre-commit-config.yaml

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,24 @@ ci:
22
autoupdate_schedule: quarterly
33

44
repos:
5-
- repo: https://github.com/PyCQA/isort
6-
rev: 5.11.4
5+
- repo: https://github.com/charliermarsh/ruff-pre-commit
6+
# Ruff version.
7+
rev: 'v0.0.235'
78
hooks:
8-
- id: isort
9-
files: .+\.py$
9+
- id: ruff
10+
args: ["--fix"]
1011

1112
- repo: https://github.com/psf/black
1213
rev: 22.12.0
1314
hooks:
1415
- id: black
1516

16-
- repo: https://github.com/PyCQA/flake8
17-
rev: 6.0.0
18-
hooks:
19-
- id: flake8
20-
2117
- repo: https://github.com/rstcheck/rstcheck
2218
rev: v6.1.1
2319
hooks:
2420
- id: rstcheck
25-
additional_dependencies: [sphinx]
21+
additional_dependencies: [sphinx, tomli]
22+
args: ['--config', 'pyproject.toml']
2623

2724
- repo: https://github.com/executablebooks/mdformat
2825
rev: 0.7.16
@@ -36,29 +33,21 @@ repos:
3633
rev: 1.6.0
3734
hooks:
3835
- id: nbqa-black
39-
- id: nbqa-pyupgrade
40-
args: [--py37-plus]
41-
- id: nbqa-isort
36+
- id: nbqa-ruff
4237
- id: nbqa
4338
entry: nbqa mdformat
4439
name: nbqa-mdformat
4540
alias: nbqa-mdformat
4641
additional_dependencies: [mdformat==0.7.14]
4742

48-
- repo: https://github.com/asottile/pyupgrade
49-
rev: v3.3.1
50-
hooks:
51-
- id: pyupgrade
52-
args:
53-
- "--py37-plus"
54-
5543
- repo: https://github.com/pre-commit/pre-commit-hooks
5644
rev: v4.4.0
5745
hooks:
5846
- id: trailing-whitespace
5947
- id: end-of-file-fixer
6048
- id: check-toml
6149
- id: check-yaml
50+
- id: debug-statements
6251

6352
- repo: https://github.com/keewis/blackdoc
6453
rev: v0.3.8

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
graft cf_xarray/data
22
exclude cf_xarray/_version.py
33

4+
graft cf_xarray/scripts
45
prune ci
56
prune doc
7+
prune cf_xarray/tests
68
prune *.egg-info
79
prune .binder/
810
prune .github/

cf_xarray/scripts/print_versions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if __name__ == "__main__":
2+
import cf_xarray
3+
4+
print(cf_xarray.__version__)

doc/whats-new.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ v0.7.5 (Nov 15, 2022)
2525
By `Pascal Bourgault`_.
2626
- Improve detection of bounds order by rellaxing check a bit (:pr:`361`).
2727
By `Lars Buntemeyer`_.
28-
- Performance improvements. (:pr:`358`). By `Luke Davis`
28+
- Performance improvements. (:pr:`358`). By `Luke Davis`_
2929
- Fix coordinate/axis detection (:pr:`359`). By `Martin Schupfner`_
3030

3131
v0.7.4 (July 14, 2022)

0 commit comments

Comments
 (0)