Skip to content

Commit

Permalink
Feat/refactor (#57)
Browse files Browse the repository at this point in the history
* Remove old Score class

* Update .gitignore

* Fix module filtering in SochaPackageBuilder class

* Refactor rust code

* Refactor game state

* Remove unused imports and fix logging message

* Add linters and unittests for Rust and Python

* allow clippy lints to game_state.rs and ship.rs

* Improve CD and CI workflows

* Refactor code formatting and improve readability

* Refactor import statements and update dependencies

* Update import statement for NetworkSocket

* Set PYTHONPATH and fix import in test_network.py

* Update CI workflow to use Maturin for building and testing Python code

* Fix typo in Maturin command

* Update CI workflow to include Python setup and virtual environment creation

* Refactor CI workflow to use virtual environment
  • Loading branch information
maxblan authored Mar 16, 2024
1 parent a279fe5 commit da453d6
Show file tree
Hide file tree
Showing 21 changed files with 1,156 additions and 882 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: continuous deployment
name: CD

on:
release:
types: [published]
branches:
- master

permissions:
contents: read
Expand Down Expand Up @@ -96,7 +94,7 @@ jobs:
release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
if: startsWith(github.ref, 'refs/tags/')
needs: [linux, windows, macos, sdist]
steps:
- uses: actions/download-artifact@v3
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]

permissions: read-all

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

# Clippy - Rust linter
- name: Install Rust toolchain
run: rustup toolchain install stable
- name: Run Clippy
run: rustup component add clippy && cargo clippy -- -D warnings

# Install dependencies and run unittests within the virtual environment
- name: Setup and run tests in virtual environment
run: |
python -m venv venv
source venv/bin/activate
pip install ruff
ruff .
pip install maturin
maturin develop
python -m unittest discover -s tests -p '*.py'
# Build and test steps for Rust
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
4 changes: 2 additions & 2 deletions .github/workflows/convert.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: convert readme
on:
push:
branches: [ master ]
branches: [master]
jobs:
convert:
runs-on: ubuntu-latest
Expand All @@ -20,4 +20,4 @@ jobs:
git add docs/index.rst
git commit -m "docs: auto update index.rst"
git push
continue-on-error: true
continue-on-error: true
17 changes: 0 additions & 17 deletions .github/workflows/push.yaml

This file was deleted.

28 changes: 25 additions & 3 deletions logic.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
import logging
import random
from typing import List

# not all imports are currently used, but they might be in the future and it shows all available functionalities
from socha import Accelerate, AccelerationProblem, Advance, AdvanceInfo, AdvanceProblem, Board
from socha import CartesianCoordinate, CubeCoordinates, CubeDirection, Field, FieldType, GameState
from socha import Move, Passenger, Push, PushProblem, Segment, Ship, TeamEnum, TeamPoints, Turn, TurnProblem
from socha import (
Accelerate,
AccelerationProblem,
Advance,
AdvanceInfo,
AdvanceProblem,
Board,
CartesianCoordinate,
CubeCoordinates,
CubeDirection,
Field,
FieldType,
GameState,
Move,
Passenger,
Push,
PushProblem,
Segment,
Ship,
TeamEnum,
TeamPoints,
Turn,
TurnProblem,
)
from socha.api.networking.game_client import IClientHandler
from socha.starter import Starter

Expand Down
29 changes: 16 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ readme = "README.md"
requires-python = ">=3.10"
dependencies = ["xsdata==22.9"]
classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python",
"Programming Language :: Rust",
"Typing :: Typed",
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python",
"Programming Language :: Rust",
"Typing :: Typed",
]
homepage = "https://software-challenge.de/"
repository = "https://github.com/FalconsSky/socha-python-client"
Expand All @@ -37,3 +37,6 @@ python-source = "python"
module-name = "socha._socha"
exclude = [".github", "docs", "tests", "logic.py", "readthedocs.yaml"]
features = ["pyo3/extension-module"]

[tool.ruff]
exclude = ["logic.py", "python/socha/__init__.py"]
1 change: 0 additions & 1 deletion python/socha/_socha.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ class GameState:
other_ship: Ship, last_move: Optional[Move]) -> None: ...

def determine_ahead_team(self) -> Ship: ...
def ship_advance_points(self, ship: Ship) -> int: ...
def calculate_points(self, ship: Ship) -> int: ...
def is_current_ship_on_current(self) -> bool: ...
def perform_action(self, action: Accelerate | Advance |
Expand Down
Loading

0 comments on commit da453d6

Please sign in to comment.