Repository navigation
Expand file tree
/
Copy pathtasks.py
More file actions
113 lines (84 loc) · 3.03 KB
/
Copy pathtasks.py
File metadata and controls
113 lines (84 loc) · 3.03 KB
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
import os
import shlex
import sys
from invoke import Collection, task
HAS_COLORS: bool = (sys.stderr.isatty() or os.getenv("CLICOLOR_FORCE")) and not os.getenv("NO_COLOR")
def apply_colors(msg: object, /, *, code: str) -> str:
if HAS_COLORS:
return f"\x1b[{code}m{msg}\x1b[0m"
else:
return str(msg)
def log_info(msg: object):
print(
apply_colors("INFO:", code="1;32"),
apply_colors(msg, code="1"),
)
@task
def test(ctx):
check(ctx, format=False)
ctx.run("cargo nextest run --workspace", pty=True)
miri(ctx)
run_format(ctx, check=True)
@task
def coverage(ctx):
check(ctx, format=False)
ctx.run("cargo +nightly llvm-cov nextest --all-features", pty=True)
run_format(ctx, check=True)
@task
def miri(ctx):
# https://docs.pyinvoke.org/en/3.0/concepts/invoking-tasks.html#wrapper-tasks
ctx.run(f"cargo +nightly miri nextest run --all-features {ctx.remainder}", pty=True)
@task
def bench(ctx, basic=False):
args = shlex.split(ctx.remainder)
if basic:
args.insert(0, "--bench=basic")
ctx.run(shlex.join([*shlex.split("cargo +nightly bench -p benchmark-biasedrc --all-features"), *args]), pty=True)
@task
def check(ctx, format=True):
clippy(ctx)
doc(ctx)
# by default, check formatting as well
if format:
run_format(ctx, check=True)
@task
def clippy(ctx):
ctx.run("cargo +nightly clippy --workspace --all-targets", pty=True)
ctx.run("cargo +nightly clippy --workspace --all-targets", pty=True)
@task
def doc(ctx):
"""Build documentation and check for issues"""
ctx.run("cargo doc --workspace --document-private-items --no-deps", pty=True)
@task(name="format")
def run_format(ctx, check=False):
verb = "Checking" if check else "Fixing"
log_info(f"{verb} formatting")
maybe_check = " --check" if check else ""
maybe_fix = " --fix" if not check else ""
ctx.run("cargo +nightly fmt --all" + maybe_check)
ctx.run("taplo format" + maybe_check)
ctx.run("cargo sort --grouped --no-format --workspace" + maybe_check)
# need python format for invoke.py
ctx.run("ruff format" + maybe_check)
ctx.run("ruff check --select=I" + maybe_fix) # works like isort
check_spelling(ctx, fix=False)
TYPOS_VER = "1.46" # pinned to avoid update breakage
@task(name="typos")
def check_spelling(ctx, fix=False):
maybe_write = " --write-changes" if fix else ""
ctx.run(f"uvx typos@{TYPOS_VER}" + maybe_write)
ns = Collection(test, coverage, miri, bench, check, clippy, doc, run_format, check_spelling)
ns.configure(
{
"run": {
"echo": True,
"env": {
"CLICOLOR_FORCE": "1" if HAS_COLORS else "0",
"RUST_BACKTRACE": "1",
# Due to header arithmetic, we had problems with stacked borrows in the past.
# Right now it seems to be working. If problems come up switch back to -Zmiri-tree-borrows.
"MIRIFLAGS": "-Zmiri-strict-provenance -Zmiri-env-forward=RUST_BACKTRACE",
},
}
}
)