Skip to content

Commit 19dbf3a

Browse files
committed
initial commit
0 parents  commit 19dbf3a

39 files changed

Lines changed: 1624 additions & 0 deletions

.editorconfig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
8+
[*.{py, lua}]
9+
charset = utf-8
10+
11+
[*.{py, lua, sh}]
12+
indent_style = space
13+
indent_size = 4
14+
trim_trailing_whitespace = true
15+
ij_continuation_indent_size = 8
16+
17+
[Makefile]
18+
indent_style = tab
19+
20+
[{package.json,.gitlab-ci.yml}]
21+
indent_style = space
22+
indent_size = 2
23+
24+
[{env,.env,venv,.venv}/**]
25+
indent_style = none
26+
indent_size = none
27+
end_of_line = none
28+
trim_trailing_whitespace = none
29+
charset = none

.gitignore

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
.hypothesis/
50+
.pytest_cache/
51+
.ruff_cache/
52+
53+
# Translations
54+
*.mo
55+
*.pot
56+
57+
# Django stuff:
58+
*.log
59+
local_settings.py
60+
db.sqlite3
61+
62+
# Flask stuff:
63+
instance/
64+
.webassets-cache
65+
66+
# Scrapy stuff:
67+
.scrapy
68+
69+
# Sphinx documentation
70+
docs/_build/
71+
72+
# PyBuilder
73+
target/
74+
75+
# Jupyter Notebook
76+
.ipynb_checkpoints
77+
78+
# IPython
79+
profile_default/
80+
ipython_config.py
81+
82+
# pyenv
83+
.python-version
84+
85+
# celery beat schedule file
86+
celerybeat-schedule
87+
88+
# SageMath parsed files
89+
*.sage.py
90+
91+
# Environments
92+
.env
93+
.venv
94+
env/
95+
venv/
96+
ENV/
97+
env.bak/
98+
venv.bak/
99+
100+
# Spyder project settings
101+
.spyderproject
102+
.spyproject
103+
104+
# Rope project settings
105+
.ropeproject
106+
107+
# mkdocs documentation
108+
/site
109+
110+
# mypy
111+
.mypy_cache/
112+
.dmypy.json
113+
dmypy.json
114+
115+
# Pyre type checker
116+
.pyre/
117+
118+
# IDE
119+
.idea
120+
.vscode
121+
122+
# Custom
123+
/demo
124+
/env*
125+
/venv*
126+
pip-wheel-metadata
127+
local

.gitlab-ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include:
2+
project: mnt/ci
3+
file: modules/python.yaml

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 0.1.0
2+
3+
* Initial release

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.PHONY: mypy ruff style style-check test lint pytest
2+
3+
package?=extapi tests
4+
5+
style:
6+
python -m ruff format $(package)
7+
python -m ruff check --select I --fix $(package)
8+
9+
mypy:
10+
python -m mypy --enable-error-code ignore-without-code $(package)
11+
12+
ruff:
13+
python -m ruff check $(package)
14+
15+
style-check:
16+
python -m ruff format --check --diff $(package)
17+
18+
deptry:
19+
deptry . -e 'env|\.env|venv|\.venv|\..+'
20+
21+
lint: style-check ruff mypy deptry
22+
23+
pytest:
24+
python -m pytest .
25+
26+
test: lint pytest

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# extapi

extapi/__init__.py

Whitespace-only changes.

extapi/_helpers.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import asyncio
2+
import functools
3+
from collections.abc import Awaitable, Callable
4+
from typing import Any, ParamSpec, TypeVar, cast, overload
5+
6+
P = ParamSpec("P")
7+
R = TypeVar("R")
8+
9+
10+
@overload
11+
async def execute_sync_async(
12+
f: Callable[P, Awaitable[R]], *args: P.args, **kwargs: P.kwargs
13+
) -> R: ...
14+
15+
16+
@overload
17+
async def execute_sync_async(
18+
f: Callable[P, R], *args: P.args, **kwargs: P.kwargs
19+
) -> R: ...
20+
21+
22+
async def execute_sync_async(
23+
f: Callable[P, Awaitable[R]] | Callable[P, R], *args: P.args, **kwargs: P.kwargs
24+
) -> R:
25+
if not is_async_callable(f):
26+
return cast(R, f(*args, **kwargs))
27+
28+
return await cast(Callable[P, Awaitable[R]], f)(*args, **kwargs)
29+
30+
31+
def is_async_callable(obj: Any) -> bool:
32+
while isinstance(obj, functools.partial):
33+
obj = obj.func
34+
35+
return asyncio.iscoroutinefunction(obj) or (
36+
callable(obj) and asyncio.iscoroutinefunction(obj.__call__)
37+
)

extapi/http/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)