diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..9fbf6d1 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,36 @@ +name: release + +on: + push: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: 3.7 + + - name: Install dependencies + run: | + pip3 install -e . + pip3 install pytest wheel + + - name: Run tests + run: pytest -v tests + + - name: Build + run: | + python3 setup.py sdist + python3 setup.py bdist_wheel + + - name: Release to PyPI + env: + TWINE_USERNAME: ${{ secrets.PYPI_USER }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: twine upload --verbose dist/* || echo 'File exists' diff --git a/INSTALL.md b/INSTALL.md index 2e3b309..37bd3df 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -24,7 +24,7 @@ * Download the repository by clicking the green *Clone or download* on this page and *Download zip*. Extract the contents. * Make sure you have a python installation, I will assume Anaconda (Python 3.7), available [here](https://www.anaconda.com/products/individual#download-section). * Open 'Anaconda prompt' from the start menu and navigate to where you extracted the zip file using the `cd ` command. -* Execute the command `python setup.py install` +* Execute the command `pip3 install .` * Start the app by running `katrain` in the directory where you downloaded the scripts. # Installation from sources for Linux users @@ -34,11 +34,9 @@ * Open a terminal. * Run the command `git clone https://github.com/sanderland/katrain.git` to download the repository. * Changing directory using `cd katrain` - * Run the command `python3 setup.py install` - * If you get an error about permissions, try `python3 setup.py install --user` + * Run the command `pip3 install .` to install the package globally, then run the program by typing `katrain` in the terminal. + * If you prefer not to install, run without installing using `python -m katrain` * A binary for KataGo is included, but if you have compiled your own, point the 'engine/katago' setting to the relevant KataGo v1.4+ binary. -* Run the program by typing `katrain` in the terminal. - # Configuring the GPU(s) KataGo uses diff --git a/katrain/__main__.py b/katrain/__main__.py index 26801a4..6db3bc9 100644 --- a/katrain/__main__.py +++ b/katrain/__main__.py @@ -19,7 +19,7 @@ from kivy.storage.jsonstore import JsonStore from kivy.uix.popup import Popup from katrain.core.ai import ai_move -from katrain.core.common import OUTPUT_INFO, OUTPUT_ERROR, OUTPUT_DEBUG, OUTPUT_EXTRA_DEBUG, OUTPUT_KATAGO_STDERR, find_package_resource, clean_temp +from katrain.core.common import OUTPUT_INFO, OUTPUT_ERROR, OUTPUT_DEBUG, OUTPUT_EXTRA_DEBUG, OUTPUT_KATAGO_STDERR, find_package_resource from katrain.core.engine import KataGoEngine from katrain.core.game import Game, IllegalMoveException, KaTrainSGF from katrain.core.sgf_parser import Move, ParseError @@ -338,7 +338,6 @@ class KaTrainApp(App): def on_request_close(self, *args): if getattr(self, "gui", None) and self.gui.engine: self.gui.engine.shutdown() - clean_temp() def signal_handler(self, *args): if self.gui.debug_level >= OUTPUT_DEBUG: diff --git a/katrain/core/common.py b/katrain/core/common.py index 83bd964..9b5b7a9 100644 --- a/katrain/core/common.py +++ b/katrain/core/common.py @@ -1,5 +1,5 @@ -from typing import Any, List, Tuple import os +from typing import Any, List, Tuple try: import importlib.resources as pkg_resources @@ -30,21 +30,12 @@ def evaluation_class(points_lost: float, eval_thresholds: List[float]): return i -resource_scopes = [] - - -def clean_temp(): - for s in resource_scopes: - s.__exit__(None, None, None) - - def find_package_resource(path): if path.startswith("katrain"): parts = path.replace("\\", "/").split("/") try: - path_obj = pkg_resources.path(".".join(parts[:-1]), parts[-1]).__enter__() - resource_scopes.append(path_obj) - return str(path_obj) + with pkg_resources.path(".".join(parts[:-1]), parts[-1]) as path_obj: + return str(path_obj) # this will clean up if egg etc, but these don't work anyway except (ModuleNotFoundError, FileNotFoundError) as e: print(f"File {path} not found, installation possibly broken") return f"FILENOTFOUND::{path}" diff --git a/katrain/core/engine.py b/katrain/core/engine.py index afbdfcc..a36acdb 100644 --- a/katrain/core/engine.py +++ b/katrain/core/engine.py @@ -1,6 +1,8 @@ import json +import os import shlex import subprocess +import stat import sys import threading import time @@ -36,8 +38,8 @@ class KataGoEngine: else: # e.g. MacOS after brewing executable = "katago" - modelfile, configfile = find_package_resource(config["model"]), find_package_resource(config["config"]) - self.command = f'{find_package_resource(executable)} analysis -model "{modelfile}" -config "{configfile}" -analysis-threads {config["threads"]}' + modelfile, configfile, exefile = find_package_resource(config["model"]), find_package_resource(config["config"]), find_package_resource(executable) + self.command = f'{exefile} analysis -model "{modelfile}" -config "{configfile}" -analysis-threads {config["threads"]}' if not sys.platform.startswith("win"): self.command = shlex.split(self.command) self.queries = {} # outstanding query id -> start time and callback diff --git a/setup.py b/setup.py index 1355a81..457ac85 100644 --- a/setup.py +++ b/setup.py @@ -36,11 +36,12 @@ setup( url="https://github.com/sanderland/katrain", license="MIT", install_requires=[ - "kivy", + "kivy>=1.11,<2", "kivy_deps.glew;platform_system=='Windows'", "kivy_deps.sdl2;platform_system=='Windows'", "kivy_deps.gstreamer;platform_system=='Windows'", "importlib_resources ;python_version<'3.7'", + "wheel", ], python_requires=">=3.6, <3.8", entry_points={"console_scripts": ["katrain=katrain.__main__:run_app"]},