Skip to content

Commit

Permalink
Update the gitignore and readme to aid contributing (#70)
Browse files Browse the repository at this point in the history
* Ignore `exe` files in any directory, and ignore a `main.py` file in the `stockfish` directory. This allows developers to more easily test changes they make to `stockfish/models.py`.

* Remove a few lines from the `.gitignore` that aren't needed.

* Update the readme with a guide on how to test changes for contributors.

* Satisfy `black`.

* Update README.md

* Minor updates to `get_wdl_stats` related stuff.
  • Loading branch information
johndoknjas authored Jun 2, 2024
1 parent 496f5b3 commit 2397874
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
!*/
!LICENSE

/*.exe
*.exe
/Notes/
/stockfish/main.py

.DS_Store
*.pyc
/.idea/
/.eggs/
/stockfish.egg-info/
/.mypy_cache/
/.pytest_cache/
__pycache/
/build/
/dist/
/venv/
Expand Down
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ Before calling this function, it is recommended that you first check if your ver
use the "does_current_engine_version_have_wdl_option()" function below.

```python
stockfish.get_wdl_stats()
stockfish.get_wdl_stats() # include the argument get_as_tuple=True if you'd like to have a tuple returned instead of a list.
```

```text
Expand Down Expand Up @@ -534,8 +534,35 @@ You can (de-)activate the debug view option with the `set_debug_view` function.
stockfish.set_debug_view(True)
```

## Contributing

Most contributions will involve making updates to `stockfish/models.py`. To test your changes, download a version of stockfish and paste the executable in the `stockfish` folder. Then, create a file in the `stockfish` folder called `main.py`. Both the executable and `main.py` will be ignored by git.
In `main.py`, start with something like the following:

```python
from models import Stockfish

def main():
sf = Stockfish(path = "name of your stockfish executable")
# Use this object as you wish to test your changes.

if __name__ == "__main__":
main()
```
Then when navigating to the `stockfish` folder in the terminal, you can run this `main.py` file simply with `python main.py`.
Once you're satisfied with your changes to `models.py`, see the section below for how to run the project's entire test suite.

## Testing

For your stockfish executable (the same one mentioned in the previous section), paste it also in the project's root directory. Then in `models.py`,
temporarily modify this line so that the `path`'s default value is changed from "stockfish" to the name of your stockfish executable:

```python
path: str = "stockfish",
```

Then in the project's root directory, you can run:

```bash
$ python setup.py test
```
Expand Down
4 changes: 1 addition & 3 deletions stockfish/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,7 @@ def is_move_correct(self, move_value: str) -> bool:
self.info = old_self_info
return is_move_correct

def get_wdl_stats(
self, get_as_tuple: bool = False
) -> Union[list[int] | tuple[int, int, int] | None]:
def get_wdl_stats(self, get_as_tuple: bool = False) -> list[int] | tuple[int, int, int] | None:
"""Returns Stockfish's win/draw/loss stats for the side to move.
Args:
Expand Down
1 change: 1 addition & 0 deletions tests/stockfish/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ def test_get_wdl_stats(self, stockfish: Stockfish):
wdl_stats_3 = stockfish.get_wdl_stats()
assert isinstance(wdl_stats_3, list) and len(wdl_stats_3) == 3

stockfish._prepare_for_new_position()
wdl_stats_4 = stockfish.get_wdl_stats(get_as_tuple=True)
assert isinstance(wdl_stats_4, tuple) and len(wdl_stats_4) == 3
assert wdl_stats_3 == list(wdl_stats_4)
Expand Down

0 comments on commit 2397874

Please sign in to comment.