Skip to content

Commit 2f60079

Browse files
committed
Linting fixes
1 parent 075123f commit 2f60079

File tree

6 files changed

+32
-32
lines changed

6 files changed

+32
-32
lines changed

src/hammeraddons/bsp_transform/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Transformations that can be applied to the BSP file."""
22
from typing import Protocol
3+
from typing_extensions import deprecated
4+
35
from collections.abc import Awaitable, Callable, Container, Mapping
46
from pathlib import Path
5-
from warnings import deprecated
67
import inspect
78

89
import attrs

src/hammeraddons/build_fgd_assets.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
"""Creates the subset of assets needed for an input FGD to work.
22
"""
33
from __future__ import annotations
4+
45
from pathlib import Path
56
import argparse
6-
import sys
77
import os
8+
import shutil
9+
import sys
810

9-
from srctools.fgd import (
10-
FGD, AutoVisgroup, EntAttribute, EntityDef, EntityTypes, Helper, HelperExtAppliesTo,
11-
HelperTypes, KVDef, Snippet, ValueTypes, match_tags, validate_tags,
12-
)
13-
from srctools.filesys import File, RawFileSystem
11+
from srctools.fgd import FGD
12+
from srctools.filesys import RawFileSystem, FileSystemChain
1413
from srctools.packlist import PackList
1514

1615

@@ -21,7 +20,7 @@ def action_build(input_path: Path, output_path: Path, asset_path: Path) -> None:
2120
asset_fsys = RawFileSystem(str(asset_path))
2221
fgd = FGD()
2322
fgd.parse_file(fgd_fsys, fgd_fsys[str(input_path)], eval_bases=False, eval_extensions=False, encoding='iso-8859-1')
24-
pack = PackList(asset_fsys)
23+
pack = PackList(FileSystemChain(asset_fsys))
2524

2625
# Iterate over all entries, build a list of assets
2726
for classname in fgd.entities:
@@ -34,20 +33,19 @@ def action_build(input_path: Path, output_path: Path, asset_path: Path) -> None:
3433
pack.eval_dependencies()
3534

3635
# Output all the files we can to our new output
37-
for file in pack._files.values():
36+
for file in pack:
3837
try:
3938
sys_file = asset_fsys[file.filename]
4039
except FileNotFoundError:
4140
print(f'WARNING: "{file.filename}" not packed!')
4241
continue
4342

4443
print(file.filename)
45-
with sys_file.open_bin() as f:
46-
data = f.read()
44+
with sys_file.open_bin() as fsrc:
4745
new_path = Path(os.path.join(str(output_path), file.filename))
4846
new_path.parent.mkdir(parents=True, exist_ok=True)
49-
with open(new_path, "wb") as out:
50-
out.write(data)
47+
with open(new_path, "wb") as fdest:
48+
shutil.copyfileobj(fsrc, fdest)
5149

5250

5351
def main(args: list[str] | None = None) -> None:
@@ -81,5 +79,6 @@ def main(args: list[str] | None = None) -> None:
8179

8280
action_build(input_path, output_path, asset_path)
8381

82+
8483
if __name__ == '__main__':
8584
main(sys.argv[1:])

src/hammeraddons/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import sys
1111

1212
from srctools import AtomicWriter, Keyvalues, conv_int, logger, NoKeyError
13-
from srctools.dmx import Element, ValueType as DMXType, Attribute as DMAttribute
13+
from srctools.dmx import Element, ValueType as DMXType
1414
from srctools.filesys import FileSystem, FileSystemChain, RawFileSystem, VPKFileSystem
1515
from srctools.game import Game
1616
from srctools.steam import find_app

src/hammeraddons/fgd_reports.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def ordering(game: str) -> tuple:
140140
header = row_temp.format('Game', 'Base', 'Point', 'Brush')
141141
print('Counted entities.')
142142

143-
with open(report_dir / 'counts.txt', 'w') as f:
143+
with open(report_dir / 'counts.txt', 'w', encoding='utf8') as f:
144144
f.write(header)
145145
print('-' * len(header), file=f)
146146

@@ -153,12 +153,12 @@ def ordering(game: str) -> tuple:
153153
))
154154

155155
f.write('\n\nBases:\n')
156-
for base, count in sorted(base_uses.items(), key=lambda x: (len(x[1]), x[0])):
156+
for base, used in sorted(base_uses.items(), key=lambda x: (len(x[1]), x[0])):
157157
ent = fgd[base]
158158
if ent.type is EntityTypes.BASE and (
159159
ent.keyvalues or ent.outputs or ent.inputs
160160
):
161-
f.write(f'{base} {len(count)} {count if len(count) == 1 else '...'}\n')
161+
f.write(f'{base} {len(used)} {used if len(used) == 1 else '...'}\n')
162162

163163
for kind_name, count_map in (
164164
('keyvalues', kv_counts),
@@ -168,7 +168,7 @@ def ordering(game: str) -> tuple:
168168
('desc', desc_counts)
169169
):
170170
count = 0
171-
with open(report_dir / f'duplicate_{kind_name}.txt', 'w') as f:
171+
with open(report_dir / f'duplicate_{kind_name}.txt', 'w', encoding='utf8') as f:
172172
for key, info in sorted(count_map.items(), key=lambda v: len(v[1]), reverse=True):
173173
if len(info) <= 2:
174174
continue
@@ -215,14 +215,14 @@ def report_factories(
215215
missing = dump_classes - defined_classes
216216
all_classes |= defined_classes
217217
used_classes |= dump_classes
218-
with open(report_dir / f'factories_{game.lower()}.txt', 'w') as rep_f:
218+
with open(report_dir / f'factories_{game.lower()}.txt', 'w', encoding='utf8') as rep_f:
219219
rep_f.write('Extraneous definitions: \n')
220220
pprint(sorted(extra), rep_f, compact=True)
221221
rep_f.write('\n\nMissing definitions: \n')
222222
pprint(sorted(missing), rep_f, compact=True)
223223

224224
unused = all_classes - used_classes
225-
with open(report_dir / f'factories_unused.txt', 'w') as rep_f:
225+
with open(report_dir / 'factories_unused.txt', 'w', encoding='utf8') as rep_f:
226226
pprint(sorted(unused), rep_f, compact=True)
227227
print(f'Checked entity factories. {len(unused)} totally unused.')
228228

@@ -248,7 +248,7 @@ def report_undefined_resources(fgd: FGD, report_dir: Path) -> None:
248248
class_res[frozenset(appliesto)].append(ent.classname)
249249
missing_count += 1
250250

251-
with open(report_dir / 'undefined_resources.txt', 'w') as f:
251+
with open(report_dir / 'undefined_resources.txt', 'w', encoding='utf8') as f:
252252
for tags_list, classnames in class_res.items():
253253
classnames.sort()
254254
f.write(f'{', '.join(tags_list)} = {pformat(classnames, compact=True)}\n')
@@ -271,7 +271,7 @@ def report(msg: str) -> None:
271271
f.write(f'Ent {ent.classname} res error: {msg}\n')
272272
res_ctx = ResourceCtx(fgd=fgd)
273273

274-
with open(report_dir / 'missing_resources.txt', 'w') as f:
274+
with open(report_dir / 'missing_resources.txt', 'w', encoding='utf8') as f:
275275
for ent in fgd.entities.values():
276276
# Get them all, checking validity in the process.
277277
for _ in ent.get_resources(res_ctx, ent=None, on_error=report):
@@ -313,7 +313,7 @@ def check_ent_sprites(used: dict[str, list[str]], f: TextIO, ent: EntityDef) ->
313313
def report_helper_reuse(fgd: FGD, report_dir: Path) -> None:
314314
"""Report missing or reused helpers."""
315315
mdl_or_sprites: dict[str, list[str]] = defaultdict(list)
316-
with open(report_dir / 'helper_reuse.txt', 'w') as f:
316+
with open(report_dir / 'helper_reuse.txt', 'w', encoding='utf8') as f:
317317
for ent in fgd:
318318
if ent.type is not EntityTypes.BASE and ent.type is not EntityTypes.BRUSH and not ent.is_alias:
319319
check_ent_sprites(mdl_or_sprites, f, ent)
@@ -337,13 +337,13 @@ def check_parents(done: set[EntityDef], repeat: set[EntityDef], ent: EntityDef)
337337
assert isinstance(base, EntityDef), (ent, ent.bases)
338338
check_parents(done, repeat, base)
339339

340-
with open(report_dir / 'repeated_bases.txt', 'w') as f:
340+
with open(report_dir / 'repeated_bases.txt', 'w', encoding='utf8') as f:
341341
for ent in fgd:
342342
done: set[EntityDef] = set()
343343
repeat: set[EntityDef] = set()
344344
check_parents(done, repeat, ent)
345345
if repeat:
346-
print(
346+
f.write(
347347
f'Repeated bases: {ent.classname} = '
348348
f'{[ent.classname for ent in repeat]}, '
349349
f'all={[ent.classname for ent in done]}'

src/hammeraddons/unify_fgd.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from __future__ import annotations
66

77
from typing import Any
8-
from collections.abc import Callable, MutableMapping, Iterator
9-
from collections import Counter, defaultdict, ChainMap, deque
8+
from collections.abc import Callable, Iterator
9+
from collections import Counter, defaultdict, ChainMap
1010
from pathlib import Path
1111
import argparse
1212
import itertools
@@ -16,7 +16,7 @@
1616
from srctools import fgd
1717
from srctools.fgd import (
1818
FGD, AutoVisgroup, EntAttribute, EntityDef, EntityTypes, TagsSet, Helper, HelperExtAppliesTo,
19-
HelperTypes, KVDef, ResourceCtx, Snippet, ValueTypes, match_tags, validate_tags
19+
HelperTypes, KVDef, Snippet, ValueTypes, match_tags, validate_tags
2020
)
2121
from srctools.filesys import File, RawFileSystem
2222
from srctools.math import Vec, format_float
@@ -684,6 +684,7 @@ def add_tag(tags: TagsSet, new_tag: str) -> TagsSet:
684684

685685
return frozenset(tag_set)
686686

687+
687688
def iter_tags(fgd: FGD) -> Iterator[str]:
688689
"""Iterate over all tags defined in the FGD."""
689690
for ent in fgd:

src/strata_merge.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ def main() -> None:
104104
for fname in MERGE_DIR.iterdir():
105105
fname.unlink()
106106

107-
with open(REPORT_DIR / '.gitignore', 'w') as f:
108-
f.write('*')
107+
(REPORT_DIR / '.gitignore').write_text('*')
109108

110109
bases = {
111110
ent.classname.casefold()
@@ -159,10 +158,10 @@ def main() -> None:
159158
continue
160159

161160
folder = MERGE_DIR if classname in MERGED else REPORT_DIR
162-
with open(folder / f'{classname}.diff', 'w') as f:
161+
with open(folder / f'{classname}.diff', 'w', encoding='utf8') as f:
163162
f.writelines(difflib.unified_diff(
164163
ha_text.splitlines(keepends=True), strata_text.splitlines(keepends=True),
165-
f'HammerAddons', f'Strata', n=999,
164+
'HammerAddons', 'Strata', n=999,
166165
))
167166
if folder is REPORT_DIR:
168167
count += 1

0 commit comments

Comments
 (0)