Skip to content

Commit c4393e1

Browse files
committed
Update packages and apply autoformat
1 parent 77ef741 commit c4393e1

21 files changed

Lines changed: 1720 additions & 1077 deletions

examples/watch_replay.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def on_step(self, iteration: int):
3737
# Convert relative path to absolute path, assuming this replay is in this folder
3838
folder_path = Path(__file__).parent
3939
replay_path = folder_path / replay_name
40-
assert (
41-
replay_path.is_file()
42-
), "Run worker_rush.py in the same folder first to generate a replay. Then run watch_replay.py again."
40+
assert replay_path.is_file(), (
41+
"Run worker_rush.py in the same folder first to generate a replay. Then run watch_replay.py again."
42+
)
4343
run_replay(my_observer_ai, replay_path=str(replay_path))

generate_dicts_from_data_json.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ def get_unit_train_build_abilities(data):
205205
requirements: list[dict[str, int]] = ability_info.get("requirements", [])
206206
if requirements:
207207
# Assume train abilities only have one tech building requirement; thors requiring armory and techlab is seperatedly counted
208-
assert (
209-
len([req for req in requirements if req.get("building", 0)]) <= 1
210-
), f"Error: Building {unit_type} has more than one tech requirements with train ability {ability_id}"
208+
assert len([req for req in requirements if req.get("building", 0)]) <= 1, (
209+
f"Error: Building {unit_type} has more than one tech requirements with train ability {ability_id}"
210+
)
211211
# UnitTypeId 5 == Techlab
212212
requires_techlab: bool = any(req for req in requirements if req.get("addon", 0) == 5)
213213
requires_tech_builing_id_value: int = next(
@@ -404,9 +404,9 @@ def generate_unit_alias_dict(data: dict):
404404

405405
current_unit_tech_aliases: set[UnitTypeId] = OrderedSet2()
406406

407-
assert (
408-
unit_type_value in game_data.units
409-
), f"Unit {unit_type} not listed in game_data.units - perhaps pickled file {pickled_file_path} is outdated?"
407+
assert unit_type_value in game_data.units, (
408+
f"Unit {unit_type} not listed in game_data.units - perhaps pickled file {pickled_file_path} is outdated?"
409+
)
410410
unit_alias: int = game_data.units[unit_type_value]._proto.unit_alias
411411
if unit_alias:
412412
# Might be 0 if it has no alias

sc2/action.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def combine_actions(action_iter):
4545
elif isinstance(target, Unit):
4646
cmd.target_unit_tag = target.tag
4747
elif target is not None:
48-
raise RuntimeError(f"Must target a unit, point or None, found '{target !r}'")
48+
raise RuntimeError(f"Must target a unit, point or None, found '{target!r}'")
4949

5050
yield raw_pb.ActionRaw(unit_command=cmd)
5151

@@ -84,4 +84,4 @@ def combine_actions(action_iter):
8484
)
8585
yield raw_pb.ActionRaw(unit_command=cmd)
8686
else:
87-
raise RuntimeError(f"Must target a unit, point or None, found '{target !r}'")
87+
raise RuntimeError(f"Must target a unit, point or None, found '{target!r}'")

sc2/bot_ai.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ def main_base_ramp(self) -> Ramp:
152152
@property_cache_once_per_frame
153153
def expansion_locations_list(self) -> list[Point2]:
154154
"""Returns a list of expansion positions, not sorted in any way."""
155-
assert self._expansion_positions_list, "self._find_expansion_locations() has not been run yet, so accessing the list of expansion locations is pointless."
155+
assert self._expansion_positions_list, (
156+
"self._find_expansion_locations() has not been run yet, so accessing the list of expansion locations is pointless."
157+
)
156158
return self._expansion_positions_list
157159

158160
@property_cache_once_per_frame
@@ -163,7 +165,9 @@ def expansion_locations_dict(self) -> dict[Point2, Units]:
163165
164166
Caution: This function is slow. If you only need the expansion locations, use the property above.
165167
"""
166-
assert self._expansion_positions_list, "self._find_expansion_locations() has not been run yet, so accessing the list of expansion locations is pointless."
168+
assert self._expansion_positions_list, (
169+
"self._find_expansion_locations() has not been run yet, so accessing the list of expansion locations is pointless."
170+
)
167171
expansion_locations: dict[Point2, Units] = {pos: Units([], self) for pos in self._expansion_positions_list}
168172
for resource in self.resources:
169173
# It may be that some resources are not mapped to an expansion location
@@ -654,9 +658,9 @@ async def can_place(self, building: AbilityData | AbilityId | UnitTypeId, positi
654658
)
655659
return await self.can_place_single(building, positions)
656660
assert isinstance(positions, list), f"Expected an iterable (list, tuple), but was: {positions}"
657-
assert isinstance(
658-
positions[0], Point2
659-
), f"List is expected to have Point2, but instead had: {positions[0]} {type(positions[0])}"
661+
assert isinstance(positions[0], Point2), (
662+
f"List is expected to have Point2, but instead had: {positions[0]} {type(positions[0])}"
663+
)
660664
return await self.client._query_building_placement_fast(building, positions)
661665

662666
async def find_placement(
@@ -780,9 +784,9 @@ def structure_type_build_progress(self, structure_type: UnitTypeId | int) -> flo
780784
781785
:param structure_type:
782786
"""
783-
assert isinstance(
784-
structure_type, (int, UnitTypeId)
785-
), f"Needs to be int or UnitTypeId, but was: {type(structure_type)}"
787+
assert isinstance(structure_type, (int, UnitTypeId)), (
788+
f"Needs to be int or UnitTypeId, but was: {type(structure_type)}"
789+
)
786790
if isinstance(structure_type, int):
787791
structure_type_value: int = structure_type
788792
structure_type = UnitTypeId(structure_type_value)
@@ -1111,9 +1115,9 @@ def research(self, upgrade_type: UpgradeId) -> bool:
11111115
11121116
:param upgrade_type:
11131117
"""
1114-
assert (
1115-
upgrade_type in UPGRADE_RESEARCHED_FROM
1116-
), f"Could not find upgrade {upgrade_type} in 'research from'-dictionary"
1118+
assert upgrade_type in UPGRADE_RESEARCHED_FROM, (
1119+
f"Could not find upgrade {upgrade_type} in 'research from'-dictionary"
1120+
)
11171121

11181122
# Not affordable
11191123
if not self.can_afford(upgrade_type):

sc2/bot_ai_internal.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ def _client(self) -> Client:
167167
@property_cache_once_per_frame
168168
def expansion_locations(self) -> dict[Point2, Units]:
169169
"""Same as the function above."""
170-
assert self._expansion_positions_list, "self._find_expansion_locations() has not been run yet, so accessing the list of expansion locations is pointless."
170+
assert self._expansion_positions_list, (
171+
"self._find_expansion_locations() has not been run yet, so accessing the list of expansion locations is pointless."
172+
)
171173
warnings.warn(
172174
"You are using 'self.expansion_locations', please use 'self.expansion_locations_list' (fast) or 'self.expansion_locations_dict' (slow) instead.",
173175
DeprecationWarning,
@@ -372,9 +374,9 @@ def do(
372374
)
373375
return action
374376

375-
assert isinstance(
376-
action, UnitCommand
377-
), f"Given unit command is not a command, but instead of type {type(action)}"
377+
assert isinstance(action, UnitCommand), (
378+
f"Given unit command is not a command, but instead of type {type(action)}"
379+
)
378380
if subtract_cost:
379381
cost: Cost = self.game_data.calculate_ability_cost(action.ability)
380382
if can_afford_check and not (self.minerals >= cost.minerals and self.vespene >= cost.vespene):
@@ -400,9 +402,9 @@ async def synchronous_do(self, action: UnitCommand):
400402
This function is only useful for realtime=True in the first frame of the game to instantly produce a worker
401403
and split workers on the mineral patches.
402404
"""
403-
assert isinstance(
404-
action, UnitCommand
405-
), f"Given unit command is not a command, but instead of type {type(action)}"
405+
assert isinstance(action, UnitCommand), (
406+
f"Given unit command is not a command, but instead of type {type(action)}"
407+
)
406408
if not self.can_afford(action.ability):
407409
logger.warning(f"Cannot afford action {action}")
408410
return ActionResult.Error
@@ -888,9 +890,9 @@ def _distance_squared_unit_to_unit_method1(self, unit1: Unit, unit2: Unit) -> fl
888890
return 0
889891
# Calculate index, needs to be after pdist has been calculated and cached
890892
condensed_index = self.square_to_condensed(unit1.distance_calculation_index, unit2.distance_calculation_index)
891-
assert (
892-
condensed_index < len(self._cached_pdist)
893-
), f"Condensed index is larger than amount of calculated distances: {condensed_index} < {len(self._cached_pdist)}, units that caused the assert error: {unit1} and {unit2}"
893+
assert condensed_index < len(self._cached_pdist), (
894+
f"Condensed index is larger than amount of calculated distances: {condensed_index} < {len(self._cached_pdist)}, units that caused the assert error: {unit1} and {unit2}"
895+
)
894896
distance = self._pdist[condensed_index]
895897
return distance
896898

sc2/client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,12 @@ async def debug_set_unit_value(
657657
unit_tags = unit_tags.tags
658658
if isinstance(unit_tags, Unit):
659659
unit_tags = [unit_tags.tag]
660-
assert hasattr(
661-
unit_tags, "__iter__"
662-
), f"unit_tags argument needs to be an iterable (list, dict, set, Units), given argument is {type(unit_tags).__name__}"
663-
assert (
664-
1 <= unit_value <= 3
665-
), f"unit_value needs to be between 1 and 3 (1 for energy, 2 for life, 3 for shields), given argument is {unit_value}"
660+
assert hasattr(unit_tags, "__iter__"), (
661+
f"unit_tags argument needs to be an iterable (list, dict, set, Units), given argument is {type(unit_tags).__name__}"
662+
)
663+
assert 1 <= unit_value <= 3, (
664+
f"unit_value needs to be between 1 and 3 (1 for energy, 2 for life, 3 for shields), given argument is {unit_value}"
665+
)
666666
assert all(tag > 0 for tag in unit_tags), f"Unit tags have invalid value: {unit_tags}"
667667
assert isinstance(value, (int, float)), "Value needs to be of type int or float"
668668
assert value >= 0, "Value can't be negative"

sc2/generate_ids.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ def parse_data(self, data) -> dict[str, Any]:
8787
if v["friendlyname"] != "":
8888
key = v["friendlyname"]
8989
else:
90-
sys.exit(f"Not mapped: {v !r}")
90+
sys.exit(f"Not mapped: {v!r}")
9191

9292
key = key.upper().replace(" ", "_").replace("@", "")
9393

9494
if "name" in v:
95-
key = f'{v["name"].upper().replace(" ", "_")}_{key}'
95+
key = f"{v['name'].upper().replace(' ', '_')}_{key}"
9696

9797
if "friendlyname" in v:
9898
key = v["friendlyname"].upper().replace(" ", "_")
@@ -147,7 +147,7 @@ def generate_python_code(self, enums) -> None:
147147
idsdir.mkdir(exist_ok=True)
148148

149149
with (idsdir / "__init__.py").open("w") as f:
150-
initstring = f"__all__ = {[n.lower() for n in self.FILE_TRANSLATE.values()] !r}\n".replace("'", '"')
150+
initstring = f"__all__ = {[n.lower() for n in self.FILE_TRANSLATE.values()]!r}\n".replace("'", '"')
151151
f.write("\n".join([self.HEADER, initstring]))
152152

153153
for name, body in enums.items():

sc2/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,9 @@ async def run_host_and_join():
491491
def run_replay(ai, replay_path: Path | str, realtime: bool = False, observed_id: int = 0):
492492
portconfig = Portconfig()
493493
assert Path(replay_path).is_file(), f"Replay does not exist at the given path: {replay_path}"
494-
assert Path(
495-
replay_path
496-
).is_absolute(), f'Replay path has to be an absolute path, e.g. "C:/replays/my_replay.SC2Replay" but given path was "{replay_path}"'
494+
assert Path(replay_path).is_absolute(), (
495+
f'Replay path has to be an absolute path, e.g. "C:/replays/my_replay.SC2Replay" but given path was "{replay_path}"'
496+
)
497497
base_build, data_version = get_replay_version(replay_path)
498498
result = asyncio.get_event_loop().run_until_complete(
499499
_host_replay(replay_path, ai, realtime, portconfig, base_build, data_version, observed_id)

sc2/pixel_map.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def __init__(self, proto, in_bits: bool = False) -> None:
1818
# Used for copying pixelmaps
1919
self._in_bits: bool = in_bits
2020

21-
assert self.width * self.height == (8 if in_bits else 1) * len(
22-
self._proto.data
23-
), f"{self.width * self.height} {(8 if in_bits else 1)*len(self._proto.data)}"
21+
assert self.width * self.height == (8 if in_bits else 1) * len(self._proto.data), (
22+
f"{self.width * self.height} {(8 if in_bits else 1) * len(self._proto.data)}"
23+
)
2424
buffer_data = np.frombuffer(self._proto.data, dtype=np.uint8)
2525
if in_bits:
2626
buffer_data = np.unpackbits(buffer_data)
@@ -52,9 +52,9 @@ def __setitem__(self, pos: tuple[int, int], value: int) -> None:
5252
"""Example usage: self._game_info.pathing_grid[Point2((20, 20))] = 255"""
5353
assert 0 <= pos[0] < self.width, f"x is {pos[0]}, self.width is {self.width}"
5454
assert 0 <= pos[1] < self.height, f"y is {pos[1]}, self.height is {self.height}"
55-
assert (
56-
0 <= value <= 254 * self._in_bits + 1
57-
), f"value is {value}, it should be between 0 and {254 * self._in_bits + 1}"
55+
assert 0 <= value <= 254 * self._in_bits + 1, (
56+
f"value is {value}, it should be between 0 and {254 * self._in_bits + 1}"
57+
)
5858
assert isinstance(value, int), f"value is of type {type(value)}, it should be an integer"
5959
self.data_numpy[pos[1], pos[0]] = value
6060

sc2/player.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self, race, name: str | None = None, fullscreen: bool = False) -> N
5555

5656
def __str__(self) -> str:
5757
if self.name is not None:
58-
return f"Human({self.race._name_}, name={self.name !r})"
58+
return f"Human({self.race._name_}, name={self.name!r})"
5959
return f"Human({self.race._name_})"
6060

6161

@@ -71,7 +71,7 @@ def __init__(self, race, ai, name: str | None = None, fullscreen: bool = False)
7171

7272
def __str__(self) -> str:
7373
if self.name is not None:
74-
return f"Bot {self.ai.__class__.__name__}({self.race._name_}), name={self.name !r})"
74+
return f"Bot {self.ai.__class__.__name__}({self.race._name_}), name={self.name!r})"
7575
return f"Bot {self.ai.__class__.__name__}({self.race._name_})"
7676

7777

0 commit comments

Comments
 (0)