summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi>2024-02-17 09:41:48 +0200
committerAineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi>2024-02-17 09:41:48 +0200
commite785dbd4f726c5716f21071ed25dc35ac87c0c74 (patch)
tree781373b78380a1ffd1ea8c5dc8ceb2bd313631e9
parent4eff4a32cfa594cc2a3df3885de92d407edc6675 (diff)
Dev tools and directory structure rework.
-rw-r--r--.github/workflows/auto.yml12
-rw-r--r--README.md3
-rw-r--r--__main__.py60
-rw-r--r--dev/README.md18
-rw-r--r--dev/__init__.py8
-rw-r--r--dev/commands.py36
-rw-r--r--doc/DEV.md16
-rw-r--r--doc/viikkoraportti5.pdfbin0 -> 26328 bytes
-rw-r--r--pyproject.toml17
-rw-r--r--src/miinaharava/__main__.py57
-rw-r--r--src/miinaharava/app.py (renamed from app.py)0
-rw-r--r--src/miinaharava/board/__init__.py (renamed from board/__init__.py)0
-rw-r--r--src/miinaharava/board/board.py (renamed from board/board.py)0
-rw-r--r--src/miinaharava/board/static.py (renamed from board/static.py)0
-rw-r--r--src/miinaharava/bots/__init__.py (renamed from bots/__init__.py)0
-rw-r--r--src/miinaharava/bots/bot.py (renamed from bots/bot.py)0
-rw-r--r--src/miinaharava/bots/dssp.py (renamed from bots/dssp.py)1
-rw-r--r--src/miinaharava/bots/simple.py (renamed from bots/simple.py)1
-rw-r--r--src/miinaharava/cmdline.py (renamed from cmdline.py)0
-rw-r--r--src/miinaharava/game/__init__.py (renamed from game/__init__.py)0
-rw-r--r--src/miinaharava/game/game.py (renamed from game/game.py)0
-rw-r--r--src/miinaharava/tests/__init__.py (renamed from tests/__init__.py)0
-rw-r--r--src/miinaharava/tests/test_app.py (renamed from tests/test_app.py)0
-rw-r--r--src/miinaharava/tests/test_board.py (renamed from tests/test_board.py)2
-rw-r--r--src/miinaharava/tests/test_bot.py (renamed from tests/test_bot.py)0
-rw-r--r--src/miinaharava/tui/__init__.py (renamed from tui/__init__.py)0
-rw-r--r--src/miinaharava/tui/ansi.py (renamed from tui/ansi.py)0
-rw-r--r--src/miinaharava/tui/ansi_draw.py (renamed from tui/ansi_draw.py)0
-rw-r--r--src/miinaharava/tui/kbd.py (renamed from tui/kbd.py)0
-rw-r--r--src/miinaharava/tui/static.py (renamed from tui/static.py)1
-rw-r--r--src/miinaharava/tui/tui.py (renamed from tui/tui.py)0
31 files changed, 143 insertions, 89 deletions
diff --git a/.github/workflows/auto.yml b/.github/workflows/auto.yml
index 01f65bb..adec8b0 100644
--- a/.github/workflows/auto.yml
+++ b/.github/workflows/auto.yml
@@ -33,13 +33,9 @@ jobs:
- name: Install poetry dependencies
run: poetry install
- # Run unittests
- - name: Run unittests with coverage
- run: poetry run python3 -m coverage run --branch -m pytest -v
-
- # coverage -> xml
- - name: Generate coverage report
- run: poetry run python3 -m coverage xml
+ # Run coverage xml
+ - name: Run unittests with coverage and generate xml
+ run: poetry run covxml
# xml -> codecov
- name: Upload coverage reports to Codecov
@@ -49,4 +45,4 @@ jobs:
# pylint
- name: Run pylint against the code
- run: poetry run python3 -m pylint -v .
+ run: poetry run pylint
diff --git a/README.md b/README.md
index f14cd76..4939406 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,7 @@ Miinaharava ratkaisijalla
- [viikko 2](doc/viikkoraportti2.pdf)
- [viikko 3](doc/viikkoraportti3.pdf)
- [viikko 4](doc/viikkoraportti4.pdf)
+- [viikko 5](doc/viikkoraportti5.pdf)
## Ohjeita:
@@ -22,7 +23,7 @@ Miinaharava ratkaisijalla
`python3 miinaharava`
#### Lataamalla jokin tietty versio
`wget -O -
-https://github.com/Aineopintojen-harjoitustyo-Algoritmit-j/miinaharava/archive/refs/tags/v0.1-gamma.tar.gz | tar xz --strip-components=1 --one-top-level=miinaharava`
+https://github.com/Aineopintojen-harjoitustyo-Algoritmit-j/miinaharava/archive/refs/tags/v0.1-delta.tar.gz | tar xz --strip-components=1 --one-top-level=miinaharava`
### Käyttöohje
- [käyttöohje](doc/käyttöohje.pdf)
diff --git a/__main__.py b/__main__.py
index 253e699..4a91b1e 100644
--- a/__main__.py
+++ b/__main__.py
@@ -1,57 +1,3 @@
-""" __main__.py - Tästä suoritus alkaa """
-import sys
-from app import App
-
-from cmdline import args
-
-vars(args)['board'] = None
-
-if args.count is None and args.file is None:
- app = App(args)
- IS_WIN = app.run()
- del app
- sys.exit(not IS_WIN) # Exit koodeissa 0 on onnistunut suoritus
-
-WIN_COUNT = 0
-
-if args.file is None:
- args.autoplay = 2
- RUN_COUNT = args.count
- for i in range(RUN_COUNT):
- print(end=f" \rSuoritus {i+1:>6}/{RUN_COUNT} ")
- print(end=f"({100*WIN_COUNT/(i if i else 1):.1f}%)..")
- if not args.quiet:
- print()
- app = App(args)
- WIN_COUNT+=app.run()
- del app
-else:
- RUN_COUNT = 0
- with open(args.file, "r", encoding="utf-8") as bfile:
- board = []
- while True:
- line = bfile.readline()
- if not line or (line[0]!='.' and line[0]!='@'):
- if board:
- WIN_PERCENT = (100*WIN_COUNT/RUN_COUNT) if RUN_COUNT else 0
- print(end=
- f" \rAjo ...{args.file[-18:]:} ({RUN_COUNT+1}): "
- f"({WIN_PERCENT:.1f}%).."
- )
- if not args.quiet:
- print()
- args.board = board
- app = App(args)
- WIN_COUNT += app.run()
- RUN_COUNT += 1
- del app
- board = []
- if not line:
- break
- continue
- board.append([x=='@' for x in line if x in ('.', '@')])
-
-print(
- f"\n## Voittoja {WIN_COUNT}/{RUN_COUNT} "
- f"({(100*WIN_COUNT/RUN_COUNT) if RUN_COUNT else 0:.1f}%)"
-)
+""" __main__.py - Käynnistellään ohjelma src/miinaharava kansiosta """
+from runpy import run_path
+run_path("src/miinaharava", run_name="miinaharava")
diff --git a/dev/README.md b/dev/README.md
new file mode 100644
index 0000000..dd0b2dc
--- /dev/null
+++ b/dev/README.md
@@ -0,0 +1,18 @@
+# Ohjeita kehitykseen
+## Riippuvuuksien asennus:
+`PYTHON_KEYRING_BACKEND=keyring.backends.fail.Keyring poetry install`
+
+## Aja pytest:
+`poetry run pytest`
+
+## Generoi haarakattavuusraportti:
+`poetry run covhtml`
+
+## Avaa haarakattavuusraportti Firefoxilla:
+`poetry run covff`
+
+## Linttaus:
+`poetry run pylint`
+
+## Kaikki
+`poetry run all`
diff --git a/dev/__init__.py b/dev/__init__.py
new file mode 100644
index 0000000..52cc7d9
--- /dev/null
+++ b/dev/__init__.py
@@ -0,0 +1,8 @@
+from .commands import (
+ dev_pylint,
+ dev_pytest,
+ dev_coverage,
+ dev_covhtml,
+ dev_covxml,
+ dev_covff,
+ dev_all)
diff --git a/dev/commands.py b/dev/commands.py
new file mode 100644
index 0000000..ed9341a
--- /dev/null
+++ b/dev/commands.py
@@ -0,0 +1,36 @@
+import pytest
+import pylint
+from subprocess import run
+
+def dev_pylint():
+ return pylint.run_pylint(argv=["-v", "src/miinaharava"])
+
+def dev_pytest():
+ return pytest.main(["-v"])
+
+def dev_coverage():
+ return run(
+ "poetry run python3 -m coverage run --branch -m pytest -v ".split()
+ ).returncode
+
+def dev_covhtml():
+ if e := dev_coverage(): return e
+ return run(
+ "poetry run python3 -m coverage html".split()
+ ).returncode
+
+def dev_covxml():
+ if e := dev_coverage(): return e
+ return run(
+ "poetry run python3 -m coverage xml".split()
+ ).returncode
+
+def dev_covff():
+ if e := dev_covhtml(): return e
+ return run(
+ "firefox htmlcov/index.html".split()
+ ).returncode
+
+def dev_all():
+ if e := dev_covff(): return e
+ return dev_pylint()
diff --git a/doc/DEV.md b/doc/DEV.md
deleted file mode 100644
index 6f3eec4..0000000
--- a/doc/DEV.md
+++ /dev/null
@@ -1,16 +0,0 @@
-# Ohjeita kehitykseen
-## Riippuvuuksien asennus:
-`PYTHON_KEYRING_BACKEND=keyring.backends.fail.Keyring poetry install --no-root`
-
-## Aja pytest:
-`poetry run python3 -m pytest`
-
-## Generoi haarakattavuusraportti:
-`poetry run python3 -m coverage run --branch -m pytest -v && poetry run python3 -m coverage html && firefox htmlcov/index.html`
-
-## Linttaus:
-`poetry run python3 -m pylint -v .`
-
-## Kaikki samassa:
-`poetry run python3 -m coverage run --branch -m pytest -v && poetry run python3 -m coverage html && firefox htmlcov/index.html && poetry run python3 -m pylint -v .`
-
diff --git a/doc/viikkoraportti5.pdf b/doc/viikkoraportti5.pdf
new file mode 100644
index 0000000..1aadf0a
--- /dev/null
+++ b/doc/viikkoraportti5.pdf
Binary files differ
diff --git a/pyproject.toml b/pyproject.toml
index fd1ea78..ca26e7d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,9 +1,10 @@
[tool.poetry]
name = "miinaharava"
-version = "0.1.0"
+version = "0.1"
description = "Miinaharava ratkaisijalla"
authors = ["Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi>"]
readme = "README.md"
+packages = [ { include = "miinaharava", from = "src" } ]
[tool.poetry.dependencies]
python = "^3.10"
@@ -13,14 +14,18 @@ pytest = "^7.4.4"
coverage = "^7.4.0"
pylint = "^3.0.3"
+[tool.poetry.scripts]
+pylint = "dev:dev_pylint"
+pytest = "dev:dev_pytest"
+covhtml = "dev:dev_covhtml"
+covxml = "dev:dev_covxml"
+covff = "dev:dev_covff"
+all = "dev:dev_all"
+
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.pylint.main]
recursive = true
-source-roots = ["./"]
-
-[tool.pylint.basic]
-
-[tool.pylint.messages]
+source-roots = ["src/miinaharava/"]
diff --git a/src/miinaharava/__main__.py b/src/miinaharava/__main__.py
new file mode 100644
index 0000000..ba7a25f
--- /dev/null
+++ b/src/miinaharava/__main__.py
@@ -0,0 +1,57 @@
+""" __main__.py - Tästä suoritus alkaa """
+import sys
+
+from app import App
+from cmdline import args
+
+vars(args)['board'] = None
+
+if args.count is None and args.file is None:
+ app = App(args)
+ IS_WIN = app.run()
+ del app
+ sys.exit(not IS_WIN) # Exit koodeissa 0 on onnistunut suoritus
+
+WIN_COUNT = 0
+
+if args.file is None:
+ args.autoplay = 2
+ RUN_COUNT = args.count
+ for i in range(RUN_COUNT):
+ print(end=f" \rSuoritus {i+1:>6}/{RUN_COUNT} ")
+ print(end=f"({100*WIN_COUNT/(i if i else 1):.1f}%)..")
+ if not args.quiet:
+ print()
+ app = App(args)
+ WIN_COUNT+=app.run()
+ del app
+else:
+ RUN_COUNT = 0
+ with open(args.file, "r", encoding="utf-8") as bfile:
+ board = []
+ while True:
+ line = bfile.readline()
+ if not line or (line[0]!='.' and line[0]!='@'):
+ if board:
+ WIN_PERCENT = (100*WIN_COUNT/RUN_COUNT) if RUN_COUNT else 0
+ print(end=
+ f" \rAjo ...{args.file[-18:]:} ({RUN_COUNT+1}): "
+ f"({WIN_PERCENT:.1f}%).."
+ )
+ if not args.quiet:
+ print()
+ args.board = board
+ app = App(args)
+ WIN_COUNT += app.run()
+ RUN_COUNT += 1
+ del app
+ board = []
+ if not line:
+ break
+ continue
+ board.append([x=='@' for x in line if x in ('.', '@')])
+
+print(
+ f"\n## Voittoja {WIN_COUNT}/{RUN_COUNT} "
+ f"({(100*WIN_COUNT/RUN_COUNT) if RUN_COUNT else 0:.1f}%)"
+)
diff --git a/app.py b/src/miinaharava/app.py
index 8553fe5..8553fe5 100644
--- a/app.py
+++ b/src/miinaharava/app.py
diff --git a/board/__init__.py b/src/miinaharava/board/__init__.py
index ba87812..ba87812 100644
--- a/board/__init__.py
+++ b/src/miinaharava/board/__init__.py
diff --git a/board/board.py b/src/miinaharava/board/board.py
index 36ceb62..36ceb62 100644
--- a/board/board.py
+++ b/src/miinaharava/board/board.py
diff --git a/board/static.py b/src/miinaharava/board/static.py
index 4804ded..4804ded 100644
--- a/board/static.py
+++ b/src/miinaharava/board/static.py
diff --git a/bots/__init__.py b/src/miinaharava/bots/__init__.py
index f346d07..f346d07 100644
--- a/bots/__init__.py
+++ b/src/miinaharava/bots/__init__.py
diff --git a/bots/bot.py b/src/miinaharava/bots/bot.py
index 2f3baae..2f3baae 100644
--- a/bots/bot.py
+++ b/src/miinaharava/bots/bot.py
diff --git a/bots/dssp.py b/src/miinaharava/bots/dssp.py
index 0cace12..1815b49 100644
--- a/bots/dssp.py
+++ b/src/miinaharava/bots/dssp.py
@@ -1,5 +1,6 @@
""" bots/dssp.py - päättelee kahden vierekkäisen laatan perusteella """
from random import sample
+
from .simple import SimpleBot
class DSSPBot(SimpleBot):
diff --git a/bots/simple.py b/src/miinaharava/bots/simple.py
index 54e2d05..46b9506 100644
--- a/bots/simple.py
+++ b/src/miinaharava/bots/simple.py
@@ -1,5 +1,6 @@
""" bots/simple.py - yksinkertainen botti joka etsii vain yhdeltä laatalta """
from random import sample
+
from .bot import Bot
class SimpleBot(Bot):
diff --git a/cmdline.py b/src/miinaharava/cmdline.py
index 533c40f..533c40f 100644
--- a/cmdline.py
+++ b/src/miinaharava/cmdline.py
diff --git a/game/__init__.py b/src/miinaharava/game/__init__.py
index 066e2e3..066e2e3 100644
--- a/game/__init__.py
+++ b/src/miinaharava/game/__init__.py
diff --git a/game/game.py b/src/miinaharava/game/game.py
index fefcf8f..fefcf8f 100644
--- a/game/game.py
+++ b/src/miinaharava/game/game.py
diff --git a/tests/__init__.py b/src/miinaharava/tests/__init__.py
index e69de29..e69de29 100644
--- a/tests/__init__.py
+++ b/src/miinaharava/tests/__init__.py
diff --git a/tests/test_app.py b/src/miinaharava/tests/test_app.py
index 1d13a71..1d13a71 100644
--- a/tests/test_app.py
+++ b/src/miinaharava/tests/test_app.py
diff --git a/tests/test_board.py b/src/miinaharava/tests/test_board.py
index 37a2d54..8aeac89 100644
--- a/tests/test_board.py
+++ b/src/miinaharava/tests/test_board.py
@@ -1,8 +1,8 @@
""" tests/test_board.py - Testit pelilaudalle """
import unittest
-from board import Board, Level, LevelSpecs
+from board import Board, Level, LevelSpecs
def matrix_equals(m1, m2):
""" matrix_equals - apufunktio testaa onko matriisit samat """
diff --git a/tests/test_bot.py b/src/miinaharava/tests/test_bot.py
index 4dab148..4dab148 100644
--- a/tests/test_bot.py
+++ b/src/miinaharava/tests/test_bot.py
diff --git a/tui/__init__.py b/src/miinaharava/tui/__init__.py
index 0c8d632..0c8d632 100644
--- a/tui/__init__.py
+++ b/src/miinaharava/tui/__init__.py
diff --git a/tui/ansi.py b/src/miinaharava/tui/ansi.py
index c25ff6c..c25ff6c 100644
--- a/tui/ansi.py
+++ b/src/miinaharava/tui/ansi.py
diff --git a/tui/ansi_draw.py b/src/miinaharava/tui/ansi_draw.py
index ba71fdb..ba71fdb 100644
--- a/tui/ansi_draw.py
+++ b/src/miinaharava/tui/ansi_draw.py
diff --git a/tui/kbd.py b/src/miinaharava/tui/kbd.py
index a31e56f..a31e56f 100644
--- a/tui/kbd.py
+++ b/src/miinaharava/tui/kbd.py
diff --git a/tui/static.py b/src/miinaharava/tui/static.py
index 60442c0..50dbb44 100644
--- a/tui/static.py
+++ b/src/miinaharava/tui/static.py
@@ -1,6 +1,7 @@
""" tui/static.py - Staattiset määritykset tui:ssa tarvittaville jutuille. """
from enum import Enum
from dataclasses import dataclass
+
from board import Tile
class Action(Enum):
diff --git a/tui/tui.py b/src/miinaharava/tui/tui.py
index d7f7fb3..d7f7fb3 100644
--- a/tui/tui.py
+++ b/src/miinaharava/tui/tui.py