Skip to content

Commit

Permalink
Update ruff checking (#66)
Browse files Browse the repository at this point in the history
* Add/update ruff requirement

* Update ruff config

* Drop superfluous spaces before brackets/braces/etc

* Start block comments properly

* Give arithmetic operators room to breathe

* Clean up multiple spaces after commas

* Clean up whitespace _before_ brackets
  • Loading branch information
CyberiaResurrection authored Oct 18, 2023
1 parent df6428d commit b57b032
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion PyRoute/AllyGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AllyGen(object):
("KC",),
("Kk", "KkTw", "KO"),
('So', 'SoCf', 'SoBF', 'SoCT', 'SoFr', 'SoHn', 'SoKv', 'SoNS',
'SoQu', 'SoRD', 'SoRz', 'SoWu' ),
'SoQu', 'SoRD', 'SoRz', 'SoWu'),
('Lp', 'CoLp'),
('Vd', 'VDeG'),
('Vo', 'VOpA'),
Expand Down
2 changes: 1 addition & 1 deletion PyRoute/Calculation/TradeCalculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def get_trade_between(self, star, target):
route.reverse()
delta = fwd_weight - rev_weight
assert 1e-16 > delta * delta,\
"Route weight between " + str(star) + " and " + str(target) + " should not be direction sensitive. Forward weight " + str(fwd_weight) + ", rev weight " + str(rev_weight) +", delta " + str(abs(delta))
"Route weight between " + str(star) + " and " + str(target) + " should not be direction sensitive. Forward weight " + str(fwd_weight) + ", rev weight " + str(rev_weight) + ", delta " + str(abs(delta))

try:
self.cross_check_totals()
Expand Down
4 changes: 2 additions & 2 deletions PyRoute/Calculation/TradeMPCalculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class TradeMPCalculation(TradeCalculation):
between all the trade pairs using a multi-process route finder
"""

def __init__(self, galaxy, min_btn=13, route_btn=8, route_reuse=10, debug_flag=False, mp_threads=os.cpu_count()-1):
def __init__(self, galaxy, min_btn=13, route_btn=8, route_reuse=10, debug_flag=False, mp_threads=os.cpu_count() - 1):
super(TradeMPCalculation, self).__init__(galaxy, min_btn, route_btn, route_reuse, debug_flag)

self.btn = []
Expand Down Expand Up @@ -143,7 +143,7 @@ def calculate_routes(self):
large_btn_index = next(i for i, v in enumerate(self.btn) if v[2]['btn'] == 18)

# Do the large routes (btn 19 - 26) first. These are short and take only a short amount of time.
self.process_routes(self.btn[0:large_btn_index-1])
self.process_routes(self.btn[0:(large_btn_index - 1)])
# Do the in-sector routes next. Again short, and famed across multiple processor to make this faster.
self.start_mp_services()
# Do the remaining routes, which are long and will take a while
Expand Down
4 changes: 2 additions & 2 deletions PyRoute/DeltaDebug/DeltaDebug.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def process():
help='RU calculation, default [scaled]')
route.add_argument('--speculative-version', choices=['CT', 'T5', 'None'], default='CT',
help='version of the speculative trade calculations, default [CT]')
route.add_argument('--mp-threads', default=os.cpu_count()-1, type=int,
help=f"Number of processes to use for trade-mp processing, default {os.cpu_count()-1}")
route.add_argument('--mp-threads', default=os.cpu_count() - 1, type=int,
help=f"Number of processes to use for trade-mp processing, default {os.cpu_count() - 1}")

output = parser.add_argument_group('Output', 'Output options')

Expand Down
2 changes: 1 addition & 1 deletion PyRoute/DeltaDebug/DeltaDictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def allegiance_subset(self, allegiances):
raw_lines = [line for line in raw_lines if ' ' + alg + ' ' not in line]

result = self.drop_lines(raw_lines)
result.allegiances = {key: alg for (key, alg) in self.allegiances.items() if key in allegiances }
result.allegiances = {key: alg for (key, alg) in self.allegiances.items() if key in allegiances}

nu_headers = []

Expand Down
2 changes: 1 addition & 1 deletion PyRoute/DeltaPasses/AllegianceReducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def run(self, singleton_only=False):
for i in range(0, num_chunks):
if i + len(remove) >= len(chunks):
continue
msg = "Allegiance reduction: Attempting chunk " + str(i+1) + "/" + str(num_chunks)
msg = "Allegiance reduction: Attempting chunk " + str(i + 1) + "/" + str(num_chunks)
self.reducer.logger.error(msg)
raw_lines = self.reducer._assemble_all_but_ith_chunk(chunks, i)
if 0 == len(raw_lines):
Expand Down
2 changes: 1 addition & 1 deletion PyRoute/DeltaPasses/SectorReducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def run(self, singleton_only=False):
threshold = i + (len(remove) if 2 == num_chunks else 0)
if threshold >= len(chunks):
continue
msg = "Sector reduction: Attempting chunk " + str(i+1) + "/" + str(num_chunks)
msg = "Sector reduction: Attempting chunk " + str(i + 1) + "/" + str(num_chunks)
self.reducer.logger.error(msg)
raw_lines = self.reducer._assemble_all_but_ith_chunk(chunks, i)
if 0 == len(raw_lines):
Expand Down
4 changes: 2 additions & 2 deletions PyRoute/DeltaPasses/SingleLineReducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run(self, singleton_only=False):
threshold = i + (len(remove) if 2 == num_chunks else 0)
if threshold >= len(chunks):
continue
msg = "Line reduction: Attempting chunk " + str(i+1) + "/" + str(num_chunks)
msg = "Line reduction: Attempting chunk " + str(i + 1) + "/" + str(num_chunks)
self.reducer.logger.error(msg)
raw_lines = self.reducer._assemble_all_but_ith_chunk(chunks, i)
if 0 == len(raw_lines):
Expand Down Expand Up @@ -76,7 +76,7 @@ def run(self, singleton_only=False):
if 0 < i: # if have cleared a later chunk, it's worth trying to expand the hole backwards
msg = "Widening breach backwards"
self.reducer.logger.error(msg)
startloc = bounds[i-1][1]
startloc = bounds[i - 1][1]
best_sectors = self.breacher.run(
start_pos=startloc,
reverse=True,
Expand Down
2 changes: 1 addition & 1 deletion PyRoute/DeltaPasses/SubsectorReducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def run(self, singleton_only=False):
for i in range(0, num_chunks):
if i + len(remove) >= len(chunks):
continue
msg = "Subsector reduction: Attempting chunk " + str(i+1) + "/" + str(num_chunks)
msg = "Subsector reduction: Attempting chunk " + str(i + 1) + "/" + str(num_chunks)
self.reducer.logger.error(msg)
raw_lines = self.reducer._assemble_all_but_ith_chunk(chunks, i)
if 0 == len(raw_lines):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ def update_edges(self, edges):
rightdist = self._distances[right]
shelf = self._graph._arcs[left]
keep = shelf[0] == right
#matches = [dist_head for (head, dist_head) in shelf if head == right]
#weight = matches[0]
weight = shelf[1][keep][0]
delta = abs(leftdist - rightdist)

Expand Down
2 changes: 1 addition & 1 deletion PyRoute/Position/Hex.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def x(self):

@property
def y(self):
return -self.q -self.r
return -self.q - self.r

@property
def z(self):
Expand Down
8 changes: 4 additions & 4 deletions PyRoute/Star.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def subsector(self):
def calculate_gwp(self, pop_code):
calcGWP = [220, 350, 560, 560, 560, 895, 895, 1430, 2289, 3660, 3660, 3660, 5860, 5860, 9375, 15000, 24400,
24400, 39000, 39000]
#flatGWP = [229, 301, 396, 521, 685, 902, 1186, 1560, 2051, 2698, 3548, 4667, 6138, 8072, 10617, 13964, 18365,
# flatGWP = [229, 301, 396, 521, 685, 902, 1186, 1560, 2051, 2698, 3548, 4667, 6138, 8072, 10617, 13964, 18365,
# 24155, 31769, 41783]
popCodeM = [0, 10, 13, 17, 22, 28, 36, 47, 60, 78]

Expand Down Expand Up @@ -606,7 +606,7 @@ def calculate_TCS(self):
'M': 1.1, 'N': 1.2,
# Unknown Gov Codes
'I': 1.0, 'P': 1.0, 'Q': 1.0, 'R': 1.0, 'S': 1.0, 'T': 1.0,
'': 1.0, 'U': 1.0, 'V': 1.0, 'W': 1.0, 'X': 1.0, '?': 0.0
'': 1.0, 'U': 1.0, 'V': 1.0, 'W': 1.0, 'X': 1.0, '?': 0.0
}
self.ship_capacity = int(self.population * tax_rate[self.uwpCodes['Government']] * 1000)
gwp_base = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32]
Expand Down Expand Up @@ -740,11 +740,11 @@ def _int_to_ehex(self, value):
# Ehex doesn't use I, as it's too easily confused with the numeric 1, likewise with 0 and O
if 9 < value < 18:
valstring = 'ABCDEFGH'
return valstring[value-10]
return valstring[value - 10]
if 17 < value:
valstring = 'JKLMNOPQRSTUVWXYZ'
value += 1 if 22 < value else 0
return valstring[value-18]
return valstring[value - 18]

def split_stellar_data(self):
star_parts = self.stars.split()
Expand Down
2 changes: 1 addition & 1 deletion PyRoute/StatCalculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ObjectStatistics(object):
'N': 'Naval base', 'O': 'Naval outpost',
'R': 'Clan base', 'S': 'Scout base', 'T': 'Tlaukhu base', 'V': 'Scout base', 'W': 'Way station',
'*': 'Unknown', 'I': 'Unknown',
'G': 'Vargr Naval base', 'J': 'Naval base',
'G': 'Vargr Naval base', 'J': 'Naval base',
'L': 'Hiver naval base', 'P': 'Droyne Naval base', 'Q': 'Droyne military garrison',
'X': 'Zhodani relay station', 'Y': 'Zhodani depot',
'A': 'Split', 'B': 'Split', 'F': 'Split', 'H': 'Split', 'U': 'Split', 'Z': 'Split'}
Expand Down
2 changes: 1 addition & 1 deletion PyRoute/downloadsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_url(url, sector, suffix, output_dir):

for sector in sectorsList:
sector = sector.rstrip()
print ('Downloading %s' % sector)
print('Downloading %s' % sector)
params = {'sector': sector, 'type': 'SecondSurvey'}
if args.routes:
params['routes'] = '1'
Expand Down
6 changes: 3 additions & 3 deletions PyRoute/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def process():
help='RU calculation, default [scaled]')
route.add_argument('--speculative-version', choices=['CT', 'T5', 'None'], default='CT',
help='version of the speculative trade calculations, default [CT]')
route.add_argument('--mp-threads', default=os.cpu_count()-1, type=int,
help=f"Number of processes to use for trade-mp processing, default {os.cpu_count()-1}")
route.add_argument('--mp-threads', default=os.cpu_count() - 1, type=int,
help=f"Number of processes to use for trade-mp processing, default {os.cpu_count() - 1}")

output = parser.add_argument_group('Output', 'Output options')

Expand All @@ -70,7 +70,7 @@ def process():
source.add_argument('sector', nargs='*', help='T5SS sector file(s) to process')

debugging = parser.add_argument_group('Debug', "Debugging flags")
debugging.add_argument('--debug', dest="debug_flag", default=False, action=argparse.BooleanOptionalAction,
debugging.add_argument('--debug', dest="debug_flag", default=False, action=argparse.BooleanOptionalAction,
help="Turn on trade-route debugging")

parser.add_argument('--version', action='version', version='%(prog)s 0.4')
Expand Down
16 changes: 8 additions & 8 deletions PyRoute/wikistats.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, galaxy, uwp, min_alg_count=10, match_alg='collapse', json_dat

self.env = Environment(
loader=FileSystemLoader(templatedir),
#loader=PackageLoader('PyRoute', 'templates'),
# loader=PackageLoader('PyRoute', 'templates'),
autoescape=select_autoescape(['html', 'xml'])
)

Expand All @@ -55,13 +55,13 @@ def write_statistics(self):
self.sector_data_template()
self.allegiance_statistics_template()

#self.top_summary()
#self.tcs_statistics()
#self.subsector_statistics()
#self.write_allegiances(self.galaxy.alg)
#self.write_worlds_wiki_stats()
#self.write_sector_wiki()
#self.write_world_statistics()
# self.top_summary()
# self.tcs_statistics()
# self.subsector_statistics()
# self.write_allegiances(self.galaxy.alg)
# self.write_worlds_wiki_stats()
# self.write_sector_wiki()
# self.write_world_statistics()

self.write_summary_lists()
if self.json_data:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fixable = ["ALL"]
unfixable = []

# Specify github format
format = "github"
output-format = "github"

# Exclude a variety of commonly ignored directories.
exclude = [
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pytest
pytest-console-scripts
pytest-randomly
pytest-subtests
ruff >= 0.1.0

0 comments on commit b57b032

Please sign in to comment.