Skip to content

Commit dd282b7

Browse files
committed
Lint Python code with ruff instead of flake8
1 parent f3744fe commit dd282b7

File tree

12 files changed

+37
-26
lines changed

12 files changed

+37
-26
lines changed

.circleci/config.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ jobs:
1717
steps:
1818
- checkout
1919
- run: python --version ; pip --version ; pwd ; ls -l
20-
- run: pip install black codespell flake8 ruff
20+
- run: pip install black codespell ruff
2121
- run: codespell -L queenland,uint
22-
# stop the build if there are Python syntax errors or undefined names
23-
- run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
24-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
25-
- run: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
22+
- run: ruff .
2623
- run: black . --check
2724

2825

STYLE_GUIDE.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
STYLE GUIDE
22
==============
33

4-
As a rough style guide, please lint your code with black, codespell, and flake8::
4+
As a rough style guide, please lint your code with black, codespell, and ruff::
55

6-
pip install black codespell flake8
6+
pip install black codespell ruff
77
codespell -L queenland,uint
8-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
9-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
8+
ruff .
109
black . --check
1110

1211
More up-to-date checks may be detailed in `.circleci/config.yml`.

docs/source/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
# All configuration values have a default; values that are commented out
1111
# serve to show the default.
1212

13-
import sys, os
13+
import os
14+
import sys
15+
1416
import sc2reader
1517

1618
autodoc_member_order = "bysource"

examples/sc2autosave.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ def run(args):
192192
replay = sc2reader.load_replay(path, load_level=2)
193193
except KeyboardInterrupt:
194194
raise
195-
except:
195+
except Exception as e:
196196
# Failure to parse
197+
args.log.write(f"{e!r}")
197198
file_name = os.path.basename(path)
198199
directory = make_directory(args, ("parse_error",))
199200
new_path = os.path.join(directory, file_name)

ruff.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ignore = [
2+
"E402", # Module level import not at top of file
3+
"F401", # module imported but unused; consider using `importlib.util.find_spec` to test for availability
4+
"F403", # Run `removestar` on this codebase
5+
"F405", # Run `removestar` on this codebase
6+
"F841", # Run `ruff --select=F841 --fix .`
7+
]
8+
line-length=129

sc2reader/engine/plugins/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def handleUnitTypeChangeEvent(self, event, replay):
263263
replay.datapack.change_type(event.unit, event.unit_type_name, event.frame)
264264
else:
265265
self.logger.error(
266-
"Unit {} type changed at {} [{}] before it was born!".format(
266+
"Unit {} type changed at {} before it was born!".format(
267267
event.unit_id, Length(seconds=event.second)
268268
)
269269
)

sc2reader/engine/plugins/selection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def _deselect(self, selection, mode, data):
7676

7777
if mode == "Mask":
7878
# Deselect objects according to deselect mask
79-
sfilter = lambda bit_u: not bit_u[0]
79+
def sfilter(bit_u):
80+
return not bit_u[0]
81+
8082
mask = data + [False] * (selection_size - data_size)
8183
new_selection = [u for (bit, u) in filter(sfilter, zip(mask, selection))]
8284
error = data_size > selection_size

sc2reader/factories/plugins/replay.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ def toDict(replay):
8585
"is_ladder": getattr(replay, "is_ladder", False),
8686
"is_private": getattr(replay, "is_private", False),
8787
"filename": getattr(replay, "filename", None),
88-
"file_time": getattr(replay, "file_time", None),
8988
"frames": getattr(replay, "frames", None),
9089
"build": getattr(replay, "build", None),
9190
"release": getattr(replay, "release_string", None),

sc2reader/factories/sc2factory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,13 @@ def load_remote_resource_contents(self, remote_resource, **options):
266266
return resource
267267

268268
def cache_has(self, cache_key):
269-
raise NotImplemented()
269+
raise NotImplementedError()
270270

271271
def cache_get(self, cache_key):
272-
raise NotImplemented()
272+
raise NotImplementedError()
273273

274274
def cache_set(self, cache_key, value):
275-
raise NotImplemented()
275+
raise NotImplementedError()
276276

277277

278278
class FileCachedSC2Factory(CachedSC2Factory):

sc2reader/resources.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,8 +1491,8 @@ def __init__(self, header_file, filename=None, **options):
14911491

14921492
# Parse localization hashes
14931493
l18n_struct = self.data[0][4][8]
1494-
for l in l18n_struct:
1495-
parsed_hash = utils.parse_hash(l[1][0])
1496-
self.localization_urls[l[0]] = utils.get_resource_url(
1494+
for h in l18n_struct:
1495+
parsed_hash = utils.parse_hash(h[1][0])
1496+
self.localization_urls[h[0]] = utils.get_resource_url(
14971497
parsed_hash["server"], parsed_hash["hash"], parsed_hash["type"]
14981498
)

0 commit comments

Comments
 (0)