From c6af552dbdc8232b87f67eecfa1c5f319bd568d1 Mon Sep 17 00:00:00 2001
From: Sander Land <48946947+sanderland@users.noreply.github.com>
Date: Sat, 23 Jan 2021 23:08:24 +0900
Subject: [PATCH] Add Github action for OSX build (#332)
---
.github/workflows/osxbuild.yaml | 70 +++++++++++++++++++++++++++++++++
.github/workflows/test.yaml | 2 +-
INSTALL.md | 10 +++++
README.md | 3 +-
katrain/core/engine.py | 7 +++-
spec/KaTrain.spec | 2 +-
6 files changed, 88 insertions(+), 6 deletions(-)
create mode 100644 .github/workflows/osxbuild.yaml
diff --git a/.github/workflows/osxbuild.yaml b/.github/workflows/osxbuild.yaml
new file mode 100644
index 0000000..2fd5705
--- /dev/null
+++ b/.github/workflows/osxbuild.yaml
@@ -0,0 +1,70 @@
+name: build_osx
+
+on:
+ push:
+ branches: [ master ]
+
+jobs:
+ osx_app:
+ runs-on: macos-10.15
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Python
+ uses: actions/setup-python@v2
+ with:
+ python-version: 3.8
+ - name: Build KataGo
+ run: |
+ rm katrain/KataGo/katago
+ rm katrain/KataGo/*.dll
+ rm katrain/KataGo/katago.exe
+ cd ..
+ git clone https://github.com/lightvector/KataGo.git
+ pushd KataGo/cpp
+ cmake . -DUSE_BACKEND=OPENCL
+ make
+ cp katago ../../katrain/katrain/KataGo/katago-osx
+ - name: Get Kivy dependencies
+ run: |
+ cd ..
+ git clone https://github.com/kivy/kivy-sdk-packager.git
+ cd kivy-sdk-packager/osx
+ curl -O -L https://kivy.org/downloads/ci/osx/app/Kivy.dmg
+ hdiutil attach Kivy.dmg -mountroot .
+ cp -R Kivy/Kivy.app KaTrain.app
+ - name: Install KaTrain pip dependencies
+ run: |
+ pushd ../kivy-sdk-packager/osx/KaTrain.app/Contents/Resources/venv/bin
+ source activate
+ popd
+ python -m pip install .
+ - name: Finalize KaTrain bundle
+ run: |
+ cd ../kivy-sdk-packager/osx
+ pushd KaTrain.app/Contents/Resources/
+ ln -s ./venv/bin/KaTrain yourapp
+ popd
+ ./fix-bundle-metadata.sh KaTrain.app -n KaTrain -v "1.7.2" -a "Sander Land" -o "org.katrain.KaTrain" -i "../../katrain/katrain/img/icon.ico"
+ ./cleanup-app.sh KaTrain.app -g 1
+ ./relocate.sh KaTrain.app
+ - name: Create dmg
+ run: |
+ pushd ../kivy-sdk-packager/osx
+ ./create-osx-dmg.sh KaTrain.app KaTrain
+ popd
+ mkdir osx_app
+ cp ../kivy-sdk-packager/osx/KaTrain.dmg osx_app/
+ - name: Upload app as artifact
+ uses: actions/upload-artifact@v2
+ with:
+ name: KaTrainOSX
+ path: osx_app
+ - name: Upload to GitHub Release
+ uses: softprops/action-gh-release@78c309ef59fdb9557cd6574f2e0be552936ed728
+ if: startsWith(github.ref, 'refs/tags/')
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ files: KaTrainOSX/*
+ draft: true
+ fail_on_unmatched_files: true
\ No newline at end of file
diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
index 2fb049f..23e9496 100644
--- a/.github/workflows/test.yaml
+++ b/.github/workflows/test.yaml
@@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- python-version: [3.6, 3.7]
+ python-version: [3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
diff --git a/INSTALL.md b/INSTALL.md
index ae86c72..1a7bd9a 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -10,6 +10,10 @@
##
Installation for MacOS users
### Quick install guide
+You can find downloadable .app files for MacOSX [here](https://github.com/sanderland/katrain/releases).
+Simply download, unzip the file, mount the .dmg and drag the .app file to your application folder, everything is included.
+
+### Command line install guide
[Open a terminal](https://support.apple.com/guide/terminal/open-or-quit-terminal-apd5265185d-f365-44cb-8b09-71a064a42125/mac) and enter the following commands:
```bash
@@ -18,6 +22,7 @@ brew install python3
brew install katago
pip3 install katrain
```
+
Now you can start KaTrain by simply typing `katrain` in a terminal.
These commands install [Homebrew](https://brew.sh), which simplifies installing packages,
@@ -34,6 +39,11 @@ Installation from sources is essentially the same as for Linux, see [here](#Linu
If you encounter SSL errors on downloading model files, you may need to follow [these](https://stackoverflow.com/questions/52805115/certificate-verify-failed-unable-to-get-local-issuer-certificate) instructions to fix your certificates.
+Users with the new M1 macs likely need to install the latest unreleased version of kivy using:
+```bash
+pip3 install "kivy[base] @ https://github.com/kivy/kivy/archive/master.zip"
+```
+
##
Installation for Windows users
### Quick install guide
diff --git a/README.md b/README.md
index 3a2bf1b..4786a01 100644
--- a/README.md
+++ b/README.md
@@ -196,7 +196,7 @@ In addition to shortcuts mentioned above and those shown in the main menu:
## FAQ
-* How can I create themes?
+* How can I create or install themes?
* See [these instructions](THEMES.md).
* The program is running too slowly. How can I speed it up?
* Adjust the number of visits or maximum time allowed in the settings.
@@ -215,7 +215,6 @@ In addition to shortcuts mentioned above and those shown in the main menu:
* Ideas, feedback, and contributions to code or translations are all very welcome.
* For suggestions and planned improvements, see [open issues](http://github.com/sanderland/katrain/issues) on github to check if the functionality is already planned.
- * I am looking for contributors of more translations of both this manual and the program itself. The best way to help with this is to contact me on discord.
* You can contact me on the [Leela Zero & Friends Discord](http://discord.gg/AjTPFpN) (use the #gui channel) to get help, discuss improvements, or simply show your appreciation.
* You can also donate to the project through [Github Sponsors](http://github.com/sponsors/sanderland).
diff --git a/katrain/core/engine.py b/katrain/core/engine.py
index ec6e2d2..fce51f1 100644
--- a/katrain/core/engine.py
+++ b/katrain/core/engine.py
@@ -1,6 +1,7 @@
import copy
import json
import os
+import sys
import queue
import shlex
import subprocess
@@ -63,8 +64,10 @@ class KataGoEngine:
exe = "katrain/KataGo/katago.exe"
elif platform == "linux":
exe = "katrain/KataGo/katago"
- else: # e.g. MacOS after brewing
- exe = "katago"
+ else:
+ exe = find_package_resource("katrain/KataGo/katago-osx") # github actions built
+ if not os.path.isfile(exe):
+ exe = "katago" # e.g. MacOS after brewing
model = find_package_resource(config["model"])
cfg = find_package_resource(config["config"])
diff --git a/spec/KaTrain.spec b/spec/KaTrain.spec
index 6de304e..96b22db 100644
--- a/spec/KaTrain.spec
+++ b/spec/KaTrain.spec
@@ -5,7 +5,7 @@ import subprocess
block_cipher = None
-# pyinstaller spec/katrain.spec --noconfirm
+# pyinstaller spec/KaTrain.spec --noconfirm
# --upx-dir my
a = Analysis(