-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
99 lines (74 loc) · 3.24 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
import os
import shutil
import sys
from invoke import task, Context, Collection
import subprocess
def get_allowed_doc_languages():
build_docs_file_name = "scripts/build-docs.sh"
try:
with open(build_docs_file_name, "r") as f:
for line in f:
if "for lang in" in line:
langs = line.split("in")[1].strip().split(";")[0].split()
return [lang.strip() for lang in langs]
except FileNotFoundError:
print(f"No {build_docs_file_name} file found")
return ["en", "bg", "de", "es", "fr", "ru"] # default
ALLOWED_DOC_LANGUAGES = get_allowed_doc_languages()
ALLOWED_VERSION_TYPES = ["release", "bug", "feature"]
@task
def version(c: Context):
"""Show the current version."""
with open("src/async-s3/__about__.py", "r") as f:
version_line = f.readline()
version_num = version_line.split('"')[1]
print(version_num)
return version_num
def ver_task_factory(version_type: str):
@task
def ver(c: Context):
"""Bump the version."""
c.run(f"./scripts/verup.sh {version_type}")
return ver
@task
def compile_requirements(c: Context):
"Convert requirements.in to requirements.txt and requirements.dev.txt."
start_time = subprocess.check_output(["date", "+%s"]).decode().strip()
c.run("uv pip compile requirements.in --output-file=requirements.txt --upgrade") # --refresh-package
reqs_time = subprocess.check_output(["date", "+%s"]).decode().strip()
c.run("uv pip compile requirements.dev.in --output-file=requirements.dev.txt --upgrade")
end_time = subprocess.check_output(["date", "+%s"]).decode().strip()
print(f"Req's compilation time: {int(reqs_time) - int(start_time)} seconds")
print(f"Req's dev compilation time: {int(end_time) - int(reqs_time)} seconds")
print(f"Total execution time: {int(end_time) - int(start_time)} seconds")
c.run("scripts/include_pyproject_requirements.py requirements.in")
@task(pre=[compile_requirements])
def reqs(c: Context):
"""Upgrade requirements including pre-commit."""
c.run("pre-commit autoupdate")
c.run("uv pip install -r requirements.dev.txt")
def docs_task_factory(language: str):
@task
def docs(c: Context):
"""Docs preview for the language specified."""
c.run("open -a 'Google Chrome' http://127.0.0.1:8000/async-s3/")
c.run(f"scripts/docs-render-config.sh {language}")
if language != "en":
shutil.rmtree(f"./docs/src/{language}/images", ignore_errors=True)
shutil.copytree("./docs/src/en/images", f"./docs/src/{language}/images")
shutil.copy("./docs/src/en/reference.md", f"./docs/src/{language}/reference.md")
c.run("mkdocs serve -f docs/_mkdocs.yml")
return docs
@task
def uv(c: Context):
"""Install or upgrade uv."""
c.run("curl -LsSf https://astral.sh/uv/install.sh | sh")
@task
def pre(c):
"""Run pre-commit checks"""
c.run("pre-commit run --verbose --all-files")
namespace = Collection.from_module(sys.modules[__name__])
for name in ALLOWED_VERSION_TYPES:
namespace.add_task(ver_task_factory(name), name=f"ver-{name}")
for name in ALLOWED_DOC_LANGUAGES:
namespace.add_task(docs_task_factory(name), name=f"docs-{name}")