Skip to content

Commit ae78c11

Browse files
committed
ci: swith type checker from ignoring files to specific lines
1 parent 7d29203 commit ae78c11

25 files changed

+83
-111
lines changed

pyproject.toml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,4 @@ known-first-party = ["taskgraph"]
3434

3535
[tool.pyright]
3636
include = ["src"]
37-
exclude = [ # TODO fix errors in these files
38-
"src/taskgraph/decision.py",
39-
"src/taskgraph/docker.py",
40-
"src/taskgraph/files_changed.py",
41-
"src/taskgraph/generator.py",
42-
"src/taskgraph/graph.py",
43-
"src/taskgraph/main.py",
44-
"src/taskgraph/morph.py",
45-
"src/taskgraph/parameters.py",
46-
"src/taskgraph/taskgraph.py",
47-
"src/taskgraph/actions/cancel.py",
48-
"src/taskgraph/actions/cancel_all.py",
49-
"src/taskgraph/actions/rebuild_cached_tasks.py",
50-
"src/taskgraph/actions/util.py",
51-
"src/taskgraph/optimize/base.py",
52-
"src/taskgraph/run-task/robustcheckout.py",
53-
"src/taskgraph/transforms/fetch.py",
54-
"src/taskgraph/transforms/task.py",
55-
"src/taskgraph/transforms/run/run_task.py",
56-
"src/taskgraph/util/cached_tasks.py",
57-
"src/taskgraph/util/decision.py",
58-
"src/taskgraph/util/python_path.py",
59-
"src/taskgraph/util/schema.py",
60-
"src/taskgraph/util/taskcluster.py",
61-
"src/taskgraph/util/vcs.py",
62-
"src/taskgraph/util/workertypes.py",
63-
"src/taskgraph/util/yaml.py",
64-
]
6537
reportIncompatibleMethodOverride = false

src/taskgraph/actions/cancel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def cancel_action(parameters, graph_config, input, task_group_id, task_id):
2929
try:
3030
cancel_task(task_id, use_proxy=True)
3131
except requests.HTTPError as e:
32-
if e.response.status_code == 409:
32+
if e.response.status_code == 409: # type: ignore
3333
# A 409 response indicates that this task is past its deadline. It
3434
# cannot be cancelled at this time, but it's also not running
3535
# anymore, so we can ignore this error.

src/taskgraph/actions/cancel_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def do_cancel_task(task_id):
3838
try:
3939
cancel_task(task_id, use_proxy=True)
4040
except requests.HTTPError as e:
41-
if e.response.status_code == 409:
41+
if e.response.status_code == 409: # type: ignore
4242
# A 409 response indicates that this task is past its deadline. It
4343
# cannot be cancelled at this time, but it's also not running
4444
# anymore, so we can ignore this error.

src/taskgraph/actions/rebuild_cached_tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def rebuild_cached_tasks_action(
2222
)
2323
cached_tasks = [
2424
label
25-
for label, task in full_task_graph.tasks.items()
25+
for label, task in full_task_graph.tasks.items() # type: ignore
2626
if task.attributes.get("cached_task", False)
2727
]
2828
if cached_tasks:

src/taskgraph/actions/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def fetch_action(task_id):
6060
run_label_to_id = get_artifact(task_id, "public/label-to-taskid.json")
6161
label_to_taskid.update(run_label_to_id)
6262
except HTTPError as e:
63-
if e.response.status_code != 404:
63+
if e.response.status_code != 404: # type: ignore
6464
raise
6565
logger.debug(f"No label-to-taskid.json found for {task_id}: {e}")
6666

@@ -79,7 +79,7 @@ def fetch_cron(task_id):
7979
run_label_to_id = get_artifact(task_id, "public/label-to-taskid.json")
8080
label_to_taskid.update(run_label_to_id)
8181
except HTTPError as e:
82-
if e.response.status_code != 404:
82+
if e.response.status_code != 404: # type: ignore
8383
raise
8484
logger.debug(f"No label-to-taskid.json found for {task_id}: {e}")
8585

@@ -160,7 +160,7 @@ def create_tasks(
160160

161161
target_graph = full_task_graph.graph.transitive_closure(to_run)
162162
target_task_graph = TaskGraph(
163-
{l: modifier(full_task_graph[l]) for l in target_graph.nodes}, target_graph
163+
{l: modifier(full_task_graph[l]) for l in target_graph.nodes}, target_graph # type: ignore
164164
)
165165
target_task_graph.for_each_task(update_parent)
166166
if decision_task_id and decision_task_id != os.environ.get("TASK_ID"):

src/taskgraph/decision.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def write_artifact(filename, data):
359359
import gzip
360360

361361
with gzip.open(path, "wb") as f:
362-
f.write(json.dumps(data))
362+
f.write(json.dumps(data)) # type: ignore
363363
else:
364364
raise TypeError(f"Don't know how to write to {filename}")
365365

src/taskgraph/docker.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ def download_and_modify_image():
173173
req = get_session().get(url, stream=True)
174174
req.raise_for_status()
175175

176-
with zstd.ZstdDecompressor().stream_reader(req.raw) as ifh:
176+
with zstd.ZstdDecompressor().stream_reader(req.raw) as ifh: # type: ignore
177177
tarin = tarfile.open(
178178
mode="r|",
179179
fileobj=ifh,
180-
bufsize=zstd.DECOMPRESSION_RECOMMENDED_OUTPUT_SIZE,
180+
bufsize=zstd.DECOMPRESSION_RECOMMENDED_OUTPUT_SIZE, # type: ignore
181181
)
182182

183183
# Stream through each member of the downloaded tar file individually.
@@ -194,8 +194,8 @@ def download_and_modify_image():
194194
# image tags.
195195
if member.name == "repositories":
196196
# Read and parse repositories
197-
repos = json.loads(reader.read())
198-
reader.close()
197+
repos = json.loads(reader.read()) # type: ignore
198+
reader.close() # type: ignore
199199

200200
# If there is more than one image or tag, we can't handle it
201201
# here.
@@ -217,16 +217,16 @@ def download_and_modify_image():
217217
# Then emit its content.
218218
remaining = member.size
219219
while remaining:
220-
length = min(remaining, zstd.DECOMPRESSION_RECOMMENDED_OUTPUT_SIZE)
221-
buf = reader.read(length)
220+
length = min(remaining, zstd.DECOMPRESSION_RECOMMENDED_OUTPUT_SIZE) # type: ignore
221+
buf = reader.read(length) # type: ignore
222222
remaining -= len(buf)
223223
yield buf
224224
# Pad to fill a 512 bytes block, per tar format.
225225
remainder = member.size % 512
226226
if remainder:
227227
yield ("\0" * (512 - remainder)).encode("utf-8")
228228

229-
reader.close()
229+
reader.close() # type: ignore
230230

231231
subprocess.run(
232232
["docker", "image", "load"], input=b"".join(download_and_modify_image())

src/taskgraph/generator.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def __init__(
138138
self._write_artifacts = write_artifacts
139139

140140
# start the generator
141-
self._run = self._run()
141+
self._run = self._run() # type: ignore
142142
self._run_results = {}
143143

144144
@property
@@ -295,7 +295,7 @@ def _run(self):
295295
for kind in kinds.values():
296296
for dep in kind.config.get("kind-dependencies", []):
297297
edges.add((kind.name, dep, "kind-dependency"))
298-
kind_graph = Graph(set(kinds), edges)
298+
kind_graph = Graph(set(kinds), edges) # type: ignore
299299

300300
if target_kinds:
301301
kind_graph = kind_graph.transitive_closure(
@@ -321,7 +321,7 @@ def _run(self):
321321
raise Exception("duplicate tasks with label " + task.label)
322322
all_tasks[task.label] = task
323323
logger.info(f"Generated {len(new_tasks)} tasks for kind {kind_name}")
324-
full_task_set = TaskGraph(all_tasks, Graph(set(all_tasks), set()))
324+
full_task_set = TaskGraph(all_tasks, Graph(set(all_tasks), set())) # type: ignore
325325
yield self.verify("full_task_set", full_task_set, graph_config, parameters)
326326

327327
logger.info("Generating full task graph")
@@ -334,7 +334,7 @@ def _run(self):
334334
)
335335
edges.add((t.label, dep, depname))
336336

337-
full_task_graph = TaskGraph(all_tasks, Graph(full_task_set.graph.nodes, edges))
337+
full_task_graph = TaskGraph(all_tasks, Graph(full_task_set.graph.nodes, edges)) # type: ignore
338338
logger.info(
339339
"Full task graph contains %d tasks and %d dependencies"
340340
% (len(full_task_set.graph.nodes), len(edges))
@@ -343,13 +343,13 @@ def _run(self):
343343

344344
logger.info("Generating target task set")
345345
target_task_set = TaskGraph(
346-
dict(all_tasks), Graph(set(all_tasks.keys()), set())
346+
dict(all_tasks), Graph(set(all_tasks.keys()), set()) # type: ignore
347347
)
348348
for fltr in filters:
349349
old_len = len(target_task_set.graph.nodes)
350350
target_tasks = set(fltr(target_task_set, parameters, graph_config))
351351
target_task_set = TaskGraph(
352-
{l: all_tasks[l] for l in target_tasks}, Graph(target_tasks, set())
352+
{l: all_tasks[l] for l in target_tasks}, Graph(target_tasks, set()) # type: ignore
353353
)
354354
logger.info(
355355
"Filter %s pruned %d tasks (%d remain)"
@@ -363,7 +363,7 @@ def _run(self):
363363
if parameters["enable_always_target"]:
364364
always_target_tasks = {
365365
t.label
366-
for t in full_task_graph.tasks.values()
366+
for t in full_task_graph.tasks.values() # type: ignore
367367
if t.attributes.get("always_target")
368368
if parameters["enable_always_target"] is True
369369
or t.kind in parameters["enable_always_target"]
@@ -372,12 +372,12 @@ def _run(self):
372372
always_target_tasks = set()
373373
logger.info(
374374
"Adding %d tasks with `always_target` attribute"
375-
% (len(always_target_tasks) - len(always_target_tasks & target_tasks))
375+
% (len(always_target_tasks) - len(always_target_tasks & target_tasks)) # type: ignore
376376
)
377-
requested_tasks = target_tasks | always_target_tasks
377+
requested_tasks = target_tasks | always_target_tasks # type: ignore
378378
target_graph = full_task_graph.graph.transitive_closure(requested_tasks)
379379
target_task_graph = TaskGraph(
380-
{l: all_tasks[l] for l in target_graph.nodes}, target_graph
380+
{l: all_tasks[l] for l in target_graph.nodes}, target_graph # type: ignore
381381
)
382382
yield self.verify(
383383
"target_task_graph", target_task_graph, graph_config, parameters
@@ -422,7 +422,7 @@ def _run(self):
422422
def _run_until(self, name):
423423
while name not in self._run_results:
424424
try:
425-
k, v = next(self._run)
425+
k, v = next(self._run) # type: ignore
426426
except StopIteration:
427427
raise AttributeError(f"No such run result {name}")
428428
self._run_results[k] = v

src/taskgraph/graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def transitive_closure(self, nodes, reverse=False):
6868
add_nodes = {(left if reverse else right) for (left, right, _) in add_edges}
6969
new_nodes = nodes | add_nodes
7070
new_edges = edges | add_edges
71-
return Graph(new_nodes, new_edges)
71+
return Graph(new_nodes, new_edges) # type: ignore
7272

7373
def _visit(self, reverse):
7474
queue = collections.deque(sorted(self.nodes))

src/taskgraph/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ def get_filtered_taskgraph(taskgraph, tasksregex, exclude_keys):
8888
if regexprogram.match(dep):
8989
filterededges.add((key, dep, depname))
9090

91-
taskgraph = TaskGraph(filteredtasks, Graph(set(filteredtasks), filterededges))
91+
taskgraph = TaskGraph(filteredtasks, Graph(set(filteredtasks), filterededges)) # type: ignore
9292

9393
if exclude_keys:
94-
for label, task in taskgraph.tasks.items():
94+
for label, task in taskgraph.tasks.items(): # type: ignore
9595
task = task.to_json()
9696
for key in exclude_keys:
9797
obj = task
@@ -490,7 +490,7 @@ def show_taskgraph(options):
490490
base_path = os.path.join(
491491
diffdir, f"{options['graph_attr']}_{base_rev_file}"
492492
)
493-
cur_path = os.path.join(diffdir, f"{options['graph_attr']}_{cur_rev_file}")
493+
cur_path = os.path.join(diffdir, f"{options['graph_attr']}_{cur_rev_file}") # type: ignore
494494

495495
params_name = None
496496
if len(parameters) > 1:
@@ -862,7 +862,7 @@ def init_taskgraph(options):
862862
context = {"project_name": root.name}
863863

864864
try:
865-
repo_url = repo.get_url(remote=repo.remote_name)
865+
repo_url = repo.get_url(remote=repo.remote_name) # type: ignore
866866
except RuntimeError:
867867
repo_url = ""
868868

@@ -895,7 +895,7 @@ def init_taskgraph(options):
895895
directory="template",
896896
extra_context=context,
897897
no_input=options["no_input"],
898-
output_dir=root.parent,
898+
output_dir=root.parent, # type: ignore
899899
overwrite_if_exists=True,
900900
)
901901

0 commit comments

Comments
 (0)