diff --git a/python/.tool-versions b/python/.tool-versions new file mode 100644 index 0000000..234139b --- /dev/null +++ b/python/.tool-versions @@ -0,0 +1 @@ +python 3.13 diff --git a/python/README.md b/python/README.md index 98ad12a..75cb987 100644 --- a/python/README.md +++ b/python/README.md @@ -2,16 +2,29 @@ Skeleton project for Python. -## Usage (on MacOS / Linux) -- `./script/setup` to install dependencies (uses [homebrew](https://brew.sh/)) -- `./script/test` to run the tests +## Prerequisites + +The toolchain this project needs is declared in [`.tool-versions`](./.tool-versions): + +``` +python 3.13 +``` + +Install those however you prefer, as long as they end up on your `PATH`. The quickest route is +[mise](https://mise.jdx.dev/), which reads the file for you: -## Usage (on Windows) -- Install Python 3. You can either download from https://www.python.org/downloads/ or run `python` in a terminal to open Windows store Python download. -- Run `./script/test.bat` in terminal to run tests +```sh +mise install +``` + +## Usage +- `./script/setup` to create the virtual environment +- `./script/test` to run the tests +- `./script/start` to run the exercise ## Structure - Code located in [`pairing_exercise.py`](./pairing_exercise.py) - Tests located in [`test_pairing_exercise.py`](./test_pairing_exercise.py) -However, you're free to organise your code as you like. +However, you're free to organise your code as you like. + diff --git a/python/script/setup b/python/script/setup index 9b77adb..dc11e2a 100755 --- a/python/script/setup +++ b/python/script/setup @@ -1,14 +1,11 @@ #!/usr/bin/env bash -set -e +set -euo pipefail -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -pushd "$DIR" +cd "$(dirname "${BASH_SOURCE[0]}")/.." -brew install python3 +python3 -m venv venv -pip3 install virtualenv - -virtualenv ../venv - -popd +if [[ -f requirements.txt ]]; then + venv/bin/pip install -r requirements.txt +fi diff --git a/python/script/start b/python/script/start new file mode 100755 index 0000000..002d8ea --- /dev/null +++ b/python/script/start @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -euo pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +venv/bin/python pairing_exercise.py diff --git a/python/script/test b/python/script/test index c4115ce..96bba79 100755 --- a/python/script/test +++ b/python/script/test @@ -1,7 +1,7 @@ #!/usr/bin/env bash -set -e +set -euo pipefail -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +cd "$(dirname "${BASH_SOURCE[0]}")/.." -"$DIR"/../venv/bin/python -m unittest discover +venv/bin/python -m unittest discover diff --git a/python/script/test.bat b/python/script/test.bat deleted file mode 100644 index c2145d5..0000000 --- a/python/script/test.bat +++ /dev/null @@ -1,9 +0,0 @@ -:: Setup python virtual environment if it doesn't already exist -@echo off -if not exist venv\ ( - python -m venv .\venv -) - -call .\venv\Scripts\activate.bat - -python -m unittest discover