Skip to content

Commit a41f485

Browse files
committed
python static checkers
1 parent faa1627 commit a41f485

File tree

8 files changed

+186
-66
lines changed

8 files changed

+186
-66
lines changed

.github/workflows/python.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Python
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
mypy:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
11+
- name: setup python
12+
uses: actions/setup-python@v4
13+
with:
14+
python-version: "3.13"
15+
16+
- name: install dependencies
17+
run: |
18+
pip install mypy cffi types-cffi
19+
20+
- name: run mypy
21+
run: mypy python
22+
23+
pyright:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: setup python
29+
uses: actions/setup-python@v4
30+
with:
31+
python-version: "3.13"
32+
33+
- name: install dependencies
34+
run: |
35+
pip install pyright cffi types-cffi
36+
37+
- name: run pyright
38+
run: pyright python

python/bot/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .bot import Bot
2+
3+
__all__ = ["Bot"]

python/bot/bot.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from uwapi.game import game
1+
from uwapi import *
22

33
class Bot:
44
isConfigured = False
@@ -11,25 +11,25 @@ def AssignRandomRecipes(self):
1111
pass # todo
1212

1313
def Configure(self):
14-
if isConfigured:
14+
if self.isConfigured:
1515
return
16-
isConfigured = True
16+
self.isConfigured = True
1717

1818
game.SetPlayerName("bot-cs")
1919
game.PlayerJoinForce(0) # create new force
2020
game.SetForceColor(1, 0, 0)
2121
# todo choose race
2222

2323
def Updating(self, stepping: bool):
24-
if game.GameState() == UwGameStateEnum.Session:
24+
if game.GameState() == GameState.Session:
2525
self.Configure()
2626
return
2727

2828
if not stepping:
2929
return
3030

31-
workStep += 1
32-
match workStep % 10: # save some cpu cycles by splitting work over multiple steps
31+
self.workStep += 1
32+
match self.workStep % 10: # save some cpu cycles by splitting work over multiple steps
3333
case 1:
3434
self.AttackNearestEnemies()
3535
case 5:

python/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from uwapi.library import UwapiLibrary
2-
from bot.bot import Bot
1+
from uwapi import UwapiLibrary
2+
from bot import Bot
33

44
if __name__ == "__main__":
55
with UwapiLibrary():

python/uwapi/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
# THIS FILE IS GENERATED BY SCRIPT
3+
# DO NOT MODIFY
4+
5+
from .interop import *
6+
from .library import UwapiLibrary
7+
from .game import game
8+
9+
__all__ = ["UwapiLibrary","game","Severity","LogCallback","ConnectionState","MyPlayer","AssistConfig","PerformanceStatistics","OrderType","OrderPriority","Order","Orders","Ids","Priority","Ping","PathState","ForeignPolicy","ChatTarget","ProtoComponent","OwnerComponent","ControllerComponent","PositionComponent","UnitState","UnitComponent","LifeComponent","ManaComponent","MoveComponent","AimComponent","RecipeComponent","RecipeStatisticsComponent","LogisticsTimestampComponent","PriorityComponent","AmountComponent","AttachmentComponent","PingComponent","PlayerState","PlayerConnectionClass","PlayerComponent","PlayerAiConfigComponent","ForceState","ForceComponent","ForceDetailsComponent","ForeignPolicyComponent","DiplomacyProposalComponent","GameState","ShootingUnit","ShootingData","ShootingArray","ExplosionData","ExplosionsArray","TaskType","MapState","MapInfo","MapStartingPosition","MapStartingPositionsArray","Tile","Cluster","ClustersDistancesQuery","ClustersDistancesResult","PrototypeType","MyForceStatistics","UnitUpgrades","Overview","OverviewExtract","UnitPathfindingQuery","UnitPathfindingResult"]

python/uwapi/game.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ def ConnectEnvironment(self) -> bool:
2323
def ConnectNewServer(self, visibility: int = 0, name: str = "", extraCmdParams: str = "") -> None:
2424
interop.uwConnectNewServer(visibility, name, extraCmdParams)
2525

26+
def GameState(self) -> GameState:
27+
return interop.uwGameState()
28+
2629
game = Game()

0 commit comments

Comments
 (0)