diff --git a/.gitignore b/.gitignore index 7bfcd7a..067e3b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ __pycache__/ -*.pyc \ No newline at end of file +*.pyc +dist/ +build/ +*.egg-info/ \ No newline at end of file diff --git a/kostky/__init__.py b/kostky/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kostky/__main__.py b/kostky/__main__.py new file mode 100644 index 0000000..ac32257 --- /dev/null +++ b/kostky/__main__.py @@ -0,0 +1,4 @@ +from kostky.kostky import main + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/hodnoty.csv b/kostky/hodnoty.csv similarity index 100% rename from hodnoty.csv rename to kostky/hodnoty.csv diff --git a/main.py b/kostky/kostky.py similarity index 87% rename from main.py rename to kostky/kostky.py index d103c9d..92e2333 100644 --- a/main.py +++ b/kostky/kostky.py @@ -1,9 +1,11 @@ -from typing import Any -from random import randint -from os import system, name -import re import csv +import re from collections import Counter +from importlib.resources import files +from os import name, system +from random import randint +from typing import Any + from tabulate import tabulate score: int = 0 @@ -15,19 +17,19 @@ h_bool: bool = True aggr: dict[str, int] = {} final_score: int = 10000 -with open("hodnoty.csv", "r") as csv_file: - csv_reader = csv.reader(csv_file) +csv_text = files(__package__).joinpath("hodnoty.csv").read_text(encoding="utf-8") +csv_reader = csv.reader(csv_text.splitlines()) - for row in csv_reader: - key = str(row[0]) - value = int(row[1]) +for row in csv_reader: + key = str(row[0]) + value = int(row[1]) - hodnoty[key] = value + hodnoty[key] = value def throw(count: int) -> str: count = int(count) new_throw: list[str] = [] - for dice in range(count): + for _dice in range(count): new_throw.append(str(randint(1, 6))) new_throw_str: str = "".join(new_throw) return new_throw_str @@ -39,7 +41,7 @@ def show_throw(throw: str) -> str: pretty_list: str = ", ".join(throw_temp) pretty_list += "\n" - for i in range(1, len(throw_temp) + 1): + for _i in range(1, len(throw_temp) + 1): pretty_list += "^ " pretty_list += "\n" for i in range(1, len(throw_temp) + 1): @@ -47,10 +49,7 @@ def show_throw(throw: str) -> str: return pretty_list def clear() -> None: - if name == 'nt': - _ = system('cls') - else: - _ = system('clear') + _ = system('cls') if name == 'nt' else system('clear') def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]: @@ -78,16 +77,25 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]: inp = str(inp) if re.search(r"^\d+$", inp): if len(inp) > count: - data: tuple[Any, ...] = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu: ", count, throw) + data: tuple[Any, ...] = ( + "msg", + "ER01", + "Tolika kostkami nemůžete hodit. Zkuste to znovu: ", + count, + throw + ) else: for x in inp: x = int(x) if x > count: - if count == 1: - ran = "1" - else: - ran = f"1–{count}" - data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({ran}): ", count, throw) + ran = "1" if count == 1 else f"1–{count}" + data = ( + "msg", + "ER02", + f"Zvolte prosím kostky v platném rozsahu ({ran}): ", + count, + throw + ) return data old_throw: list[str] = [] pick: list[str] = [] @@ -203,8 +211,9 @@ def add_players() -> None: else: break -def to_sorted_tuple(d: dict[str, int], s: bool = True) -> tuple[list[tuple[int, str, int]], dict[str, int]]: - L: list[tuple[str, int]] = [] +def to_sorted_tuple(d: dict[str, int], s: bool = True) -> tuple[list[tuple[int, str, int]], + dict[str, int]]: + L: list[tuple[int, str, int]] = [] if s: d = dict(sorted(d.items(), key=lambda x: x[1], reverse=True)) @@ -276,7 +285,8 @@ def game(data: tuple) -> None: if count == 0: count = 6 msg: str = ("Jakou akci chcete provést?\n" - " - Zadejte kombinaci kostek k ponechání (dojde k jejich vyhodnocení): [pozice kostek] (např. 1 nebo 34 nebo 123456).\n" + " - Zadejte kombinaci kostek k ponechání (dojde k jejich vyhodnocení): " + "[pozice kostek] (např. 1 nebo 34 nebo 123456).\n" " - Hodit znovu: [h].\n" f" - Ukončit hod a ponechat si skóre z tohoto hodu ({score}): [k].\n" " - Ukončit hru: [exit].\n" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ce6429b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,50 @@ +[build-system] +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" + +[project] +name = "kostky" +dynamic = ["version"] +description = "Textová hra v kostky." +readme = "README.md" +requires-python = ">=3.9" +license = "GPL-3.0-or-later" +license-files = ["LICENSE"] +authors = [{ name = "David Spáčil" }] +keywords = ["hra", "kostky", "cli"] +classifiers = [ + "Programming Language :: Python :: 3", + "Environment :: Console", + "Operating System :: OS Independent", + "Topic :: Games/Entertainment", +] +dependencies = [ + "tabulate", +] + +[project.optional-dependencies] +dev = ["mypy", "ruff", "types-tabulate"] + +[project.urls] +Repository = "https://gitea.spacilovi.eu/david/kostky" + +[project.scripts] +kostky = "kostky.kostky:main" + +[tool.hatch.version] +source = "vcs" + +[tool.hatch.build.targets.wheel] +packages = ["kostky"] + +[tool.mypy] +python_version = "3.9" +strict = true +files = ["kostky"] + +[tool.ruff] +target-version = "py39" +line-length = 100 + +[tool.ruff.lint] +select = ["E", "F", "I", "UP", "B", "SIM"] \ No newline at end of file