Skip to content

Commit b78cb01

Browse files
committed
Use ruff to lint
1 parent c14cdf0 commit b78cb01

8 files changed

Lines changed: 73 additions & 43 deletions

File tree

.github/workflows/linting.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Linting
2+
3+
# Build on every branch push, tag push, and pull request change:
4+
on: [push, pull_request]
5+
6+
jobs:
7+
mypy:
8+
name: mypy
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout reposistory
12+
uses: actions/checkout@v4
13+
14+
- name: Set up Python 3.9
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: 3.9
18+
19+
- name: Install Dependencies
20+
run: |
21+
python3 -m pip install -r requirements.txt
22+
python3 -m pip install -U maturin
23+
python3 -m pip install -U mypy
24+
25+
- name: mypy
26+
run: mypy --show-column-numbers --hide-error-context .
27+
28+
ruff:
29+
runs-on: ubuntu-latest
30+
name: ruff
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
35+
- name: Set up Python 3.9
36+
uses: actions/setup-python@v5
37+
with:
38+
python-version: '3.9'
39+
40+
- name: Setup venv
41+
run: |
42+
python3 -m venv .venv
43+
44+
- name: Install Dependencies
45+
run: |
46+
. .venv/bin/activate
47+
python3 -m pip install -U -r requirements.txt
48+
python3 -m pip install -U ruff
49+
50+
- name: mypy
51+
run: |
52+
. .venv/bin/activate
53+
ruff check

.github/workflows/mypy.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,5 @@ cython_debug/
170170
# Added by cargo
171171

172172
/target
173+
174+
.ruff_cache/

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ This library is available for Python3 and Rust
1515

1616
- Fast parsing written in Rust.
1717
- Support map formats:
18-
- GNU ld
19-
- clang lld
20-
- Metrowerks ld
18+
- `GNU ld`.
19+
- `clang lld`.
20+
- `Metrowerks ld`.
2121
- Built-in cli utilities to process the parsed map file (see [Examples](#examples)).
2222

2323
## Installing

src/mapfile_parser/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424

2525
from . import frontends as frontends
2626

27-
# Renamed types
28-
from .mapfile import Section as File
27+
# Renamed types.
28+
# TODO: remove on version 3.0
29+
File = Section

src/mapfile_parser/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def mapfileParserMain():
1515
decompConfig: decomp_settings.Config|None
1616
try:
1717
decompConfig = decomp_settings.scan_for_config()
18-
except:
18+
except Exception:
1919
decompConfig = None
2020

2121
description = description="""\

src/mapfile_parser/frontends/bss_check.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def printSymbolComparisonAsCsv(comparisonInfo: mapfile.MapsComparisonInfo, print
5353
symbolState = "BAD"
5454
if symbolInfo.diff == 0:
5555
symbolState = "GOOD"
56-
if not buildFile in comparisonInfo.badFiles and not expectedFile in comparisonInfo.badFiles:
57-
if not buildFile in comparisonInfo.badFiles and not expectedFile in comparisonInfo.badFiles:
56+
if buildFile not in comparisonInfo.badFiles and expectedFile not in comparisonInfo.badFiles:
57+
if buildFile not in comparisonInfo.badFiles and expectedFile not in comparisonInfo.badFiles:
5858
if not printAll:
5959
continue
6060

@@ -88,8 +88,8 @@ def printSymbolComparisonAsListing(comparisonInfo: mapfile.MapsComparisonInfo, p
8888
symbolState = "BAD"
8989
if symbolInfo.diff == 0:
9090
symbolState = "GOOD"
91-
if not buildFile in comparisonInfo.badFiles and not expectedFile in comparisonInfo.badFiles:
92-
if not buildFile in comparisonInfo.badFiles and not expectedFile in comparisonInfo.badFiles:
91+
if buildFile not in comparisonInfo.badFiles and expectedFile not in comparisonInfo.badFiles:
92+
if buildFile not in comparisonInfo.badFiles and expectedFile not in comparisonInfo.badFiles:
9393
if not printAll:
9494
continue
9595

src/mapfile_parser/mapfile.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ def findLowestDifferingSymbol(self, otherMapFile: MapFile) -> tuple[Symbol, Sect
877877
# We want to check the previous section, not the current one,
878878
# since we already know the current one doesn't have a symbol
879879
# preceding the one we found.
880-
j -= 1;
880+
j -= 1
881881

882882
while i >= 0:
883883
builtSegment = self[i]
@@ -916,7 +916,7 @@ def getProgress(self, asmPath: Path, nonmatchings: Path, aliases: dict[str, str]
916916
progressPerFolder: dict[str, ProgressStats] = dict()
917917

918918
if self.debugging:
919-
utils.eprint(f"getProgress():")
919+
utils.eprint("getProgress():")
920920

921921
for segment in self._segmentsList:
922922
for section in segment:
@@ -965,22 +965,22 @@ def getProgress(self, asmPath: Path, nonmatchings: Path, aliases: dict[str, str]
965965
totalStats.undecompedSize += symSize
966966
progressPerFolder[folder].undecompedSize += symSize
967967
if self.debugging:
968-
utils.eprint(f" the whole section is undecomped (no individual function files exist yet)")
968+
utils.eprint(" the whole section is undecomped (no individual function files exist yet)")
969969
elif self.findSymbolByName(f"{func.name}.NON_MATCHING") is not None:
970970
totalStats.undecompedSize += symSize
971971
progressPerFolder[folder].undecompedSize += symSize
972972
if self.debugging:
973-
utils.eprint(f" the function hasn't been matched yet (there's a `.NON_MATCHING` symbol with the same name)")
973+
utils.eprint(" the function hasn't been matched yet (there's a `.NON_MATCHING` symbol with the same name)")
974974
elif checkFunctionFiles and funcAsmPath.exists():
975975
totalStats.undecompedSize += symSize
976976
progressPerFolder[folder].undecompedSize += symSize
977977
if self.debugging:
978-
utils.eprint(f" the function hasn't been matched yet (the function section still exists)")
978+
utils.eprint(" the function hasn't been matched yet (the function section still exists)")
979979
else:
980980
totalStats.decompedSize += symSize
981981
progressPerFolder[folder].decompedSize += symSize
982982
if self.debugging:
983-
utils.eprint(f" the function is matched! (the function section was not found)")
983+
utils.eprint(" the function is matched! (the function section was not found)")
984984

985985
return totalStats, progressPerFolder
986986

@@ -1111,7 +1111,7 @@ def toCsv(self, printVram: bool=True, skipWithoutSymbols: bool=True) -> str:
11111111
return ret
11121112

11131113
def toCsvSymbols(self) -> str:
1114-
ret = f"Section," + Symbol.toCsvHeader() + "\n"
1114+
ret = "Section," + Symbol.toCsvHeader() + "\n"
11151115

11161116
for segment in self._segmentsList:
11171117
ret += segment.toCsvSymbols()

0 commit comments

Comments
 (0)