diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f17443a..cbae1b7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -105,10 +105,10 @@ curl "http://localhost:5000/?fen=rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR%20w This engine implements the UCI protocol and can be used as a bot on [Lichess](https://lichess.org). You can use the python bridge between Lichess Bot API and the engine: [https://github.com/ShailChoksi/lichess-bot](https://github.com/ShailChoksi/lichess-bot). -To run it as a bot you'll need to produce a python executable. [PyInstaller](https://pyinstaller.readthedocs.io/en/stable/) can produce it by running the following command: +To run it as a bot you'll need to produce a python executable. We use [PyInstaller](https://pyinstaller.readthedocs.io/en/stable/) via our Makefile: ```shell -python3 -m PyInstaller main.py +make build-lichess ``` This creates a `build` and `dist` folder. The `dist` folder contains the main executable in a folder called `main`. All the files inside `main` need to be copied over to `/lichess-bot/engines` for it to work. You can checkout [/lichess](lichess/README.md) for further lichess setup. diff --git a/Makefile b/Makefile index da140c4..df62a96 100644 --- a/Makefile +++ b/Makefile @@ -21,5 +21,8 @@ install: venv activate requirements.txt: pyproject.toml ensure-uv uv pip compile pyproject.toml -o requirements.txt +build-lichess: ensure-uv + uv run pyinstaller moonfish/main.py --name moonfish --onefile --hidden-import chess --add-data "opening_book:opening_book" + clean: - rm -rf .venv __pycache__ .mypy_cache dist *.egg-info \ No newline at end of file + rm -rf .venv __pycache__ .mypy_cache dist build *.egg-info *.spec \ No newline at end of file diff --git a/lichess/README.md b/lichess/README.md index 36a70d8..26c7bb9 100644 --- a/lichess/README.md +++ b/lichess/README.md @@ -4,7 +4,7 @@ To run the engine as a lichess bot you'll need to install the [Lichess Bot API]( If you pull [https://github.com/ShailChoksi/lichess-bot](https://github.com/ShailChoksi/lichess-bot) to the same parent directory of moonfish, such that your local setup looks like: -```bash +```shell $ tree moonfish/ lichess-bot/ -L 1 moonfish/ ├── LICENSE @@ -20,6 +20,6 @@ you could then run the below to setup (build + move files) lichess to work with don't forget to create a [`.env`](../.env.example) with your lichess API token (with bot:play scope) -```bash +```shell lichess/setup_macos.sh ``` diff --git a/lichess/setup_macos.sh b/lichess/setup_macos.sh index 7e84f6b..575bef5 100755 --- a/lichess/setup_macos.sh +++ b/lichess/setup_macos.sh @@ -24,7 +24,7 @@ source .env read -p "Do you want to build a new binary? (y/n) " answer answer=$(echo "$answer" | tr '[:upper:]' '[:lower:]') if [[ "$answer" == "y" || "$answer" == "yes" ]]; then - python -m PyInstaller main.py --onefile + make build-lichess fi # fetch opening book if not already downloaded @@ -39,7 +39,7 @@ brew install gettext if [ -f ../lichess-bot/engines/main ]; then rm ../lichess-bot/engines/main fi -cp dist/main ../lichess-bot/engines/main +cp dist/moonfish ../lichess-bot/engines/main mkdir -p ../lichess-bot/engines/opening_book cp opening_book/cerebellum.bin ../lichess-bot/engines/opening_book/cerebellum.bin bash .env