Skip to content

Commit 09fd93b

Browse files
committed
Add codegen template
1 parent 567bdc4 commit 09fd93b

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎src/django_unasyncify/_codegen.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
This file is managed by django-unasyncify and should not be
3+
directly modified. Future runs of django-unasyncify will
4+
likely overwrite any changes you make to this file.
5+
"""
6+
7+
8+
def from_codegen(f):
9+
"""
10+
This indicates that the function was gotten from codegen, and
11+
should not be directly modified
12+
"""
13+
return f
14+
15+
16+
def generate_unasynced(*args, **kwargs):
17+
"""
18+
This indicates we should unasync this function/method
19+
"""
20+
21+
def wrapper(f):
22+
return f
23+
24+
# @generate_unasynced()
25+
if not args and not kwargs:
26+
return wrapper
27+
28+
# @generate_unasynced
29+
if args:
30+
assert (
31+
len(args) == 1 and len(kwargs) == 0
32+
), "Invalid calling convention for generate_unasynced"
33+
return args[0]
34+
35+
if kwargs:
36+
raise NotImplementedError("Handling kwargs...")
37+
38+
39+
# this marker gets replaced by False when unasyncifying a function
40+
IS_ASYNC = True
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pathlib import Path
2+
from shutil import copyfile
3+
4+
5+
def ensure_codegen_template(target_location):
6+
"""
7+
Insert the codegen template to where it's needed
8+
"""
9+
codegen_location = Path(__file__).parent / "_codegen.py"
10+
copyfile(src=codegen_location, dst=target_location)

0 commit comments

Comments
 (0)