Skip to content

Commit a99c054

Browse files
author
Filip Richtarik
committed
formatting init
1 parent 7921fcd commit a99c054

17 files changed

Lines changed: 1929 additions & 1932 deletions

.github/workflows/publish.yml

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -4,125 +4,125 @@ name: Publish Python Package
44
on:
55
push:
66
tags:
7-
- 'v[0-9]+.[0-9]+.[0-9]*'
7+
- "v[0-9]+.[0-9]+.[0-9]*"
88

99
jobs:
1010
build:
1111
name: Build distribution
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v4
16-
# NOTE: tags are not present unless triggered by tag push
17-
# - name: Get tags
18-
# run: git fetch --tags origin
19-
# - name: List tags
20-
# run: git tag --list
21-
# TODO: somehow versioneer does not pickup the tag when workflow is not triggered by a
22-
# tag push, getting e.g. (for sister repo scantree) scantree-0+untagged.1.gd74b1d5,
23-
# see: https://github.com/andhus/scantree/actions/runs/7485873305/job/20375116541#step:7:42)
24-
- name: Set up Python
25-
uses: actions/setup-python@v5
26-
with:
27-
python-version: "3.x"
28-
- name: Install pypa/build
29-
run: >-
30-
python3 -m
31-
pip install
32-
build
33-
--user
34-
- name: Build a binary wheel and a source tarball
35-
run: python3 -m build
36-
- name: Store the distribution packages
37-
uses: actions/upload-artifact@v4
38-
with:
39-
name: python-package-distributions
40-
path: dist/
15+
- uses: actions/checkout@v4
16+
# NOTE: tags are not present unless triggered by tag push
17+
# - name: Get tags
18+
# run: git fetch --tags origin
19+
# - name: List tags
20+
# run: git tag --list
21+
# TODO: somehow versioneer does not pickup the tag when workflow is not triggered by a
22+
# tag push, getting e.g. (for sister repo scantree) scantree-0+untagged.1.gd74b1d5,
23+
# see: https://github.com/andhus/scantree/actions/runs/7485873305/job/20375116541#step:7:42)
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.x"
28+
- name: Install pypa/build
29+
run: >-
30+
python3 -m
31+
pip install
32+
build
33+
--user
34+
- name: Build a binary wheel and a source tarball
35+
run: python3 -m build
36+
- name: Store the distribution packages
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: python-package-distributions
40+
path: dist/
4141

4242
publish-to-pypi:
4343
name: Publish to PyPI
4444
# TODO we need to make sure the tag matches the version!
45-
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
45+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
4646
needs:
47-
- build
47+
- build
4848
runs-on: ubuntu-latest
4949
environment:
5050
name: pypi
5151
url: https://pypi.org/p/dirhash
5252
permissions:
53-
id-token: write # IMPORTANT: mandatory for trusted publishing
53+
id-token: write # IMPORTANT: mandatory for trusted publishing
5454

5555
steps:
56-
- name: Download all the dists
57-
uses: actions/download-artifact@v4
58-
with:
59-
name: python-package-distributions
60-
path: dist/
61-
- name: Publish distribution 📦 to PyPI
62-
uses: pypa/gh-action-pypi-publish@release/v1
56+
- name: Download all the dists
57+
uses: actions/download-artifact@v4
58+
with:
59+
name: python-package-distributions
60+
path: dist/
61+
- name: Publish distribution 📦 to PyPI
62+
uses: pypa/gh-action-pypi-publish@release/v1
6363

6464
github-release:
6565
name: Sign and upload to GitHub Release
6666
needs:
67-
- publish-to-pypi
67+
- publish-to-pypi
6868
runs-on: ubuntu-latest
6969

7070
permissions:
71-
contents: write # IMPORTANT: mandatory for making GitHub Releases
72-
id-token: write # IMPORTANT: mandatory for sigstore
71+
contents: write # IMPORTANT: mandatory for making GitHub Releases
72+
id-token: write # IMPORTANT: mandatory for sigstore
7373

7474
steps:
75-
- name: Download all the dists
76-
uses: actions/download-artifact@v4
77-
with:
78-
name: python-package-distributions
79-
path: dist/
80-
- name: Sign the dists with Sigstore
81-
uses: sigstore/gh-action-sigstore-python@v2.1.1
82-
with:
83-
inputs: >-
84-
./dist/*.tar.gz
85-
./dist/*.whl
86-
- name: Create GitHub Release
87-
env:
88-
GITHUB_TOKEN: ${{ github.token }}
89-
run: >-
90-
gh release create
91-
'${{ github.ref_name }}'
92-
--repo '${{ github.repository }}'
93-
--notes ""
94-
- name: Upload artifact signatures to GitHub Release
95-
env:
96-
GITHUB_TOKEN: ${{ github.token }}
97-
# Upload to GitHub Release using the `gh` CLI.
98-
# `dist/` contains the built packages, and the
99-
# sigstore-produced signatures and certificates.
100-
run: >-
101-
gh release upload
102-
'${{ github.ref_name }}' dist/**
103-
--repo '${{ github.repository }}'
75+
- name: Download all the dists
76+
uses: actions/download-artifact@v4
77+
with:
78+
name: python-package-distributions
79+
path: dist/
80+
- name: Sign the dists with Sigstore
81+
uses: sigstore/gh-action-sigstore-python@v2.1.1
82+
with:
83+
inputs: >-
84+
./dist/*.tar.gz
85+
./dist/*.whl
86+
- name: Create GitHub Release
87+
env:
88+
GITHUB_TOKEN: ${{ github.token }}
89+
run: >-
90+
gh release create
91+
'${{ github.ref_name }}'
92+
--repo '${{ github.repository }}'
93+
--notes ""
94+
- name: Upload artifact signatures to GitHub Release
95+
env:
96+
GITHUB_TOKEN: ${{ github.token }}
97+
# Upload to GitHub Release using the `gh` CLI.
98+
# `dist/` contains the built packages, and the
99+
# sigstore-produced signatures and certificates.
100+
run: >-
101+
gh release upload
102+
'${{ github.ref_name }}' dist/**
103+
--repo '${{ github.repository }}'
104104
105105
publish-to-testpypi:
106106
name: Publish to TestPyPI
107-
if: startsWith(github.ref, 'refs/tags/') # only publish on tag pushes
107+
if: startsWith(github.ref, 'refs/tags/') # only publish on tag pushes
108108
needs:
109-
- build
109+
- build
110110
runs-on: ubuntu-latest
111111

112112
environment:
113113
name: testpypi
114114
url: https://test.pypi.org/p/dirhash
115115

116116
permissions:
117-
id-token: write # IMPORTANT: mandatory for trusted publishing
117+
id-token: write # IMPORTANT: mandatory for trusted publishing
118118

119119
steps:
120-
- name: Download all the dists
121-
uses: actions/download-artifact@v4
122-
with:
123-
name: python-package-distributions
124-
path: dist/
125-
- name: Publish distribution 📦 to TestPyPI
126-
uses: pypa/gh-action-pypi-publish@release/v1
127-
with:
128-
repository-url: https://test.pypi.org/legacy/
120+
- name: Download all the dists
121+
uses: actions/download-artifact@v4
122+
with:
123+
name: python-package-distributions
124+
path: dist/
125+
- name: Publish distribution 📦 to TestPyPI
126+
uses: pypa/gh-action-pypi-publish@release/v1
127+
with:
128+
repository-url: https://test.pypi.org/legacy/

.github/workflows/test.yml

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,87 @@ on:
1313

1414
jobs:
1515
tests:
16-
1716
runs-on: ubuntu-latest
1817
strategy:
1918
fail-fast: false
2019
matrix:
2120
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
2221

2322
steps:
24-
- uses: actions/checkout@v4
25-
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v5
27-
with:
28-
python-version: ${{ matrix.python-version }}
29-
- name: Install dependencies
30-
run: |
31-
python -m pip install --upgrade pip
32-
python -m pip install tox tox-gh-actions
33-
- name: Cache tox environments
34-
id: cache-tox
35-
uses: actions/cache@v4
36-
with:
37-
path: .tox
38-
# setup.py and setup.cfg have versioning info that would impact the
39-
# tox environment. hashFiles only takes a single file path or pattern
40-
# at the moment.
41-
key: ${{ runner.os }}-${{ matrix.python-version }}-tox-${{ hashFiles('setup.py') }}-${{ hashFiles('setup.cfg') }} }}
42-
- name: Test with tox
43-
run: tox
44-
- uses: codecov/codecov-action@v4
45-
with:
46-
token: ${{ secrets.CODECOV_TOKEN }}
47-
verbose: true
23+
- uses: actions/checkout@v4
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
python -m pip install tox tox-gh-actions
32+
- name: Cache tox environments
33+
id: cache-tox
34+
uses: actions/cache@v4
35+
with:
36+
path: .tox
37+
# setup.py and setup.cfg have versioning info that would impact the
38+
# tox environment. hashFiles only takes a single file path or pattern
39+
# at the moment.
40+
key: ${{ runner.os }}-${{ matrix.python-version }}-tox-${{ hashFiles('setup.py') }}-${{ hashFiles('setup.cfg') }} }}
41+
- name: Test with tox
42+
run: tox
43+
- uses: codecov/codecov-action@v4
44+
with:
45+
token: ${{ secrets.CODECOV_TOKEN }}
46+
verbose: true
47+
48+
# Always run this last as it can push new changes and actions will not rerun.
49+
pre-commit:
50+
needs: [tests]
51+
runs-on: ubuntu-latest
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v4
55+
with:
56+
ref: ${{ github.head_ref }}
57+
58+
- name: Setup Python
59+
uses: actions/setup-python@v5
60+
with:
61+
python-version: "3.8"
62+
63+
- name: Install PreCommit
64+
run: pip install pre-commit
65+
66+
- uses: actions/cache@v4
67+
with:
68+
path: ~/.cache/pre-commit
69+
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
70+
restore-keys: |
71+
${{ runner.os }}-pre-commit-
72+
73+
- name: PreCommit
74+
id: pre-commit
75+
run: |
76+
if pre-commit run --show-diff-on-failure --color=always --all-files; then
77+
echo "failed=0" >> $GITHUB_OUTPUT
78+
else
79+
echo "failed=1" >> $GITHUB_OUTPUT
80+
fi
81+
if [ -n "$(git status -s)" ]; then
82+
echo "dirty=1" >> $GITHUB_OUTPUT
83+
else
84+
echo "dirty=0" >> $GITHUB_OUTPUT
85+
fi
86+
87+
# Run a second time to verify that everything has indeed been fixed.
88+
- name: PreCommit verify
89+
if: steps.pre-commit.outputs.failed == 1
90+
run: |
91+
pre-commit run --show-diff-on-failure --color=always --all-files
92+
93+
- name: Commit and Push to Pull Request
94+
if: steps.pre-commit.outputs.dirty == 1
95+
run: |
96+
git add .
97+
git status
98+
git commit -m "✨ ⭐ Automated commit has been added to your pull request to fix formatting! ⭐ ✨"
99+
git push origin ${{ github.head_ref }}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ venv.bak/
106106
# Pycharm
107107
.idea/
108108

109+
# VSC
110+
.vscode/
109111

110112
# Project specific
111-
benchmark/test_cases/*
113+
benchmark/test_cases/*

.pre-commit-config.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 24.3.0
4+
hooks:
5+
- id: black
6+
args: ["--target-version", "py38"]
7+
- repo: https://github.com/PyCQA/isort
8+
rev: 5.13.2
9+
hooks:
10+
- id: isort
11+
args: ["--profile", "black"]
12+
- repo: https://github.com/pre-commit/mirrors-prettier
13+
rev: v3.1.0
14+
hooks:
15+
- id: prettier
16+
args: [--prose-wrap=preserve, --print-width=90]
17+
- repo: https://github.com/pycqa/flake8
18+
rev: 7.0.0
19+
hooks:
20+
- id: flake8
21+
args: ["--max-line-length=90", "--extend-ignore=E203,W503"]
22+
- repo: https://github.com/asottile/pyupgrade
23+
rev: v3.15.2
24+
hooks:
25+
- id: pyupgrade
26+
args: ["--py38-plus"]

0 commit comments

Comments
 (0)