-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathtasks.py
155 lines (131 loc) · 4.26 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Copyright Modal Labs 2022
# Copyright (c) Modal Labs 2022
import inspect
import subprocess
if not hasattr(inspect, "getargspec"):
# Workaround until invoke supports Python 3.11
# https://github.com/pyinvoke/invoke/issues/833#issuecomment-1293148106
inspect.getargspec = inspect.getfullargspec # type: ignore
import datetime
import os
import sys
from pathlib import Path
from invoke import task
year = datetime.date.today().year
copyright_header_start = "# Copyright Modal Labs"
copyright_header_full = f"{copyright_header_start} {year}"
@task
def protoc(ctx):
py_protoc = (
f"{sys.executable} -m grpc_tools.protoc"
+ " --python_out=. --grpclib_python_out=. --grpc_python_out=. --mypy_out=. --mypy_grpc_out=."
)
print(py_protoc)
ctx.run(f"{py_protoc} -I . " "modal_proto/api.proto " "modal_proto/options.proto ")
@task
def lint(ctx):
ctx.run("ruff .", pty=True)
@task
def mypy(ctx):
ctx.run("mypy .", pty=True)
@task
def check_copyright(ctx, fix=False):
invalid_files = []
d = str(Path(__file__).parent)
for root, dirs, files in os.walk(d):
# jupytext notebook formatted .py files can't be detected as notebooks if we put a copyright comment at the top
fns = [
os.path.join(root, fn)
for fn in files
if fn.endswith(".py") and not fn.endswith(".notebook.py") and "/site-packages/" not in root
]
for fn in fns:
first_line = open(fn).readline()
if not first_line.startswith(copyright_header_start):
if fix:
print(f"Fixing {fn}...")
content = copyright_header_full + "\n" + open(fn).read()
with open(fn, "w") as g:
g.write(content)
else:
invalid_files.append(fn)
if invalid_files:
for fn in invalid_files:
print("Missing copyright:", fn)
raise Exception(
f"{len(invalid_files)} are missing copyright headers!" " Please run `inv check-copyright --fix`"
)
@task
def update_build_number(ctx, new_build_number):
new_build_number = int(new_build_number)
from modal_version import build_number as current_build_number
assert new_build_number > current_build_number
with open("modal_version/_version_generated.py", "w") as f:
f.write(
f"""\
{copyright_header_full}
build_number = {new_build_number}
"""
)
@task
def create_alias_package(ctx):
from modal_version import __version__
os.makedirs("alias-package", exist_ok=True)
with open("alias-package/setup.py", "w") as f:
f.write(
f"""\
{copyright_header_full}
from setuptools import setup
setup(version="{__version__}")
"""
)
with open("alias-package/setup.cfg", "w") as f:
f.write(
f"""\
[metadata]
name = modal-client
author = Modal Labs
author_email = [email protected]
description = Legacy name for the Modal client
long_description = This is a legacy compatibility package that just requires the `modal` client library.
In versions before 0.51, the official name of the client library was called `modal-client`.
We have renamed it to `modal`, but this library is kept updated for compatibility.
long_description_content_type = text/markdown
project_urls =
Homepage = https://modal.com
[options]
install_requires =
modal=={__version__}
"""
)
with open("alias-package/pyproject.toml", "w") as f:
f.write(
"""\
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
"""
)
@task
def type_stubs(ctx):
# we only generate type stubs for modules that contain synchronicity wrapped types
# TODO(erikbern): can we automate this list?
modules = [
"modal.app",
"modal.client",
"modal.cls",
"modal.dict",
"modal.environments",
"modal.functions",
"modal.image",
"modal.mount",
"modal.network_file_system",
"modal.object",
"modal.proxy",
"modal.queue",
"modal.sandbox",
"modal.secret",
"modal.stub",
"modal.volume",
]
subprocess.check_call(["python", "-m", "synchronicity.type_stubs", *modules])