Skip to content

Commit

Permalink
Opt: switch to Poetry and Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed Feb 16, 2023
1 parent 995dcad commit ec031b5
Show file tree
Hide file tree
Showing 39 changed files with 985 additions and 345 deletions.
108 changes: 63 additions & 45 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,86 @@
name: check
name: Checks

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- master

env:
ANSICON: 1
FORCE_COLOR: 1

jobs:
check:
name: Check
runs-on: ubuntu-latest

strategy:
max-parallel: 6
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- 'pypy-3.8'
- 'pypy-3.9'

steps:
- uses: actions/cache@v3
name: Cache pip
- name: "📥 Checkout"
uses: actions/checkout@v3
with:
path: "~/.cache/pip"
key: pip-${{ runner.os }}-${{ matrix.python-version }}
fetch-depth: 0

- uses: actions/cache@v3
name: Cache mypy
- name: "✨ Install Poetry"
run: |
pipx install poetry
pipx inject poetry poetry-dynamic-versioning
- name: 🐍 Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
path: ".mypy_cache"
key: mypy-${{ runner.os }}-${{ matrix.python-version }}
python-version: ${{ matrix.python-version }}
cache: poetry

- uses: actions/cache@v3
name: Cache pytest
- name: "🗃 Cache"
if: success() || failure()
uses: actions/cache@v3
with:
path: ".pytest_cache"
key: pytest-${{ runner.os }}-${{ matrix.python-version }}
path: |
.mypy_cache
.pytest_cache
.ruff_cache
key: ${{ runner.os }}-${{ matrix.python-version }}-check

- name: Checkout
uses: actions/checkout@v3
- name: "📥 Install the package"
run: make install

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: "🪄 Linter: Black"
run: make lint/black

- name: Install
run: make venv
- name: "🪄 Linter: Ruff"
if: success() || failure()
run: make lint/ruff

- name: Test
run: make unittests
- name: "🪄 Linter: mypy"
if: success() || failure()
run: make lint/mypy

- name: Lint
run: make lint
- name: "🧪 Tests"
if: success() || failure()
run: poetry run pytest tests --test-redis

- name: Coveralls
uses: coverallsapp/github-action@master
- name: "📤 Codecov"
if: success() || failure()
uses: codecov/codecov-action@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: ${{ matrix.python-version }}
parallel: true
path-to-lcov: .coverage.lcov
token: ${{ secrets.CODECOV_TOKEN }}
env_vars: PYTHON
name: Python ${{ matrix.python-version }}
files: coverage.xml
fail_ci_if_error: true

finish:
needs: check
if: always()
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
- name: "📦 Build and publish package: dry run"
if: success() || failure()
run: poetry publish --build --dry-run --ansi
61 changes: 36 additions & 25 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
name: publish
name: Publish

on:
release:
types: [published]

env:
ANSICON: 1
FORCE_COLOR: 1

jobs:
build-n-publish:
publish:
runs-on: ubuntu-latest

steps:
- name: ⬇️ Checkout
uses: actions/checkout@v3

- name: 🔖 Get history and tags
run: |
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: 🐍 Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: ⚙️ Install
run: pip install build

- name: 🏗 Build
run: python -m build --sdist --wheel --outdir dist/ .

- name: 📦 Publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: 📥 Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: 📝 Build changelog
id: changelog
uses: Bullrich/generate-release-changelog@master
env:
REPO: ${{ github.repository }}

- name: 📤 Update release
uses: tubone24/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_name: ${{ github.ref_name }}
body: ${{ steps.changelog.outputs.changelog }}

- name: "✨ Install Poetry"
run: |
pipx install poetry
pipx inject poetry poetry-dynamic-versioning
- name: 📦 Build package
run: poetry build --ansi

- name: 📤 Publish package
run: poetry publish --ansi
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.benchmarks

# Created by https://www.toptal.com/developers/gitignore/api/linux,macos,python,windows,sublimetext,visualstudiocode,intellij+all
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,python,windows,sublimetext,visualstudiocode,intellij+all
# Created by https://www.toptal.com/developers/gitignore/api/linux,macos,python,windows,sublimetext,intellij+all,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,python,windows,sublimetext,intellij+all,visualstudiocode

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
Expand Down Expand Up @@ -305,6 +305,8 @@ cython_debug/
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

### SublimeText ###
# Cache files for Sublime Text
Expand Down Expand Up @@ -384,4 +386,4 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/linux,macos,python,windows,sublimetext,visualstudiocode,intellij+all
# End of https://www.toptal.com/developers/gitignore/api/linux,macos,python,windows,sublimetext,intellij+all,visualstudiocode
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright © 2011-2020 `pure-protobuf` contributors
Copyright © 2011-2023 `pure-protobuf` contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
85 changes: 36 additions & 49 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,67 +1,54 @@
# Please follow the Makefile style guide.
# http://clarkgrubb.com/makefile-style-guide

BIN := venv/bin

.PHONY: build
build:
$(BIN)/python -m build --sdist --wheel

.PHONY: publish
publish:
$(BIN)/python -m twine upload dist/*
.PHONY: all
all: install lint test build

.PHONY: clean
clean:
find . -type d -name __pycache__ -delete
rm -rf venv .mypy_cache .pytest_cache build dist *.egg-info .coverage .benchmarks
rm -rf .ruff_cache .mypy_cache .pytest_cache
find . -name "*.pyc" -delete
rm -rf *.egg-info build
rm -rf coverage*.xml .coverage
rm -rf .benchmarks

.PHONY: venv
venv:
python3 -m venv venv
$(BIN)/pip install --upgrade pip wheel
$(BIN)/pip install -e.[dev]
.PHONY: install
install:
poetry install --all-extras --with dev

.PHONY: test check
test check: unittests lint
.PHONY: lint
lint: lint/ruff lint/black lint/mypy

.PHONY: unittests
unittests:
$(BIN)/coverage run --source=pure_protobuf -m pytest --benchmark-disable tests
$(BIN)/coverage lcov -o .coverage.lcov
$(BIN)/coverage xml -o .coverage.xml
$(BIN)/coverage html -d .coverage.html
.PHONY: lint/black
lint/black:
poetry run black --diff --check pure_protobuf tests

.PHONY: benchmark
benchmark:
$(BIN)/pytest --benchmark-only --benchmark-columns=mean,stddev,median,ops --benchmark-warmup=on tests
.PHONY: lint/ruff
lint/ruff:
poetry run ruff pure_protobuf tests

.PHONY: format
format: format/isort format/black
.PHONY: lint/mypy
lint/mypy:
poetry run mypy pure_protobuf tests

.PHONY: format/isort
format/isort:
$(BIN)/isort pure_protobuf tests
.PHONY: format
format: format/ruff format/black

.PHONY: format/black
format/black:
$(BIN)/black pure_protobuf tests

.PHONY: lint
lint: lint/flake8 lint/isort lint/mypy lint/format
poetry run black pure_protobuf tests

.PHONY: lint/flake8
lint/flake8:
$(BIN)/flake8 pure_protobuf tests
.PHONY: format/ruff
format/ruff:
poetry run ruff --fix pure_protobuf tests

.PHONY: lint/isort
lint/isort:
$(BIN)/isort -c --diff pure_protobuf tests
.PHONY: test
test:
poetry run pytest tests --benchmark-disable

.PHONY: lint/mypy
lint/mypy:
$(BIN)/mypy pure_protobuf tests
.PHONY: benchmark
benchmark:
poetry run pytest tests --benchmark-only --benchmark-columns=mean,stddev,median,ops --benchmark-warmup=on

.PHONY: lint/format
lint/format:
$(BIN)/black --check --diff pure_protobuf tests
.PHONY: build
build:
poetry build
Loading

0 comments on commit ec031b5

Please sign in to comment.