Skip to content

Commit 0332a34

Browse files
committed
add pre-commit hooks
1 parent 919f124 commit 0332a34

17 files changed

Lines changed: 127 additions & 49 deletions

.github/workflows/release_package.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ jobs:
7373
echo "release-tag=$(echo $TAG)" >> $GITHUB_OUTPUT
7474
- uses: mukunku/tag-exists-action@v1.6.0
7575
id: check-tag
76-
with:
76+
with:
7777
tag: ${{ steps.read-tag.outputs.release-tag }}
7878
- name: Fail if tag exists
7979
run: |
8080
echo "Tag ${{ steps.read-tag.outputs.release-tag }} exists!"
8181
exit 1
82-
if: steps.check-tag.outputs.exists == 'true'
82+
if: steps.check-tag.outputs.exists == 'true'
8383
- name: Print tag if it doesn't exist
8484
run: |
8585
echo "Tag ${{ steps.read-tag.outputs.release-tag }} doesn't yet exist and can be created"
86-
if: steps.check-tag.outputs.exists == 'false'
86+
if: steps.check-tag.outputs.exists == 'false'
8787

8888
release:
8989
needs: [pylint, pytest, build, tag]

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Run Tests
22

3-
on:
3+
on:
44
push:
55
branches: [main]
66
pull_request:

.pre-commit-config.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v6.0.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- repo: https://github.com/codespell-project/codespell
9+
rev: v2.4.1
10+
hooks:
11+
- id: codespell
12+
files: ^.*\.(py|md|yml)$
13+
exclude: >
14+
(?x)^(
15+
src/test/fuzzy_test.py|
16+
src/test/alg_test.py
17+
)$
18+
additional_dependencies:
19+
- tomli
20+
- repo: https://github.com/astral-sh/ruff-pre-commit
21+
# Ruff version.
22+
rev: v0.12.10
23+
hooks:
24+
- id: ruff-check
25+
args:
26+
- --fix
27+
- --unsafe-fixes
28+
- repo: https://github.com/pycqa/isort
29+
rev: 6.0.1
30+
hooks:
31+
- id: isort
32+
name: isort (python)
33+
- repo: https://github.com/pycqa/pylint
34+
rev: v3.3.8
35+
hooks:
36+
- id: pylint
37+
args:
38+
- -d import-error
39+
- -sn

README.md

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,41 @@ Finally, the server is stopped gracefully.
5757

5858
More examples can be found in the **examples** folder.
5959

60-
## Run tests locally
60+
## Development environment setup
6161

62-
In order to run tests locally, there are a few things that have to be setup:
62+
If you want to contribute to this project, you need to set up your local environment.
6363

64-
### Add credentials for testing
64+
### Clone the repository
6565

66-
To simulate a player connecting ot the server, it needs to authenticate against microsofts servers. This means, that a microsoft account which owns Minecraft is needed. Don't worry, the credentials are only saved locally.
66+
Run the command
67+
```bash
68+
git clone https://github.com/mcserver-tools/mcserverwrapper
69+
cd mcserverwrapper
70+
```
71+
in your terminal.
6772

68-
Create a new file named *password.txt* in the repository root and add the following content (without the brackets):
73+
### Install pip packages
74+
75+
To install all optional as well as development python packages, run the following commands in the project root.
76+
77+
Windows:
78+
```bash
79+
py -m venv venv
80+
venv\Scripts\activate.bat
81+
pip install -r requirements.txt
6982
```
70-
(username-here)
71-
(password-here)
83+
84+
Linux:
85+
```bash
86+
python3 -m venv venv
87+
source venv/bin/activate
88+
pip install -r requirements.txt
7289
```
7390

7491
### Node
7592

7693
Node 20 is needed to use MineFlayer.
94+
The install instructions can be found below:
7795

7896
#### Windows
7997

@@ -98,9 +116,41 @@ To actually run a minecraft server, a Java 21 JRE needs to be installed and adde
98116

99117
Download it from (here)[https://adoptium.net/temurin/releases/].
100118

119+
### Add credentials for testing
120+
121+
To simulate a player connecting to the server, it needs to authenticate against microsofts servers. This means, that a microsoft account which owns Minecraft is needed. Don't worry, the credentials are only saved locally.
122+
123+
Create a new file named *password.txt* in the repository root and add the following content (without the brackets):
124+
```
125+
(username-here)
126+
(password-here)
127+
```
128+
101129
### Run tests
102130

103131
After installing all of the requirements, the tests can be ran using
104132
```bash
105-
python -m pytest
133+
python -m pytest src -rs --skip-linting --skip-test-all
134+
```
135+
136+
If you want to run tests for all Minecraft versions, remove the `--skip-test-all` argument from the command above.
137+
138+
> **Warning**
139+
> Beware that testing all versions can take multiple hours!
140+
141+
### Git pre-commit hooks
142+
143+
Pre-commit hooks are used to check and autofix formatting issues and typos before you commit your changes.
144+
Once installed, they run automatically if you run `git commit ...`.
145+
146+
Using these is optional, but encouraged.
147+
148+
```bash
149+
pip install pre-commit
150+
pre-commit install
151+
```
152+
153+
To verify the installation and run all checks:
154+
```bash
155+
pre-commit run --all-files
106156
```

examples/example_01.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pathlib
55

66
import requests
7+
78
from mcserverwrapper import Wrapper
89

910
def download_server_jar():

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies = [
3939
dev = [
4040
"bs4==0.0.2",
4141
"javascript==1!1.2.6",
42+
"pre-commit==4.3.0",
4243
"pylint==3.3.9",
4344
"pytest==8.4.2",
4445
"requests==2.32.5",

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ bs4==0.0.2
22
javascript==1!1.2.6
33
mcstatus==12.0.5
44
pexpect==4.9.0
5+
pre-commit==4.3.0
56
pylint==3.3.9
67
pytest==8.4.2
78
requests==2.32.5

src/mcserverwrapper/error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ class McServerWrapperError(Exception):
44
"""The base exception, can be used to catch all other McServerWrapper-related errors"""
55

66
class ServerExitedError(McServerWrapperError):
7-
"""An error occuring if the minecraft server unexpectedly crashed"""
7+
"""An error occurring if the minecraft server unexpectedly crashed"""

src/mcserverwrapper/server/base_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""A module contining the base server class"""
1+
"""A module containing the base server class"""
22

33
from __future__ import annotations
44

src/mcserverwrapper/server/server_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def from_jar(cls, jar_file: str) -> ServerBuilder:
3333
3434
Args:
3535
jar_file (str): the full or relative path to the jar file to be used to start the server
36-
36+
3737
Returns:
3838
ServerBuilder: a new ServerBuilder instance
3939
"""

0 commit comments

Comments
 (0)