Rewrite bin scripts to python in scripts/ dir
This commit is contained in:
parent
12727c4d1c
commit
0beb2128bd
9 changed files with 53 additions and 32 deletions
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
@ -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: |
|
||||
|
|
12
README.md
12
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
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
set -x
|
||||
set -e
|
||||
|
||||
pytest --cov=. --cov-report=html
|
11
bin/run.sh
11
bin/run.sh
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
17
scripts/run.py
Executable file
17
scripts/run.py
Executable file
|
@ -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)
|
9
scripts/test-cov.py
Executable file
9
scripts/test-cov.py
Executable file
|
@ -0,0 +1,9 @@
|
|||
import pytest
|
||||
import sys
|
||||
|
||||
# Run pytest with a coverage report
|
||||
exitcode = pytest.main([
|
||||
"--cov", ".",
|
||||
"--cov-report", "html"
|
||||
])
|
||||
sys.exit(exitcode)
|
15
scripts/test.py
Normal file
15
scripts/test.py
Normal file
|
@ -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)
|
Loading…
Add table
Add a link
Reference in a new issue