Skip to content

Commit

Permalink
formatting init
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Richtarik committed Apr 11, 2024
1 parent 7921fcd commit a99c054
Show file tree
Hide file tree
Showing 17 changed files with 1,929 additions and 1,932 deletions.
162 changes: 81 additions & 81 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,125 +4,125 @@ name: Publish Python Package
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]*'
- "v[0-9]+.[0-9]+.[0-9]*"

jobs:
build:
name: Build distribution
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
# NOTE: tags are not present unless triggered by tag push
# - name: Get tags
# run: git fetch --tags origin
# - name: List tags
# run: git tag --list
# TODO: somehow versioneer does not pickup the tag when workflow is not triggered by a
# tag push, getting e.g. (for sister repo scantree) scantree-0+untagged.1.gd74b1d5,
# see: https://github.com/andhus/scantree/actions/runs/7485873305/job/20375116541#step:7:42)
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
- uses: actions/checkout@v4
# NOTE: tags are not present unless triggered by tag push
# - name: Get tags
# run: git fetch --tags origin
# - name: List tags
# run: git tag --list
# TODO: somehow versioneer does not pickup the tag when workflow is not triggered by a
# tag push, getting e.g. (for sister repo scantree) scantree-0+untagged.1.gd74b1d5,
# see: https://github.com/andhus/scantree/actions/runs/7485873305/job/20375116541#step:7:42)
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: Publish to PyPI
# TODO we need to make sure the tag matches the version!
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/dirhash
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: Sign and upload to GitHub Release
needs:
- publish-to-pypi
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
publish-to-testpypi:
name: Publish to TestPyPI
if: startsWith(github.ref, 'refs/tags/') # only publish on tag pushes
if: startsWith(github.ref, 'refs/tags/') # only publish on tag pushes
needs:
- build
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/dirhash

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
102 changes: 77 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,87 @@ on:

jobs:
tests:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Cache tox environments
id: cache-tox
uses: actions/cache@v4
with:
path: .tox
# setup.py and setup.cfg have versioning info that would impact the
# tox environment. hashFiles only takes a single file path or pattern
# at the moment.
key: ${{ runner.os }}-${{ matrix.python-version }}-tox-${{ hashFiles('setup.py') }}-${{ hashFiles('setup.cfg') }} }}
- name: Test with tox
run: tox
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Cache tox environments
id: cache-tox
uses: actions/cache@v4
with:
path: .tox
# setup.py and setup.cfg have versioning info that would impact the
# tox environment. hashFiles only takes a single file path or pattern
# at the moment.
key: ${{ runner.os }}-${{ matrix.python-version }}-tox-${{ hashFiles('setup.py') }}-${{ hashFiles('setup.cfg') }} }}
- name: Test with tox
run: tox
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true

# Always run this last as it can push new changes and actions will not rerun.
pre-commit:
needs: [tests]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.8"

- name: Install PreCommit
run: pip install pre-commit

- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
${{ runner.os }}-pre-commit-
- name: PreCommit
id: pre-commit
run: |
if pre-commit run --show-diff-on-failure --color=always --all-files; then
echo "failed=0" >> $GITHUB_OUTPUT
else
echo "failed=1" >> $GITHUB_OUTPUT
fi
if [ -n "$(git status -s)" ]; then
echo "dirty=1" >> $GITHUB_OUTPUT
else
echo "dirty=0" >> $GITHUB_OUTPUT
fi
# Run a second time to verify that everything has indeed been fixed.
- name: PreCommit verify
if: steps.pre-commit.outputs.failed == 1
run: |
pre-commit run --show-diff-on-failure --color=always --all-files
- name: Commit and Push to Pull Request
if: steps.pre-commit.outputs.dirty == 1
run: |
git add .
git status
git commit -m "✨ ⭐ Automated commit has been added to your pull request to fix formatting! ⭐ ✨"
git push origin ${{ github.head_ref }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ venv.bak/
# Pycharm
.idea/

# VSC
.vscode/

# Project specific
benchmark/test_cases/*
benchmark/test_cases/*
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
args: ["--target-version", "py38"]
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
args: [--prose-wrap=preserve, --print-width=90]
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
args: ["--max-line-length=90", "--extend-ignore=E203,W503"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args: ["--py38-plus"]
Loading

0 comments on commit a99c054

Please sign in to comment.