# Path: sc2/paths.py
# class Paths(metaclass=_MetaPaths):
#     """Paths for SC2 folders, lazily loaded using the above metaclass."""
# 
# Path: sc2/controller.py
# class Controller(Protocol):
#     def __init__(self, ws, process):
#         super().__init__(ws)
#         self.__process = process
# 
#     @property
#     def running(self):
#         return self.__process._process is not None
# 
#     async def create_game(self, game_map, players, realtime, random_seed=None):
#         assert isinstance(realtime, bool)
#         req = sc_pb.RequestCreateGame(
#             local_map=sc_pb.LocalMap(
#                 map_path=str(game_map.relative_path)
#             ),
#             realtime=realtime
#         )
#         if random_seed is not None:
#             req.random_seed = random_seed
# 
#         for player in players:
#             p = req.player_setup.add()
#             p.type = player.type.value
#             if isinstance(player, Computer):
#                 p.race = player.race.value
#                 p.difficulty = player.difficulty.value
# 
#         logger.info("Creating new game")
#         logger.info(f"Map:     {game_map.name}")
#         logger.info(f"Players: {', '.join(str(p) for p in players)}")
#         result = await self._execute(create_game=req)
#         return result


from typing import Any, Optional, List
from .paths import Paths
from .controller import Controller
import sys
import signal
import time
import asyncio
import os.path
import shutil
import tempfile
import subprocess
import portpicker
import aiohttp
import logging

        if logger.getEffectiveLevel() <= logging.DEBUG:
            args.append("-verbose")

        return subprocess.Popen(args,
            cwd=(str(Paths.CWD) if Paths.CWD else None),
            #, env=run_config.env
        )

    async def _connect(self):
        for i in range(60):
            if self._process is None:
                # The ._clean() was called, clearing the process
                logger.debug("Process cleanup complete, exit")
                sys.exit()

            await asyncio.sleep(1)
            try:
                self._session = aiohttp.ClientSession()
                ws = await self._session.ws_connect(self.ws_url, timeout=120)
                logger.debug("Websocket connection ready")
                return ws
            except aiohttp.client_exceptions.ClientConnectorError:
                await self._session.close()
                if i > 15:
                    logger.debug("Connection refused (startup not complete (yet))")

        logger.debug("Websocket connection to SC2 process timed out")
        raise TimeoutError("Websocket")


# Path: sc2/paths.py
# class Paths(metaclass=_MetaPaths):
#     """Paths for SC2 folders, lazily loaded using the above metaclass."""
# 
# Path: sc2/controller.py
# class Controller(Protocol):
#     def __init__(self, ws, process):
#         super().__init__(ws)
#         self.__process = process
# 
#     @property
#     def running(self):
#         return self.__process._process is not None
# 
#     async def create_game(self, game_map, players, realtime, random_seed=None):
#         assert isinstance(realtime, bool)
#         req = sc_pb.RequestCreateGame(
#             local_map=sc_pb.LocalMap(
#                 map_path=str(game_map.relative_path)
#             ),
#             realtime=realtime
#         )
#         if random_seed is not None:
#             req.random_seed = random_seed
# 
#         for player in players:
#             p = req.player_setup.add()
#             p.type = player.type.value
#             if isinstance(player, Computer):
#                 p.race = player.race.value
#                 p.difficulty = player.difficulty.value
# 
#         logger.info("Creating new game")
#         logger.info(f"Map:     {game_map.name}")
#         logger.info(f"Players: {', '.join(str(p) for p in players)}")
#         result = await self._execute(create_game=req)
#         return result


# Path: sc2/sc2process.py
from typing import Any, Optional, List
from .paths import Paths
from .controller import Controller
import sys
import signal
import time
import asyncio
import os.path
import shutil
import tempfile
import subprocess
import portpicker
import aiohttp
import logging


        if logger.getEffectiveLevel() <= logging.DEBUG:
            args.append("-verbose")

        return subprocess.Popen(args,
            cwd=(str(Paths.CWD) if Paths.CWD else None),
            #, env=run_config.env
        )

    async def _connect(self):
        for i in range(60):
            if self._process is None:
                # The ._clean() was called, clearing the process
                logger.debug("Process cleanup complete, exit")
                sys.exit()

            await asyncio.sleep(1)
            try:
                self._session = aiohttp.ClientSession()
                ws = await self._session.ws_connect(self.ws_url, timeout=120)
                logger.debug("Websocket connection ready")
                return ws
            except aiohttp.client_exceptions.ClientConnectorError:
                await self._session.close()
                if i > 15:
                    logger.debug("Connection refused (startup not complete (yet))")

        logger.debug("Websocket connection to SC2 process timed out")
        raise TimeoutError("Websocket")


    async def _close_connection(self):