Skip to content

Commit

Permalink
Merge pull request #6 from pomponchik/develop
Browse files Browse the repository at this point in the history
0.0.6
  • Loading branch information
pomponchik authored Jan 7, 2024
2 parents 0f95ae9 + b652126 commit 4b90ca0
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 11 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ jobs:
shell: bash
run: pip install -r requirements_dev.txt

- name: Install the library
shell: bash
run: pip install .

- name: Run mypy
shell: bash
run: mypy cbfa --strict

- name: Run ruff
shell: bash
run: ruff cbfa
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
push:
branches:
- main

jobs:
pypi-publish:
name: upload release to PyPI
runs-on: ubuntu-latest
# Specifying a GitHub environment is optional, but strongly encouraged
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
shell: bash
run: pip install -r requirements_dev.txt

- name: Build the project
shell: bash
run: python -m build .

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build
venv
.pytest_cache
test.py
.mypy_cache
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
[![Downloads](https://static.pepy.tech/badge/cbfa/month)](https://pepy.tech/project/cbfa)
[![Downloads](https://static.pepy.tech/badge/cbfa)](https://pepy.tech/project/cbfa)
[![codecov](https://codecov.io/gh/pomponchik/cbfa/graph/badge.svg?token=7XDY2T7S68)](https://codecov.io/gh/pomponchik/cbfa)
[![Test-Package](https://github.com/pomponchik/cbfa/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/cbfa/actions/workflows/tests_and_coverage.yml)
[![Hits-of-Code](https://hitsofcode.com/github/pomponchik/cbfa?branch=main)](https://hitsofcode.com/github/pomponchik/cbfa/view?branch=main)
[![Tests](https://github.com/pomponchik/cbfa/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/cbfa/actions/workflows/tests_and_coverage.yml)
[![Python versions](https://img.shields.io/pypi/pyversions/cbfa.svg)](https://pypi.python.org/pypi/cbfa)
[![PyPI version](https://badge.fury.io/py/cbfa.svg)](https://badge.fury.io/py/cbfa)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)


Expand Down
2 changes: 1 addition & 1 deletion cbfa/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from cbfa.class_based import ClassBased # noqa: F401
from cbfa.class_based import ClassBased as ClassBased # noqa: F401
21 changes: 13 additions & 8 deletions cbfa/class_based.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from typing import Callable, Type, Optional, Any

from fastapi import FastAPI


class ClassBased:
methods = (
'get',
Expand All @@ -11,22 +16,22 @@ class ClassBased:
'patch',
)

def __init__(self, app):
def __init__(self, app: FastAPI) -> None:
self.app = app

def __call__(self, *args, **kwargs):
def decorator(Class):
def __call__(self, *args: Any, **kwargs: Any) -> Callable[[Type[Any]], Type[Any]]:
def decorator(Class: Type[Any]) -> Type[Any]:
for method_name in self.methods:
if hasattr(Class, method_name):
method = self.get_method(method_name)
if method is not None:
method = method(*args, **kwargs)
fastapi_decorator_fabrique = self.get_fastapi_decorator_fabrique(method_name)
if fastapi_decorator_fabrique is not None:
fast_api_decorator = fastapi_decorator_fabrique(*args, **kwargs)
new_method = getattr(Class, method_name)
new_method.__name__ = f'{Class.__name__.lower()}_{method_name}'
new_method = method(new_method)
new_method = fast_api_decorator(new_method)
setattr(Class, method_name, new_method)
return Class
return decorator

def get_method(self, method_name):
def get_fastapi_decorator_fabrique(self, method_name: str) -> Optional[Callable[..., Any]]:
return getattr(self.app, method_name, None)
Empty file added cbfa/py.typed
Empty file.
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ build-backend = 'setuptools.build_meta'

[project]
name = 'cbfa'
version = '0.0.5'
version = '0.0.6'
authors = [
{ name='Evgeniy Blinov', email='[email protected]' },
]
description = 'Class-based views for the FastAPI'
readme = 'README.md'
requires-python = '>=3.7'
dependencies = [
'fastapi',
]
classifiers = [
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
Expand All @@ -29,6 +32,9 @@ classifiers = [
'Framework :: FastAPI',
]

[tool.setuptools.package-data]
"cbfa" = ["py.typed"]

[project.urls]
'Source' = 'https://github.com/pomponchik/cbfa'
'Tracker' = 'https://github.com/pomponchik/cbfa/issues'
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ twine==4.0.2
wheel==0.40.0
build==0.9.0
ruff==0.0.290
mypy==1.4.1

0 comments on commit 4b90ca0

Please sign in to comment.