Skip to content

Commit 443d415

Browse files
committed
Minor refactor
1 parent 97bf2b5 commit 443d415

File tree

1 file changed

+9
-9
lines changed
  • onlinejudge_verify/languages

1 file changed

+9
-9
lines changed

onlinejudge_verify/languages/rust.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,11 @@ def from_dep_kind(cls, kind: str):
114114
for dependency_namespace, name_in_toml in names_in_toml:
115115
if (dependency_namespace, name_in_toml) in explicit_names_in_toml:
116116
# If the `name_in_toml` is explicitly renamed one, it equals to the `extern_crate_name`.
117-
unused_packages[dependency_namespace].add(dependencies[dependency_namespace][name_in_toml]['id'])
117+
unused_package = dependencies[dependency_namespace][name_in_toml]['id']
118118
else:
119119
# Otherwise, it equals to the `package.name`.
120-
unused_packages[dependency_namespace].add(next(p['id'] for p in dependencies[dependency_namespace].values() if p['name'] == name_in_toml))
120+
unused_package = next(p['id'] for p in dependencies[dependency_namespace].values() if p['name'] == name_in_toml)
121+
unused_packages[dependency_namespace].add(unused_package)
121122

122123
# Finally, adds source files related to the depended crates except:
123124
#
@@ -170,21 +171,20 @@ def _related_source_files(metadata: Dict[str, Any]) -> Dict[pathlib.Path, Frozen
170171
)
171172
for d_file_path in d_file_paths:
172173
with open(d_file_path) as d_file:
173-
d = d_file.read()
174-
found = False
175-
for line in d.splitlines():
174+
d_file_content = d_file.read()
175+
for line in d_file_content.splitlines():
176176
words = line.split(':')
177177
if len(words) == 2 and pathlib.Path(words[0]) == d_file_path:
178178
# Ignores paths like `/dev/null` or `/usr/share/foo/bar` (if any).
179179
paths = [pathlib.Path(metadata['workspace_root'], s) for s in words[1].split() if not pathlib.Path(s).is_absolute()]
180180
if paths[:1] == [pathlib.Path(target['src_path'])]:
181181
ret[paths[0]] = frozenset(paths[1:])
182-
found = True
183182
break
184-
if found:
185-
break
183+
else:
184+
continue
185+
break
186186
else:
187-
logger.warning('no `.d` file for `%s`', target["name"])
187+
logger.error('no `.d` file for `%s`', target["name"])
188188

189189
_related_source_files_by_workspace[pathlib.Path(metadata['workspace_root'])] = ret
190190
return ret

0 commit comments

Comments
 (0)