Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
uv run pre-commit install

- name: Run pre-commit hooks
run: uv run pre-commit run --all-files --hook-stage push
run: uv run pre-commit run --all-files --hook-stage pre-push

generate_dicts_from_data_json:
name: Generate dicts from data.json
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
run: |
mv sc2/dicts sc2/dicts_old
uv run python generate_dicts_from_data_json.py
uv run pre-commit run --all-files --hook-stage push || true
uv run pre-commit run --all-files --hook-stage pre-push || true
rm -rf sc2/dicts/__pycache__ sc2/dicts_old/__pycache__

- name: Upload generated dicts folder as artifact
Expand Down
21 changes: 12 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,25 @@ repos:
# Autoformat code
- id: ruff-format-check
name: Check if files are formatted
stages: [push]
stages: [pre-push]
language: system
# Run the following command to fix:
# uv run ruff format .
entry: uv run ruff format . --check --diff
pass_filenames: false

- id: ruff-lint
name: Lint files
stages: [push]
stages: [pre-push]
language: system
# Run the following command to fix:
# uv run ruff check . --fix
entry: uv run ruff check .
pass_filenames: false

# TODO Fix issues
# - id: pyrefly
# name: Static types checking with pyrefly
# stages: [push]
# language: system
# entry: uv run pyrefly check
# pass_filenames: false
- id: pyrefly
name: Static types checking with pyrefly
stages: [pre-push]
language: system
entry: uv run pyrefly check
pass_filenames: false
17 changes: 0 additions & 17 deletions .pyre_configuration

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,5 @@ Git commit messages use [imperative-style messages](https://stackoverflow.com/a/
To run pre-commit hooks (which run autoformatting and autosort imports) you can run
```sh
uv run pre-commit install
uv run pre-commit run --all-files --hook-stage push
uv run pre-commit run --all-files --hook-stage pre-push
```
2 changes: 0 additions & 2 deletions examples/arcade_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def position_around_unit(
step_size: int = 1,
exclude_out_of_bounds: bool = True,
):
# pyre-ignore[16]
pos = pos.position.rounded
positions = {
pos.offset(Point2((x, y)))
Expand All @@ -114,7 +113,6 @@ def position_around_unit(
positions = {
p
for p in positions
# pyre-ignore[16]
if 0 <= p[0] < self.game_info.pathing_grid.width and 0 <= p[1] < self.game_info.pathing_grid.height
}
return positions
Expand Down
1 change: 0 additions & 1 deletion examples/competitive/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ async def on_step(self, iteration: int):
# Populate this function with whatever your bot should do!
pass

# pyre-ignore[11]
async def on_end(self, game_result: Result):
print("Game ended.")
# Do things here after the game ends
1 change: 0 additions & 1 deletion examples/competitive/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pyre-ignore-all-errors[16, 21]
import sys

from __init__ import run_ladder_game
Expand Down
1 change: 0 additions & 1 deletion examples/distributed_workers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pyre-ignore-all-errors[16]
from sc2 import maps
from sc2.bot_ai import BotAI
from sc2.data import Difficulty, Race
Expand Down
4 changes: 1 addition & 3 deletions examples/protoss/find_adept_shades.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ async def on_step(self, iteration: int):
if adepts and not self.shaded:
# Wait for adepts to spawn and then cast ability
for adept in adepts:
# pyre-ignore[16]
adept(AbilityId.ADEPTPHASESHIFT_ADEPTPHASESHIFT, self.game_info.map_center)
self.shaded = True
elif self.shades_mapping:
Expand All @@ -38,7 +37,6 @@ async def on_step(self, iteration: int):
# logger.info(f"Remaining shade time: {shade.buff_duration_remain} / {shade.buff_duration_max}")
pass
if adept and shade:
# pyre-ignore[16]
self.client.debug_line_out(adept, shade, (0, 255, 0))
# logger.info(self.shades_mapping)
elif self.shaded:
Expand All @@ -53,7 +51,7 @@ async def on_step(self, iteration: int):
previous_shade_location = shade.position.towards(
forward_position, -(self.client.game_step / 16) * shade.movement_speed
) # See docstring of movement_speed attribute
# pyre-ignore[6]

closest_adept = remaining_adepts.closest_to(previous_shade_location)
self.shades_mapping[closest_adept.tag] = shade.tag

Expand Down
1 change: 0 additions & 1 deletion examples/terran/onebase_battlecruiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def select_target(self) -> tuple[Point2, bool]:
return targets.random.position, True

if self.units and min(u.position.distance_to(self.enemy_start_locations[0]) for u in self.units) < 5:
# pyre-ignore[7]
return self.enemy_start_locations[0].position, False

return self.mineral_field.random.position, False
Expand Down
4 changes: 2 additions & 2 deletions examples/worker_stack_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ async def on_step(self, iteration: int):
# Move worker in front of the nexus to avoid deceleration until the last moment
if worker.distance_to(th) > th.radius + worker.radius + self.townhall_distance_threshold:
pos: Point2 = th.position
# pyre-ignore[6]

worker.move(pos.towards(worker, th.radius * self.townhall_distance_factor))
worker.return_resource(queue=True)
else:
worker.return_resource()
worker.gather(mineral, queue=True)

# Print info every 30 game-seconds
# pyre-ignore[16]

if self.state.game_loop % (22.4 * 30) == 0:
logger.info(f"{self.time_formatted} Mined a total of {int(self.state.score.collected_minerals)} minerals")

Expand Down
1 change: 0 additions & 1 deletion examples/zerg/zerg_rush.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def draw_creep_pixelmap(self):
color = Point3((0, 255, 0))
self.client.debug_box2_out(pos, half_vertex_length=0.25, color=color)

# pyre-ignore[11]
async def on_end(self, game_result: Result):
self.on_end_called = True
logger.info(f"{self.time_formatted} On end was called")
Expand Down
24 changes: 20 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dev = [
"pyglet>=2.0.20",
"pylint>=3.3.2",
# Type checker
"pyrefly>=0.21.0",
"pyrefly>=0.40.0",
"pytest>=8.3.4",
"pytest-asyncio>=0.25.0",
"pytest-benchmark>=5.1.0",
Expand Down Expand Up @@ -93,7 +93,23 @@ dedent_closing_brackets = true
allow_split_before_dict_value = false

[tool.pyrefly]
project_includes = ["sc2", "examples", "test"]
project_includes = [
"sc2",
# "examples",
# "test"
]
project-excludes = [
# Disable for those files and folders
"sc2/data.py",
# TODO Temp disable for those files and folders
"sc2/client.py",
"sc2/bot_ai_internal.py",
"sc2/bot_ai.py",
]

[tool.pyrefly.errors]
bad-override = false
inconsistent-overload = false

[tool.ruff]
target-version = 'py310'
Expand Down Expand Up @@ -132,11 +148,11 @@ ignore = [
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
]

[tool.ruff.pyupgrade]
[tool.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
# Remove once support for py3.8 and 3.9 is dropped
keep-runtime-typing = true

[tool.ruff.pep8-naming]
[tool.pep8-naming]
# Allow Pydantic's `@validator` decorator to trigger class method treatment.
classmethod-decorators = ["pydantic.validator", "classmethod"]
18 changes: 9 additions & 9 deletions s2clientprotocol/data_pb2.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections.abc import Iterable
from collections.abc import Sequence
from enum import Enum

from google.protobuf.message import Message
Expand Down Expand Up @@ -71,15 +71,15 @@ class TargetType(Enum):
class Weapon(Message):
type: int
damage: float
damage_bonus: Iterable[DamageBonus]
damage_bonus: Sequence[DamageBonus]
attacks: int
range: float
speed: float
def __init__(
self,
type: int = ...,
damage: float = ...,
damage_bonus: Iterable[DamageBonus] = ...,
damage_bonus: Sequence[DamageBonus] = ...,
attacks: int = ...,
range: float = ...,
speed: float = ...,
Expand All @@ -100,14 +100,14 @@ class UnitTypeData(Message):
has_vespene: bool
has_minerals: bool
sight_range: float
tech_alias: Iterable[int]
tech_alias: Sequence[int]
unit_alias: int
tech_requirement: int
require_attached: bool
attributes: Iterable[int]
attributes: Sequence[int]
movement_speed: float
armor: float
weapons: Iterable[Weapon]
weapons: Sequence[Weapon]
def __init__(
self,
unit_id: int = ...,
Expand All @@ -124,14 +124,14 @@ class UnitTypeData(Message):
has_vespene: bool = ...,
has_minerals: bool = ...,
sight_range: float = ...,
tech_alias: Iterable[int] = ...,
tech_alias: Sequence[int] = ...,
unit_alias: int = ...,
tech_requirement: int = ...,
require_attached: bool = ...,
attributes: Iterable[int] = ...,
attributes: Sequence[int] = ...,
movement_speed: float = ...,
armor: float = ...,
weapons: Iterable[Weapon] = ...,
weapons: Sequence[Weapon] = ...,
) -> None: ...

class UpgradeData(Message):
Expand Down
22 changes: 11 additions & 11 deletions s2clientprotocol/debug_pb2.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections.abc import Iterable
from collections.abc import Sequence
from enum import Enum

from google.protobuf.message import Message
Expand Down Expand Up @@ -27,16 +27,16 @@ class DebugCommand(Message):
) -> None: ...

class DebugDraw(Message):
text: Iterable[DebugText]
lines: Iterable[DebugLine]
boxes: Iterable[DebugBox]
spheres: Iterable[DebugSphere]
text: Sequence[DebugText]
lines: Sequence[DebugLine]
boxes: Sequence[DebugBox]
spheres: Sequence[DebugSphere]
def __init__(
self,
text: Iterable[DebugText] = ...,
lines: Iterable[DebugLine] = ...,
boxes: Iterable[DebugBox] = ...,
spheres: Iterable[DebugSphere] = ...,
text: Sequence[DebugText] = ...,
lines: Sequence[DebugLine] = ...,
boxes: Sequence[DebugBox] = ...,
spheres: Sequence[DebugSphere] = ...,
) -> None: ...

class Line(Message):
Expand Down Expand Up @@ -110,8 +110,8 @@ class DebugCreateUnit(Message):
) -> None: ...

class DebugKillUnit(Message):
tag: Iterable[int]
def __init__(self, tag: Iterable[int] = ...) -> None: ...
tag: Sequence[int]
def __init__(self, tag: Sequence[int] = ...) -> None: ...

class Test(Enum):
hang: int
Expand Down
30 changes: 15 additions & 15 deletions s2clientprotocol/query_pb2.pyi
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
from collections.abc import Iterable
from collections.abc import Sequence

from google.protobuf.message import Message

from .common_pb2 import AvailableAbility, Point2D

class RequestQuery(Message):
pathing: Iterable[RequestQueryPathing]
abilities: Iterable[RequestQueryAvailableAbilities]
placements: Iterable[RequestQueryBuildingPlacement]
pathing: Sequence[RequestQueryPathing]
abilities: Sequence[RequestQueryAvailableAbilities]
placements: Sequence[RequestQueryBuildingPlacement]
ignore_resource_requirements: bool
def __init__(
self,
pathing: Iterable[RequestQueryPathing] = ...,
abilities: Iterable[RequestQueryAvailableAbilities] = ...,
placements: Iterable[RequestQueryBuildingPlacement] = ...,
pathing: Sequence[RequestQueryPathing] = ...,
abilities: Sequence[RequestQueryAvailableAbilities] = ...,
placements: Sequence[RequestQueryBuildingPlacement] = ...,
ignore_resource_requirements: bool = ...,
) -> None: ...

class ResponseQuery(Message):
pathing: Iterable[ResponseQueryPathing]
abilities: Iterable[ResponseQueryAvailableAbilities]
placements: Iterable[ResponseQueryBuildingPlacement]
pathing: Sequence[ResponseQueryPathing]
abilities: Sequence[ResponseQueryAvailableAbilities]
placements: Sequence[ResponseQueryBuildingPlacement]
def __init__(
self,
pathing: Iterable[ResponseQueryPathing] = ...,
abilities: Iterable[ResponseQueryAvailableAbilities] = ...,
placements: Iterable[ResponseQueryBuildingPlacement] = ...,
pathing: Sequence[ResponseQueryPathing] = ...,
abilities: Sequence[ResponseQueryAvailableAbilities] = ...,
placements: Sequence[ResponseQueryBuildingPlacement] = ...,
) -> None: ...

class RequestQueryPathing(Message):
Expand All @@ -48,12 +48,12 @@ class RequestQueryAvailableAbilities(Message):
def __init__(self, unit_tag: int = ...) -> None: ...

class ResponseQueryAvailableAbilities(Message):
abilities: Iterable[AvailableAbility]
abilities: Sequence[AvailableAbility]
unit_tag: int
unit_type_id: int
def __init__(
self,
abilities: Iterable[AvailableAbility] = ...,
abilities: Sequence[AvailableAbility] = ...,
unit_tag: int = ...,
unit_type_id: int = ...,
) -> None: ...
Expand Down
Loading
Loading