Skip to content

Commit

Permalink
build: use pypi s2clientprotocol
Browse files Browse the repository at this point in the history
With the type stubs for s2clientprotocol now available in typeshed [1],
compiling the protocol buffers and the types from the s2client-proto
submodule is no longer necessary.

References:

[1] python/typeshed#10372
  • Loading branch information
jrtknauer committed Aug 1, 2023
1 parent 156aa5b commit 463c01b
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 23 deletions.
3 changes: 2 additions & 1 deletion example/bot_vs_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import os

from s2clientprotocol.common_pb2 import Race

from pycraft2.bot import BotInterface
from pycraft2.main import run_local_match
from pycraft2.map import Map
from pycraft2.match import Match
from pycraft2.player import CreatePlayer
from pycraft2.s2clientprotocol.common_pb2 import Race

EXAMPLE_MAPS_DIR = os.path.dirname(os.path.realpath(__file__)) + "/maps"

Expand Down
3 changes: 2 additions & 1 deletion example/bot_vs_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import os

from s2clientprotocol.common_pb2 import Race

from pycraft2.bot import BotInterface
from pycraft2.main import run_local_match
from pycraft2.map import Map
from pycraft2.match import Match
from pycraft2.player import CreatePlayer
from pycraft2.s2clientprotocol.common_pb2 import Race

EXAMPLE_MAPS_DIR = os.path.dirname(os.path.realpath(__file__)) + "/maps"

Expand Down
6 changes: 1 addition & 5 deletions pycraft2/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@
from typing import Optional

import structlog
from s2clientprotocol.sc2api_pb2 import PlayerResult, ResponseObservation, Status

from pycraft2.client import GameClient
from pycraft2.match import Match, MatchResult
from pycraft2.message import ResponseMessage
from pycraft2.player import Bot
from pycraft2.port import MatchPortConfig
from pycraft2.s2clientprotocol.sc2api_pb2 import (
PlayerResult,
ResponseObservation,
Status,
)
from pycraft2.transport import Messenger

LOGGER = structlog.get_logger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion pycraft2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
import asyncio
from typing import Optional

from s2clientprotocol.common_pb2 import Race

from pycraft2.bot import BotInterface
from pycraft2.ladder import LadderArg, LadderRunner
from pycraft2.match import Match
from pycraft2.player import CreatePlayer, PlayerClientConfiguration
from pycraft2.runner import LocalRunner
from pycraft2.s2clientprotocol.common_pb2 import Race


def run_local_match(match_config: Match) -> None:
Expand Down
3 changes: 2 additions & 1 deletion pycraft2/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"""
from dataclasses import dataclass

from s2clientprotocol.sc2api_pb2 import Result

from pycraft2.map import Map
from pycraft2.player import Player
from pycraft2.s2clientprotocol.sc2api_pb2 import Result


@dataclass(frozen=True, slots=True)
Expand Down
7 changes: 4 additions & 3 deletions pycraft2/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
from dataclasses import InitVar, dataclass, field
from typing import Any, Optional

from pycraft2.map import Map
from pycraft2.s2clientprotocol.common_pb2 import Race
from pycraft2.s2clientprotocol.sc2api_pb2 import (
from s2clientprotocol.common_pb2 import Race
from s2clientprotocol.sc2api_pb2 import (
AIBuild,
Difficulty,
InterfaceOptions,
Expand All @@ -54,6 +53,8 @@
Status,
)

from pycraft2.map import Map


@dataclass(slots=True)
class _ProtocolMessage(ABC):
Expand Down
4 changes: 2 additions & 2 deletions pycraft2/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
# pycraft2.util.unused_port_generator because of dataclass limitations for default
# arguments and generators.
from portpicker import pick_unused_port # pyright: ignore
from s2clientprotocol.common_pb2 import Race
from s2clientprotocol.sc2api_pb2 import AIBuild, Difficulty, PlayerType

from pycraft2.bot import BotInterface
from pycraft2.s2clientprotocol.common_pb2 import Race
from pycraft2.s2clientprotocol.sc2api_pb2 import AIBuild, Difficulty, PlayerType

LOGGER = structlog.get_logger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion pycraft2/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Optional

import structlog
from s2clientprotocol.sc2api_pb2 import Status

from pycraft2.match import Match
from pycraft2.message import (
Expand All @@ -28,7 +29,6 @@
)
from pycraft2.player import Bot, Computer, Player
from pycraft2.port import MatchPortConfig
from pycraft2.s2clientprotocol.sc2api_pb2 import Status
from pycraft2.websocket import Websocket

LOGGER = structlog.get_logger(__name__)
Expand Down
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ backoff
structlog
protobuf<4
portpicker
s2clientprotocol
8 changes: 6 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --config=pyproject.toml --resolver=backtracking requirements/base.in
# pip-compile --allow-unsafe --config=pyproject.toml requirements/base.in
#
aiohttp==3.8.4
# via -r requirements/base.in
Expand All @@ -29,9 +29,13 @@ multidict==6.0.4
portpicker==1.5.2
# via -r requirements/base.in
protobuf==3.20.3
# via -r requirements/base.in
# via
# -r requirements/base.in
# s2clientprotocol
psutil==5.9.5
# via portpicker
s2clientprotocol==5.0.11.90136.0
# via -r requirements/base.in
structlog==23.1.0
# via -r requirements/base.in
yarl==1.9.2
Expand Down
1 change: 1 addition & 0 deletions requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pyright
ruff
sphinx
sphinx-rtd-theme
types-s2clientprotocol
8 changes: 6 additions & 2 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --config=pyproject.toml --resolver=backtracking requirements/dev.in
# pip-compile --allow-unsafe --config=pyproject.toml requirements/dev.in
#
alabaster==0.7.13
# via sphinx
Expand Down Expand Up @@ -93,7 +93,11 @@ tomli==2.0.1
# -c requirements/test.txt
# black
types-protobuf==4.23.0.1
# via mypy-protobuf
# via
# mypy-protobuf
# types-s2clientprotocol
types-s2clientprotocol==5.0.0.1
# via -r requirements/dev.in
urllib3==2.0.3
# via requests

Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --config=pyproject.toml --resolver=backtracking requirements/test.in
# pip-compile --allow-unsafe --config=pyproject.toml requirements/test.in
#
cachetools==5.3.1
# via tox
Expand Down
3 changes: 2 additions & 1 deletion test/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

import os

from s2clientprotocol.common_pb2 import Race

from pycraft2.bot import BotInterface
from pycraft2.main import run_local_match
from pycraft2.map import Map
from pycraft2.match import Match
from pycraft2.player import CreatePlayer
from pycraft2.s2clientprotocol.common_pb2 import Race

EXAMPLE_MAPS_DIR = os.path.dirname(os.path.realpath(__file__)) + "/maps"

Expand Down
4 changes: 2 additions & 2 deletions test/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from typing import Optional

import pytest
from s2clientprotocol.common_pb2 import Race
from s2clientprotocol.sc2api_pb2 import AIBuild, Difficulty, PlayerType

from pycraft2.bot import BotInterface
from pycraft2.player import Bot, Computer, CreatePlayer, PlayerClientConfiguration
from pycraft2.s2clientprotocol.common_pb2 import Race
from pycraft2.s2clientprotocol.sc2api_pb2 import AIBuild, Difficulty, PlayerType


class _MockBot(BotInterface):
Expand Down

0 comments on commit 463c01b

Please sign in to comment.