Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ jobs:
steps:
- checkout
- run: python --version ; pip --version ; pwd ; ls -l
- run: pip install black codespell flake8 ruff
- run: pip install black codespell ruff
- run: codespell -L queenland,uint
# stop the build if there are Python syntax errors or undefined names
- run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
- run: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- run: ruff .
- run: black . --check


Expand Down
7 changes: 3 additions & 4 deletions STYLE_GUIDE.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
STYLE GUIDE
==============

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

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

More up-to-date checks may be detailed in `.circleci/config.yml`.
Expand Down
4 changes: 3 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import os
import sys

import sc2reader

autodoc_member_order = "bysource"
Expand Down
3 changes: 2 additions & 1 deletion examples/sc2autosave.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ def run(args):
replay = sc2reader.load_replay(path, load_level=2)
except KeyboardInterrupt:
raise
except:
except Exception as e:
# Failure to parse
args.log.write(f"{e!r}")
file_name = os.path.basename(path)
directory = make_directory(args, ("parse_error",))
new_path = os.path.join(directory, file_name)
Expand Down
4 changes: 2 additions & 2 deletions examples/sc2store.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

from pprint import PrettyPrinter

pprint = PrettyPrinter(indent=2).pprint

from sqlalchemy import create_engine
from sqlalchemy import Column, ForeignKey, distinct, Table
from sqlalchemy import Integer, String, Sequence, DateTime
Expand All @@ -23,6 +21,8 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.associationproxy import association_proxy

pprint = PrettyPrinter(indent=2).pprint

Base = declarative_base()

party_member = Table(
Expand Down
7 changes: 7 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ignore = [
"F401", # module imported but unused; consider using `importlib.util.find_spec` to test for availability
"F403", # Run `removestar` on this codebase
"F405", # Run `removestar` on this codebase
"F841", # Run `ruff --select=F841 --fix .`
]
line-length=129
6 changes: 3 additions & 3 deletions sc2reader/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import json
import pkgutil

# These are found in Repack-MPQ/fileset.{locale}#Mods#Core.SC2Mod#{locale}.SC2Data/LocalizedData/Editor/EditorCategoryStrings.txt
# EDSTR_CATEGORY_Race
# EDSTR_PLAYERPROPS_RACE
Expand Down Expand Up @@ -101,9 +104,6 @@
}


import json
import pkgutil

attributes_json = pkgutil.get_data("sc2reader.data", "attributes.json").decode("utf8")
attributes_dict = json.loads(attributes_json)
LOBBY_PROPERTIES = dict()
Expand Down
2 changes: 1 addition & 1 deletion sc2reader/engine/plugins/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def handleUnitTypeChangeEvent(self, event, replay):
replay.datapack.change_type(event.unit, event.unit_type_name, event.frame)
else:
self.logger.error(
"Unit {} type changed at {} [{}] before it was born!".format(
"Unit {} type changed at {} before it was born!".format(
event.unit_id, Length(seconds=event.second)
)
)
Expand Down
4 changes: 3 additions & 1 deletion sc2reader/engine/plugins/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def _deselect(self, selection, mode, data):

if mode == "Mask":
# Deselect objects according to deselect mask
sfilter = lambda bit_u: not bit_u[0]
def sfilter(bit_u):
return not bit_u[0]

mask = data + [False] * (selection_size - data_size)
new_selection = [u for (bit, u) in filter(sfilter, zip(mask, selection))]
error = data_size > selection_size
Expand Down
1 change: 0 additions & 1 deletion sc2reader/factories/plugins/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def toDict(replay):
"is_ladder": getattr(replay, "is_ladder", False),
"is_private": getattr(replay, "is_private", False),
"filename": getattr(replay, "filename", None),
"file_time": getattr(replay, "file_time", None),
"frames": getattr(replay, "frames", None),
"build": getattr(replay, "build", None),
"release": getattr(replay, "release_string", None),
Expand Down
6 changes: 3 additions & 3 deletions sc2reader/factories/sc2factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ def load_remote_resource_contents(self, remote_resource, **options):
return resource

def cache_has(self, cache_key):
raise NotImplemented()
raise NotImplementedError()

def cache_get(self, cache_key):
raise NotImplemented()
raise NotImplementedError()

def cache_set(self, cache_key, value):
raise NotImplemented()
raise NotImplementedError()


class FileCachedSC2Factory(CachedSC2Factory):
Expand Down
6 changes: 3 additions & 3 deletions sc2reader/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1491,8 +1491,8 @@ def __init__(self, header_file, filename=None, **options):

# Parse localization hashes
l18n_struct = self.data[0][4][8]
for l in l18n_struct:
parsed_hash = utils.parse_hash(l[1][0])
self.localization_urls[l[0]] = utils.get_resource_url(
for h in l18n_struct:
parsed_hash = utils.parse_hash(h[1][0])
self.localization_urls[h[0]] = utils.get_resource_url(
parsed_hash["server"], parsed_hash["hash"], parsed_hash["type"]
)
3 changes: 2 additions & 1 deletion sc2reader/scripts/sc2replayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def getch():
from msvcrt import getch
except ImportError as e:
# We can't make getch happen, just dump events to the screen
getch = lambda: True
def getch():
return True


import argparse
Expand Down
12 changes: 7 additions & 5 deletions sc2reader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,14 @@ def get_files(

# If an extension is supplied, use it to do a type check
if extension:
type_check = (
lambda path: os.path.splitext(path)[1][1:].lower() == extension.lower()
)

def type_check(path):
return os.path.splitext(path)[1][1:].lower() == extension.lower()

else:
type_check = lambda n: True

def type_check(n):
return True

# os.walk can't handle file paths, only directories
if os.path.isfile(path):
Expand Down Expand Up @@ -315,7 +318,6 @@ def toDict(replay):
"is_ladder": getattr(replay, "is_ladder", False),
"is_private": getattr(replay, "is_private", False),
"filename": getattr(replay, "filename", None),
"file_time": getattr(replay, "file_time", None),
"frames": getattr(replay, "frames", None),
"build": getattr(replay, "build", None),
"release": getattr(replay, "release_string", None),
Expand Down