diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3ccdaff..49d9db0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: python -m pip install -r requirements.txt - name: Run tests run: | - bash bin/test.sh + python scripts/test.py - name: Update release branch if: github.ref == 'refs/heads/main' run: | diff --git a/README.md b/README.md index 5905867..d510c1c 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Only usable by users with the `owner` scope. Only usable in a DM with the bot us Syncs bot commands and reloads the state file, or closes down the bot. ## Development -Current development is on Linux, though running on Mac or Windows should work fine, although some scripts are currently bash. +Current development is on Linux, though running on Mac or Windows should work fine. ### Dependencies * `python3` - Obviously, ideally 3.11 @@ -51,10 +51,10 @@ pip install -r requirements.txt VSCode can then be configured to use this new `.venv` and is the recommended way to develop. ### Tests -Python tests are written to use `pytest` and cover most internal functionality. Tests can be run in the same way as in the Github Actions with [`bin/test.sh`](`bin/test.sh`), which lints all python code and runs any tests with `pytest`. +Python tests are written to use `pytest` and cover most internal functionality. Tests can be run in the same way as in the Github Actions with [`scripts/test.py`](`scripts/test.py`), which lints all python code and runs any tests with `pytest`. #### Coverage -A helper script [`bin/coverage.sh`](bin/coverage.sh) is available to generate a html view on current code coverage. +A helper script [`scripts/test-cov.py`](scripts/test-cov.py) is available to generate a html view on current code coverage. ## Hosting @@ -82,11 +82,11 @@ See [`py/config.py`](py/config.py) for explanations for any extra settings here. ### Running It is recommended to only ever run the `release` branch in production, as this branch has passed the tests. -Running the bot can be as simple as `python3 bin/matchy.py`, but a [`bin/run.py`](bin/run.py) script is provided to update with `git pull`, enter the `.venv`, install new `pip` dependencies and run the bot. +Running the bot can be as simple as `python3 scripts/matchy.py`, but a [`scripts/run.py`](scripts/run.py) script is provided to update to the latest release, install any new `pip` dependencies and run the bot. -The following command can be used to execute `run.sh` command on a loop, allowing the bot to be updated with a simple `$close` command from an owner, exiting the loop if the bot throws any fatal errors. +The following command can be used to execute `run.py` on a loop, allowing the bot to be updated with a simple `$close` command from an `owner` user, but will still exit the loop if the bot throws a fatal error. ``` -while ./bin/run.sh; end +while ./scripts/run.py; end ``` ### State diff --git a/bin/coverage.sh b/bin/coverage.sh deleted file mode 100755 index b1ddb63..0000000 --- a/bin/coverage.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -x -set -e - -pytest --cov=. --cov-report=html \ No newline at end of file diff --git a/bin/run.sh b/bin/run.sh deleted file mode 100755 index 7b09ccb..0000000 --- a/bin/run.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -x -set -e - -git pull -if [ ! -d .venv ]; then - python3 -m venv .venv -fi -source .venv/bin/activate -python -m pip install -r requirements.txt -python py/matchy.py \ No newline at end of file diff --git a/bin/test.sh b/bin/test.sh deleted file mode 100755 index d019117..0000000 --- a/bin/test.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -set -x -set -e - -# Check formatting and linting -flake8 --max-line-length 120 $(git ls-files '*.py') - -# Run pytest -pytest \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 893184e..cdc2eb2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,14 +2,18 @@ aiohappyeyeballs==2.3.5 aiohttp==3.10.3 aiosignal==1.3.1 attrs==24.2.0 +autopep8==2.3.1 coverage==7.6.1 discord.py==2.4.0 flake8==7.1.1 frozenlist==1.4.1 +gitdb==4.0.11 +GitPython==3.1.43 idna==3.7 iniconfig==2.0.0 mccabe==0.7.0 multidict==6.0.5 +overrides==7.7.0 packaging==24.1 pluggy==1.5.0 pycodestyle==2.12.1 @@ -17,4 +21,5 @@ pyflakes==3.2.0 pytest==8.3.2 pytest-cov==5.0.0 schema==0.7.7 +smmap==5.0.1 yarl==1.9.4 diff --git a/scripts/run.py b/scripts/run.py new file mode 100755 index 0000000..a9440fe --- /dev/null +++ b/scripts/run.py @@ -0,0 +1,17 @@ +import sys +import git +import subprocess + +# Pull the release branch +repo = git.Repo(search_parent_directories=True) +if repo.active_branch.name != "release": + print(f"Refusing to run on branch '{repo.active_branch.name}'") + sys.exit(1) +repo.remotes.origin.pull() + +# Install any new pip requirements +subprocess.run([sys.executable, "-m", "pip", "install", + "-r", "requirements.txt"], check=True) + +# Run Matchy! +subprocess.run([sys.executable, "py/matchy.py"], check=True) diff --git a/scripts/test-cov.py b/scripts/test-cov.py new file mode 100755 index 0000000..5363c33 --- /dev/null +++ b/scripts/test-cov.py @@ -0,0 +1,9 @@ +import pytest +import sys + +# Run pytest with a coverage report +exitcode = pytest.main([ + "--cov", ".", + "--cov-report", "html" +]) +sys.exit(exitcode) diff --git a/scripts/test.py b/scripts/test.py new file mode 100644 index 0000000..ceebefe --- /dev/null +++ b/scripts/test.py @@ -0,0 +1,15 @@ +import pytest +import sys +from flake8.main.application import Application + +# Run flake +app = Application() +ret = app.run(["--max-line-length", "120", "py/", "scripts/"]) +flake_exitcode = app.exit_code() +print(flake_exitcode) + +# Run pytest +pytest_exitcode = pytest.main() + +# Exit based on the two codes +sys.exit(flake_exitcode + pytest_exitcode)