From 7ec12186ff6b002c4472db2bd9e4cb5077ea3564 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Mon, 31 Jan 2022 13:41:21 -0800 Subject: [PATCH 1/4] fix black formatting from StyleCheck 625 --- sc2reader/scripts/sc2replayer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sc2reader/scripts/sc2replayer.py b/sc2reader/scripts/sc2replayer.py index 011cffc6..3d8212ca 100755 --- a/sc2reader/scripts/sc2replayer.py +++ b/sc2reader/scripts/sc2replayer.py @@ -28,7 +28,6 @@ def getch(): termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm) fcntl.fcntl(fd, fcntl.F_SETFL, oldflags) - except ImportError as e: try: # Oops, we might be on windows, try this one From a5d2e3cd98aadfc913845f7b70a907fe21beb6f5 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Mon, 31 Jan 2022 13:46:42 -0800 Subject: [PATCH 2/4] style guide documentation updates --- STYLE_GUIDE.rst | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/STYLE_GUIDE.rst b/STYLE_GUIDE.rst index 26b0bb8f..9f202210 100644 --- a/STYLE_GUIDE.rst +++ b/STYLE_GUIDE.rst @@ -1,11 +1,15 @@ STYLE GUIDE ============== -As a rough style guide, please lint your code with pep8:: +As a rough style guide, please lint your code with black, codespell, and flake8:: - pip install pep8 - pep8 --ignore E501,E226,E241 sc2reader + pip install black codespell flake8 + 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 + black . --check +More up-to-date checks may be detailed in `.circleci/config.yml`. All files should start with the following:: @@ -18,10 +22,7 @@ All files should start with the following:: All imports should be absolute. -All string formatting sound be done in the following style:: +All string formatting should be done in the following style:: "my {0} formatted {1} string {2}".format("super", "python", "example") "the {x} style of {y} is also {z}".format(x="dict", y="arguments", z="acceptable") - -The format argument index numbers are important for 2.6 support. ``%`` formatting is not allowed for 3.x support - From a345354b3f64887fad1bd7d83359edf20a73354a Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Mon, 31 Jan 2022 13:51:52 -0800 Subject: [PATCH 3/4] more black updates --- docs/source/conf.py | 8 ++++---- sc2reader/engine/plugins/creeptracker.py | 2 +- sc2reader/events/tracker.py | 2 +- sc2reader/readers.py | 2 +- sc2reader/resources.py | 6 +++--- sc2reader/utils.py | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 2d9a7214..17164624 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -43,8 +43,8 @@ master_doc = "index" # General information about the project. -project = u"sc2reader" -copyright = u"2011-2013" +project = "sc2reader" +copyright = "2011-2013" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -182,7 +182,7 @@ # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ("index", "sc2reader.tex", u"sc2reader Documentation", u"Graylin Kim", "manual") + ("index", "sc2reader.tex", "sc2reader Documentation", "Graylin Kim", "manual") ] # The name of an image file (relative to this directory) to place at the top of @@ -213,4 +213,4 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [("index", "sc2reader", u"sc2reader Documentation", [u"Graylin Kim"], 1)] +man_pages = [("index", "sc2reader", "sc2reader Documentation", ["Graylin Kim"], 1)] diff --git a/sc2reader/engine/plugins/creeptracker.py b/sc2reader/engine/plugins/creeptracker.py index 8dde77c9..5a56b4f2 100644 --- a/sc2reader/engine/plugins/creeptracker.py +++ b/sc2reader/engine/plugins/creeptracker.py @@ -173,7 +173,7 @@ def radius_to_map_positions(self, radius): # Sample a square area using the radius for x in range(-radius, radius): for y in range(-radius, radius): - if (x ** 2 + y ** 2) <= (radius * radius): + if (x**2 + y**2) <= (radius * radius): output_coordinates.append((x, y)) return output_coordinates diff --git a/sc2reader/events/tracker.py b/sc2reader/events/tracker.py index a3e3935e..6220d5fe 100644 --- a/sc2reader/events/tracker.py +++ b/sc2reader/events/tracker.py @@ -17,7 +17,7 @@ class TrackerEvent(Event): def __init__(self, frames): #: The frame of the game this event was applied #: Ignore all but the lowest 32 bits of the frame - self.frame = frames % 2 ** 32 + self.frame = frames % 2**32 #: The second of the game (game time not real time) this event was applied self.second = self.frame >> 4 diff --git a/sc2reader/readers.py b/sc2reader/readers.py index 496f66e5..83c3a2ea 100644 --- a/sc2reader/readers.py +++ b/sc2reader/readers.py @@ -561,7 +561,7 @@ def __call__(self, data, replay): ) # Don't want to do this more than once - SINGLE_BIT_MASKS = [0x1 << i for i in range(2 ** 9)] + SINGLE_BIT_MASKS = [0x1 << i for i in range(2**9)] def read_selection_bitmask(self, data, mask_length): bits_left = mask_length diff --git a/sc2reader/resources.py b/sc2reader/resources.py index 9b4e95b9..428e9cc9 100644 --- a/sc2reader/resources.py +++ b/sc2reader/resources.py @@ -421,11 +421,11 @@ def load_details(self): # the value required to get the adjusted timestamp. We know the upper # limit for any adjustment number so use that to distinguish between # the two cases. - if details["utc_adjustment"] < 10 ** 7 * 60 * 60 * 24: - self.time_zone = details["utc_adjustment"] / (10 ** 7 * 60 * 60) + if details["utc_adjustment"] < 10**7 * 60 * 60 * 24: + self.time_zone = details["utc_adjustment"] / (10**7 * 60 * 60) else: self.time_zone = (details["utc_adjustment"] - details["file_time"]) / ( - 10 ** 7 * 60 * 60 + 10**7 * 60 * 60 ) self.game_length = self.length diff --git a/sc2reader/utils.py b/sc2reader/utils.py index 4c67992f..93787212 100644 --- a/sc2reader/utils.py +++ b/sc2reader/utils.py @@ -45,7 +45,7 @@ def windows_to_unix(windows_time): # This windows timestamp measures the number of 100 nanosecond periods since # January 1st, 1601. First we subtract the number of nanosecond periods from # 1601-1970, then we divide by 10^7 to bring it back to seconds. - return int((windows_time - 116444735995904000) / 10 ** 7) + return int((windows_time - 116444735995904000) / 10**7) @loggable From f7ff804435b86f88e683f9e34ffdc5c587cc8820 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Mon, 31 Jan 2022 20:41:16 -0800 Subject: [PATCH 4/4] reference f-strings --- STYLE_GUIDE.rst | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/STYLE_GUIDE.rst b/STYLE_GUIDE.rst index 9f202210..14f91df5 100644 --- a/STYLE_GUIDE.rst +++ b/STYLE_GUIDE.rst @@ -21,8 +21,4 @@ All files should start with the following:: All imports should be absolute. - -All string formatting should be done in the following style:: - - "my {0} formatted {1} string {2}".format("super", "python", "example") - "the {x} style of {y} is also {z}".format(x="dict", y="arguments", z="acceptable") +All string formatting should be done with f-strings. See https://docs.python.org/3/reference/lexical_analysis.html#f-strings