Skip to content

Commit 791c766

Browse files
committed
Raise line length to 120 and reformat all files.
Added additional checks for formatting in workflows.
1 parent f4e0e4a commit 791c766

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1609
-2696
lines changed

.github/workflows/python-lint.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ jobs:
3232
uses: liskin/gh-problem-matcher-wrap@v1
3333
with:
3434
linters: flake8
35-
run: flake8 tcod/
35+
run: flake8 scripts/ tcod/
3636
- name: MyPy
3737
if: always()
3838
uses: liskin/gh-problem-matcher-wrap@v1
3939
with:
4040
linters: mypy
41-
run: mypy --show-column-numbers tcod/
41+
run: mypy --show-column-numbers scripts/ tcod/
4242
- name: isort
4343
uses: liskin/gh-problem-matcher-wrap@v1
4444
with:
4545
linters: isort
46-
run: isort tcod/ tests/ --check
46+
run: isort scripts/ tcod/ tests/ *.py --check
4747
- name: isort (examples)
4848
uses: liskin/gh-problem-matcher-wrap@v1
4949
with:
5050
linters: isort
5151
run: isort examples/ --check --thirdparty tcod
5252
- name: Black
5353
run: |
54-
black --check tcod/
54+
black --check examples/ scripts/ tcod/ tests/ *.py

build_libtcod.py

Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,15 @@
3434

3535
# Regular expressions to parse the headers for cffi.
3636
RE_COMMENT = re.compile(r"\s*/\*.*?\*/|\s*//*?$", re.DOTALL | re.MULTILINE)
37-
RE_CPLUSPLUS = re.compile(
38-
r"#ifdef __cplusplus.*?#endif.*?$", re.DOTALL | re.MULTILINE
39-
)
40-
RE_PREPROCESSOR = re.compile(
41-
r"(?!#define\s+\w+\s+\d+$)#.*?(?<!\\)$", re.DOTALL | re.MULTILINE
42-
)
37+
RE_CPLUSPLUS = re.compile(r"#ifdef __cplusplus.*?#endif.*?$", re.DOTALL | re.MULTILINE)
38+
RE_PREPROCESSOR = re.compile(r"(?!#define\s+\w+\s+\d+$)#.*?(?<!\\)$", re.DOTALL | re.MULTILINE)
4339
RE_INCLUDE = re.compile(r'#include "([^"]*)"')
4440
RE_TAGS = re.compile(
4541
r"TCODLIB_C?API|TCOD_PUBLIC|TCOD_NODISCARD|TCOD_DEPRECATED_NOMESSAGE"
4642
r"|(TCOD_DEPRECATED|TCODLIB_FORMAT)\([^)]*\)|__restrict"
4743
)
4844
RE_VAFUNC = re.compile(r".*\(.*va_list.*\);")
49-
RE_INLINE = re.compile(
50-
r"(^.*?inline.*?\(.*?\))\s*\{.*?\}$", re.DOTALL | re.MULTILINE
51-
)
45+
RE_INLINE = re.compile(r"(^.*?inline.*?\(.*?\))\s*\{.*?\}$", re.DOTALL | re.MULTILINE)
5246

5347

5448
class ParsedHeader:
@@ -121,8 +115,7 @@ def resolve_dependencies(
121115
if not unresolved & resolved:
122116
raise RuntimeError(
123117
"Could not resolve header load order.\n"
124-
"Possible cyclic dependency with the unresolved headers:\n%s"
125-
% (unresolved,)
118+
"Possible cyclic dependency with the unresolved headers:\n%s" % (unresolved,)
126119
)
127120
unresolved -= resolved
128121
return result
@@ -176,9 +169,7 @@ def unpack_sdl2(version: str) -> str:
176169
assert sdl2_arc.endswith(".dmg")
177170
subprocess.check_call(["hdiutil", "mount", sdl2_arc])
178171
subprocess.check_call(["mkdir", "-p", sdl2_dir])
179-
subprocess.check_call(
180-
["cp", "-r", "/Volumes/SDL2/SDL2.framework", sdl2_dir]
181-
)
172+
subprocess.check_call(["cp", "-r", "/Volumes/SDL2/SDL2.framework", sdl2_dir])
182173
subprocess.check_call(["hdiutil", "unmount", "/Volumes/SDL2"])
183174
return sdl2_path
184175

@@ -234,9 +225,7 @@ def unpack_sdl2(version: str) -> str:
234225
else:
235226
matches = re.findall(
236227
r"-I(\S+)",
237-
subprocess.check_output(
238-
["sdl2-config", "--cflags"], universal_newlines=True
239-
),
228+
subprocess.check_output(["sdl2-config", "--cflags"], universal_newlines=True),
240229
)
241230
assert matches
242231

@@ -249,9 +238,7 @@ def unpack_sdl2(version: str) -> str:
249238
if sys.platform == "win32":
250239
include_dirs.append(SDL2_INCLUDE)
251240
ARCH_MAPPING = {"32bit": "x86", "64bit": "x64"}
252-
SDL2_LIB_DIR = os.path.join(
253-
SDL2_BUNDLE_PATH, "lib/", ARCH_MAPPING[BITSIZE]
254-
)
241+
SDL2_LIB_DIR = os.path.join(SDL2_BUNDLE_PATH, "lib/", ARCH_MAPPING[BITSIZE])
255242
library_dirs.append(SDL2_LIB_DIR)
256243
SDL2_LIB_DEST = os.path.join("tcod", ARCH_MAPPING[BITSIZE])
257244
if not os.path.exists(SDL2_LIB_DEST):
@@ -287,21 +274,9 @@ def fix_header(filepath: str) -> None:
287274
define_macros.append(("HAVE_UNISTD_H", 1))
288275

289276
if sys.platform not in ["win32", "darwin"]:
290-
extra_parse_args += (
291-
subprocess.check_output(
292-
["sdl2-config", "--cflags"], universal_newlines=True
293-
)
294-
.strip()
295-
.split()
296-
)
277+
extra_parse_args += subprocess.check_output(["sdl2-config", "--cflags"], universal_newlines=True).strip().split()
297278
extra_compile_args += extra_parse_args
298-
extra_link_args += (
299-
subprocess.check_output(
300-
["sdl2-config", "--libs"], universal_newlines=True
301-
)
302-
.strip()
303-
.split()
304-
)
279+
extra_link_args += subprocess.check_output(["sdl2-config", "--libs"], universal_newlines=True).strip().split()
305280

306281
tdl_build = os.environ.get("TDL_BUILD", "RELEASE").upper()
307282

@@ -399,9 +374,7 @@ def parse_sdl_attrs(prefix: str, all_names: List[str]) -> Tuple[str, str]:
399374
"""
400375
names = []
401376
lookup = []
402-
for name, value in sorted(
403-
find_sdl_attrs(prefix), key=lambda item: item[1]
404-
):
377+
for name, value in sorted(find_sdl_attrs(prefix), key=lambda item: item[1]):
405378
all_names.append(name)
406379
names.append("%s = %s" % (name, value))
407380
lookup.append('%s: "%s"' % (value, name))
@@ -446,9 +419,7 @@ def update_module_all(filename: str, new_all: str) -> None:
446419
def generate_enums(prefix: str) -> Iterator[str]:
447420
"""Generate attribute assignments suitable for a Python enum."""
448421
prefix_len = len(prefix) - len("SDL_") + 1
449-
for name, value in sorted(
450-
find_sdl_attrs(prefix), key=lambda item: item[1]
451-
):
422+
for name, value in sorted(find_sdl_attrs(prefix), key=lambda item: item[1]):
452423
name = name.split("_", 1)[1]
453424
if name.isdigit():
454425
name = f"N{name}"
@@ -473,9 +444,7 @@ def write_library_constants() -> None:
473444
continue
474445
if name in EXCLUDE_CONSTANTS:
475446
continue
476-
if any(
477-
name.startswith(prefix) for prefix in EXCLUDE_CONSTANT_PREFIXES
478-
):
447+
if any(name.startswith(prefix) for prefix in EXCLUDE_CONSTANT_PREFIXES):
479448
continue
480449
value = getattr(lib, name)
481450
if name[:5] == "TCOD_":
@@ -511,28 +480,16 @@ def write_library_constants() -> None:
511480
all_names = []
512481
f.write(EVENT_CONSTANT_MODULE_HEADER)
513482
f.write("# --- SDL scancodes ---\n")
514-
f.write(
515-
"%s\n_REVERSE_SCANCODE_TABLE = %s\n"
516-
% parse_sdl_attrs("SDL_SCANCODE", all_names)
517-
)
483+
f.write("%s\n_REVERSE_SCANCODE_TABLE = %s\n" % parse_sdl_attrs("SDL_SCANCODE", all_names))
518484

519485
f.write("\n# --- SDL keyboard symbols ---\n")
520-
f.write(
521-
"%s\n_REVERSE_SYM_TABLE = %s\n"
522-
% parse_sdl_attrs("SDLK", all_names)
523-
)
486+
f.write("%s\n_REVERSE_SYM_TABLE = %s\n" % parse_sdl_attrs("SDLK", all_names))
524487

525488
f.write("\n# --- SDL keyboard modifiers ---\n")
526-
f.write(
527-
"%s\n_REVERSE_MOD_TABLE = %s\n"
528-
% parse_sdl_attrs("KMOD", all_names)
529-
)
489+
f.write("%s\n_REVERSE_MOD_TABLE = %s\n" % parse_sdl_attrs("KMOD", all_names))
530490

531491
f.write("\n# --- SDL wheel ---\n")
532-
f.write(
533-
"%s\n_REVERSE_WHEEL_TABLE = %s\n"
534-
% parse_sdl_attrs("SDL_MOUSEWHEEL", all_names)
535-
)
492+
f.write("%s\n_REVERSE_WHEEL_TABLE = %s\n" % parse_sdl_attrs("SDL_MOUSEWHEEL", all_names))
536493
all_names = ",\n ".join('"%s"' % name for name in all_names)
537494
f.write("\n__all__ = [\n %s,\n]\n" % (all_names,))
538495

examples/.isort.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
profile= black
33
py_version = 36
44
skip_gitignore = true
5-
line_length = 79
5+
line_length = 120

examples/cavegen.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ def convolve(tiles: np.ndarray, wall_rule: int = 5) -> np.ndarray:
1919
walls then the tile will become a wall.
2020
"""
2121
# Use convolve2d, the 2nd input is a 3x3 ones array.
22-
neighbors: np.ndarray = scipy.signal.convolve2d(
23-
tiles == 0, [[1, 1, 1], [1, 1, 1], [1, 1, 1]], "same"
24-
)
22+
neighbors: np.ndarray = scipy.signal.convolve2d(tiles == 0, [[1, 1, 1], [1, 1, 1], [1, 1, 1]], "same")
2523
next_tiles: np.ndarray = neighbors < wall_rule # Apply the wall rule.
2624
return next_tiles
2725

examples/distribution/PyInstaller/main.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717

1818

1919
def main():
20-
tileset = tcod.tileset.load_tilesheet(
21-
FONT_PATH, 16, 16, tcod.tileset.CHARMAP_CP437
22-
)
23-
with tcod.context.new(
24-
columns=WIDTH, rows=HEIGHT, tileset=tileset
25-
) as context:
20+
tileset = tcod.tileset.load_tilesheet(FONT_PATH, 16, 16, tcod.tileset.CHARMAP_CP437)
21+
with tcod.context.new(columns=WIDTH, rows=HEIGHT, tileset=tileset) as context:
2622
while True:
2723
console = tcod.console.Console(WIDTH, HEIGHT)
2824
console.print(0, 0, "Hello World")

examples/distribution/cx_Freeze/main.py

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

77

88
def main():
9-
tileset = tcod.tileset.load_tilesheet(
10-
"data/terminal8x8_gs_ro.png", 16, 16, tcod.tileset.CHARMAP_CP437
11-
)
12-
with tcod.context.new(
13-
columns=WIDTH, rows=HEIGHT, tileset=tileset
14-
) as context:
9+
tileset = tcod.tileset.load_tilesheet("data/terminal8x8_gs_ro.png", 16, 16, tcod.tileset.CHARMAP_CP437)
10+
with tcod.context.new(columns=WIDTH, rows=HEIGHT, tileset=tileset) as context:
1511
while True:
1612
console = tcod.console.Console(WIDTH, HEIGHT)
1713
console.print(0, 0, "Hello World")

examples/eventget.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ def main() -> None:
1919
event_log: List[str] = []
2020
motion_desc = ""
2121

22-
with tcod.context.new(
23-
width=WIDTH, height=HEIGHT, sdl_window_flags=FLAGS
24-
) as context:
22+
with tcod.context.new(width=WIDTH, height=HEIGHT, sdl_window_flags=FLAGS) as context:
2523
console = context.new_console()
2624
while True:
2725
# Display all event items.

0 commit comments

Comments
 (0)