Skip to content

Commit acddc63

Browse files
authored
Merge pull request #195 from cclauss/ruff
Lint Python code with ruff instead of flake8
2 parents fc781d2 + 01b1cac commit acddc63

File tree

14 files changed

+41
-31
lines changed

14 files changed

+41
-31
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)

examples/sc2store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
from pprint import PrettyPrinter
1313

14-
pprint = PrettyPrinter(indent=2).pprint
15-
1614
from sqlalchemy import create_engine
1715
from sqlalchemy import Column, ForeignKey, distinct, Table
1816
from sqlalchemy import Integer, String, Sequence, DateTime
@@ -23,6 +21,8 @@
2321
from sqlalchemy.ext.declarative import declarative_base
2422
from sqlalchemy.ext.associationproxy import association_proxy
2523

24+
pprint = PrettyPrinter(indent=2).pprint
25+
2626
Base = declarative_base()
2727

2828
party_member = Table(

ruff.toml

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

sc2reader/constants.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import json
2+
import pkgutil
3+
14
# These are found in Repack-MPQ/fileset.{locale}#Mods#Core.SC2Mod#{locale}.SC2Data/LocalizedData/Editor/EditorCategoryStrings.txt
25
# EDSTR_CATEGORY_Race
36
# EDSTR_PLAYERPROPS_RACE
@@ -101,9 +104,6 @@
101104
}
102105

103106

104-
import json
105-
import pkgutil
106-
107107
attributes_json = pkgutil.get_data("sc2reader.data", "attributes.json").decode("utf8")
108108
attributes_dict = json.loads(attributes_json)
109109
LOBBY_PROPERTIES = dict()

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),

0 commit comments

Comments
 (0)