Skip to content

Commit

Permalink
feat: py312
Browse files Browse the repository at this point in the history
  • Loading branch information
klen committed Jul 31, 2024
1 parent 5189905 commit 9416758
Show file tree
Hide file tree
Showing 9 changed files with 1,355 additions and 120 deletions.
36 changes: 36 additions & 0 deletions .git-commits.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---

convention:
commitTypes:
- feat
- fix
- perf
- refactor
- style
- test
- build
- ops
- docs
- merge
commitScopes: []
releaseTagGlobPattern: v[0-9]*.[0-9]*.[0-9]*

changelog:
commitTypes:
- feat
- fix
- perf
- merge
includeInvalidCommits: true
commitScopes: []
commitIgnoreRegexPattern: "^WIP "
headlines:
feat: Features
fix: Bug Fixes
perf: Performance Improvements
merge: Merges
breakingChange: BREAKING CHANGES
commitUrl: https://github.com/klen/muffin-oauth/commit/%commit%
commitRangeUrl: https://github.com/klen/muffin-oauth/compare/%from%...%to%?diff=split
issueRegexPattern: "#[0-9]+"
issueUrl: https://github.com/klen/muffin-oauth/issues/%issue%
41 changes: 7 additions & 34 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,16 @@ jobs:
steps:

- uses: actions/checkout@main
with:
fetch-depth: 2

- uses: actions/setup-python@main
with:
python-version: '3.11'

- name: Build package
run: |
pip install build
python -m build
- uses: actions/upload-artifact@main
with:
name: dist
path: dist

release:
runs-on: ubuntu-latest
needs: [build]
steps:

- name: Download a distribution artifact
uses: actions/download-artifact@main
with:
name: dist
path: dist

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi }}
- name: Install poetry
run: pipx install poetry
- name: Setup poetry
run: poetry config pypi-token.pypi ${{ secrets.pypi }}
- name: Build and publish
run: poetry publish --build

notify:
runs-on: ubuntu-latest
needs: release
needs: build
steps:

- name: Notify Success
Expand Down
21 changes: 10 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,27 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- name: Checkout changes
uses: actions/checkout@main
- uses: actions/checkout@main
- name: install poetry
run: pipx install poetry

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@main
with:
cache: pip
cache: poetry
python-version: ${{ matrix.python-version }}

- name: Setup env
run: |
pip install -e .[tests]
- name: Install requirements
run: poetry install --with tests

- name: Code check
run: |
ruff muffin_oauth
- name: Check code
run: poetry run ruff check muffin_oauth

- name: Test with pytest
run: pytest tests.py
run: poetry run pytest

notify:
runs-on: ubuntu-latest
Expand Down
104 changes: 76 additions & 28 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,83 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

fail_fast: true
default_install_hook_types: [commit-msg, pre-commit, pre-push]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.253

- repo: https://github.com/qoomon/git-conventional-commits
rev: 'v2.6.5'
hooks:
- id: ruff
name: Check code
args: [--fix, --exit-non-zero-on-fix]
- id: conventional-commits
args: ["-c", ".git-commits.yaml"]
stages: ["commit-msg"]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-case-conflict
stages: ["pre-commit"]
- id: check-merge-conflict
stages: ["pre-commit"]
- id: check-added-large-files
stages: ["pre-commit"]
- id: check-ast
stages: ["pre-commit"]
- id: check-executables-have-shebangs
stages: ["pre-commit"]
- id: check-symlinks
stages: ["pre-commit"]
- id: check-toml
stages: ["pre-commit"]
- id: check-yaml
stages: ["pre-commit"]
- id: debug-statements
stages: ["pre-commit"]
- id: end-of-file-fixer
stages: ["pre-commit"]
- id: trailing-whitespace
stages: ["pre-commit"]

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
stages: ["pre-commit"]

- repo: https://github.com/python-poetry/poetry
rev: '1.5.0'
hooks:
- id: poetry-check
files: ^(.*/)?pyproject\.toml$
stages: ["pre-commit"]
- id: poetry-lock
files: ^(.*/)?(poetry\.lock|pyproject\.toml)$
args: ["--no-update"]
stages: ["pre-commit"]

- repo: local
hooks:
- id: check-types
name: Check types
entry: mypy
language: system
pass_filenames: false
- id: check-code
name: Refactor code
entry: refurb muffin_oauth
language: system
pass_filenames: false
- id: run-tests
name: Run tests
entry: pytest tests.py
language: system
pass_filenames: false
- id: ruff
name: ruff
entry: poetry run ruff check muffin_oauth
language: system
pass_filenames: false
files: \.py$
stages: ["pre-commit"]

- id: mypy
name: mypy
entry: poetry run mypy
language: system
pass_filenames: false
files: \.py$
stages: ["pre-push"]

- id: pytest
name: pytest
entry: poetry run pytest
language: system
pass_filenames: false
files: \.py$
stages: ["pre-push"]
26 changes: 16 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ clean:
.PHONY: release
VERSION?=minor
# target: release - Bump version
release: $(VIRTUAL_ENV)
@$(VIRTUAL_ENV)/bin/bump2version $(VERSION)
@git checkout master
@git merge develop
@git checkout develop
@git push origin develop master
@git push --tags
release:
git checkout develop
git pull
git checkout master
git merge develop
git pull
@poetry version $(VERSION)
git commit -am "build(release): `poetry version -s`"
git tag `poetry version -s`
git checkout develop
git merge master
git push --tags origin develop master

.PHONY: minor
minor: release
Expand All @@ -45,10 +50,11 @@ major:
# Development
# =============

$(VIRTUAL_ENV): pyproject.toml
$(VIRTUAL_ENV): poetry.lock .pre-commit-config.yaml
@[ -d $(VIRTUAL_ENV) ] || python -m venv $(VIRTUAL_ENV)
@$(VIRTUAL_ENV)/bin/pip install -e .[tests,dev,example]
@$(VIRTUAL_ENV)/bin/pre-commit install --hook-type pre-push
@poetry install --with tests,dev,example
@poetry run pre-commit install
@poetry self add poetry-bumpversion
@touch $(VIRTUAL_ENV)

.PHONY: t test
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Muffin-OAuth
Requirements
=============

- python >= 3.7
- python >= 3.9

.. _installation:

Expand Down
22 changes: 15 additions & 7 deletions muffin_oauth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""Support OAuth in Muffin Framework."""

from __future__ import annotations

import base64
import hmac
from hashlib import sha256, sha512
from random import SystemRandom
from typing import Any, Mapping, Optional, Tuple
from typing import Any, ClassVar, Mapping, Optional

from aioauth_client import Client, ClientRegistry
from muffin import Request, ResponseError, ResponseRedirect
Expand All @@ -22,13 +25,12 @@ class OAuthError(Exception):
"""Implement an exception during OAUTH process."""



class Plugin(BasePlugin):

"""Support OAuth."""

name = "oauth"
defaults: Mapping[str, Any] = {
defaults: ClassVar = {
"clients": {},
"redirect_uri": None,
"secret": "important:replace_me_asap!",
Expand All @@ -50,7 +52,9 @@ def authorize(self, client: Client, redirect_uri: Optional[str] = None, **params
state = sha256(str(random()).encode("ascii")).hexdigest()
state = f"{ state }.{ sign(state, self.cfg.secret) }"
return client.get_authorize_url(
redirect_uri=redirect_uri, state=state, **params,
redirect_uri=redirect_uri,
state=state,
**params,
)

async def login(
Expand All @@ -60,7 +64,7 @@ async def login(
redirect_uri: Optional[str] = None,
headers: Optional[Mapping[str, str]] = None,
**params,
) -> Tuple[Client, str, Any]:
) -> tuple[Client, str, Any]:
"""Process login with OAuth.
:param client_name: A name one of configured clients
Expand Down Expand Up @@ -90,7 +94,9 @@ async def login(

# Get access token
token, data = await client.get_access_token(
code, redirect_uri=redirect_uri, headers=headers,
code,
redirect_uri=redirect_uri,
headers=headers,
)
return client, token, data

Expand All @@ -102,7 +108,9 @@ def refresh(self, client_name: str, refresh_token: str, **params):
"""
client = self.client(client_name, logger=self.app.logger)
return client.get_access_token(
refresh_token, grant_type="refresh_token", **params,
refresh_token,
grant_type="refresh_token",
**params,
)


Expand Down
Loading

0 comments on commit 9416758

Please sign in to comment.