Skip to content

Commit 8af936c

Browse files
committed
✨ Update type annotations and update dependencies
1 parent d8d4995 commit 8af936c

8 files changed

Lines changed: 359 additions & 253 deletions

File tree

.gitignore

Lines changed: 98 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
1-
2-
# Created by https://www.toptal.com/developers/gitignore/api/python
3-
# Edit at https://www.toptal.com/developers/gitignore?templates=python
1+
# Created by https://www.toptal.com/developers/gitignore/api/macos,python,vim
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,python,vim
3+
4+
### macOS ###
5+
# General
6+
.DS_Store
7+
.AppleDouble
8+
.LSOverride
9+
10+
# Icon must end with two
11+
Icon
12+
13+
# Thumbnails
14+
._*
15+
16+
# Files that might appear in the root of a volume
17+
.DocumentRevisions-V100
18+
.fseventsd
19+
.Spotlight-V100
20+
.TemporaryItems
21+
.Trashes
22+
.VolumeIcon.icns
23+
.com.apple.timemachine.donotpresent
24+
25+
# Directories potentially created on remote AFP share
26+
.AppleDB
27+
.AppleDesktop
28+
Network Trash Folder
29+
Temporary Items
30+
.apdisk
31+
32+
### macOS Patch ###
33+
# iCloud generated files
34+
*.icloud
435

536
### Python ###
637
# Byte-compiled / optimized / DLL files
@@ -25,7 +56,6 @@ parts/
2556
sdist/
2657
var/
2758
wheels/
28-
pip-wheel-metadata/
2959
share/python-wheels/
3060
*.egg-info/
3161
.installed.cfg
@@ -55,7 +85,7 @@ coverage.xml
5585
*.py,cover
5686
.hypothesis/
5787
.pytest_cache/
58-
pytestdebug.log
88+
cover/
5989

6090
# Translations
6191
*.mo
@@ -76,9 +106,9 @@ instance/
76106

77107
# Sphinx documentation
78108
docs/_build/
79-
doc/_build/
80109

81110
# PyBuilder
111+
.pybuilder/
82112
target/
83113

84114
# Jupyter Notebook
@@ -89,7 +119,9 @@ profile_default/
89119
ipython_config.py
90120

91121
# pyenv
92-
.python-version
122+
# For a library or package, you might want to ignore these files since the code is
123+
# intended to run in multiple environments; otherwise, check them in:
124+
# .python-version
93125

94126
# pipenv
95127
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
@@ -98,7 +130,22 @@ ipython_config.py
98130
# install all needed dependencies.
99131
#Pipfile.lock
100132

101-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
133+
# poetry
134+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
135+
# This is especially recommended for binary packages to ensure reproducibility, and is more
136+
# commonly ignored for libraries.
137+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
138+
#poetry.lock
139+
140+
# pdm
141+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
142+
#pdm.lock
143+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
144+
# in version control.
145+
# https://pdm.fming.dev/#use-with-ide
146+
.pdm.toml
147+
148+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
102149
__pypackages__/
103150

104151
# Celery stuff
@@ -116,7 +163,6 @@ venv/
116163
ENV/
117164
env.bak/
118165
venv.bak/
119-
pythonenv*
120166

121167
# Spyder project settings
122168
.spyderproject
@@ -139,7 +185,46 @@ dmypy.json
139185
# pytype static type analyzer
140186
.pytype/
141187

142-
# profiling data
143-
.prof
144-
145-
# End of https://www.toptal.com/developers/gitignore/api/python
188+
# Cython debug symbols
189+
cython_debug/
190+
191+
# PyCharm
192+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
193+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
194+
# and can be added to the global gitignore or merged into this file. For a more nuclear
195+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
196+
#.idea/
197+
198+
### Python Patch ###
199+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
200+
poetry.toml
201+
202+
# ruff
203+
.ruff_cache/
204+
205+
# LSP config files
206+
pyrightconfig.json
207+
208+
### Vim ###
209+
# Swap
210+
[._]*.s[a-v][a-z]
211+
!*.svg # comment out if you don't need vector files
212+
[._]*.sw[a-p]
213+
[._]s[a-rt-v][a-z]
214+
[._]ss[a-gi-z]
215+
[._]sw[a-p]
216+
217+
# Session
218+
Session.vim
219+
Sessionx.vim
220+
221+
# Temporary
222+
.netrwhist
223+
*~
224+
# Auto-generated tag files
225+
tags
226+
# Persistent undo
227+
[._]*.un~
228+
229+
# End of https://www.toptal.com/developers/gitignore/api/macos,python,vim
230+
n

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.9.19

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# GoLPy
2+
23
[![GitHub
34
license](https://img.shields.io/github/license/Zeta611/golpy?style=flat-square)](https://github.com/Zeta611/golpy/blob/master/LICENSE)
45
[![PyPI](https://img.shields.io/pypi/v/golpy?style=flat-square)](https://pypi.org/project/golpy/)
@@ -7,20 +8,24 @@ license](https://img.shields.io/github/license/Zeta611/golpy?style=flat-square)]
78
GoLPy is an efficient Conway's Game of Life implemented in Python using NumPy.
89

910
## Example Output
11+
1012
The following GIF can be generated using the command:
13+
1114
```sh
1215
life --demo glidergun --out glider_gun.gif --ppc 10 --pos TL -W60 -H40
1316
```
1417

1518
![The Gosper Glider Gun](glider_gun.gif)
1619

1720
## Installation
18-
```
21+
22+
```sh
1923
pip install golpy
2024
```
2125

2226
## Usage
23-
```
27+
28+
```sh
2429
usage: life [-h] (-i GRID_INPUT | -d DEMO) [-o FILE | --debug-print]
2530
[-W WIDTH] [-H HEIGHT] [-M MAX_GEN] [--ppc PIXELS] [-P POSITION]
2631
[-p]
@@ -50,8 +55,15 @@ optional arguments:
5055
-p, --profile Measure the performance
5156
```
5257

53-
## Input Format
58+
To use without installing,
59+
60+
```sh
61+
python -m golpy # ...
5462
```
63+
64+
## Input Format
65+
66+
```txt
5567
........................O
5668
......................O.O
5769
............OO......OO............OO
@@ -66,4 +78,5 @@ OO........O...O.OO....O.O
6678
Use `.` for a dead cell, `O` (`chr(79)`) for a live cell.
6779

6880
## License
81+
6982
[MIT](LICENSE)

glider_gun.gif

49.4 KB
Loading

golpy/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import functools
33
import textwrap
44
from pathlib import Path
5-
from typing import Callable, Dict, List, Tuple
5+
from typing import Callable
66

77
import numpy as np
88
from PIL import Image
@@ -125,7 +125,7 @@ def grid_print(grid: np.ndarray, generation: int) -> None:
125125

126126
@timeit()
127127
def parse_grid(
128-
text: str, size: Tuple[int, int], pos: str = "C", live: str = "O"
128+
text: str, size: tuple[int, int], pos: str = "C", live: str = "O"
129129
) -> np.ndarray:
130130
lines = textwrap.dedent(text).strip().splitlines()
131131
text_width = max(len(line) for line in lines)
@@ -139,7 +139,7 @@ def parse_grid(
139139

140140
grid = np.zeros((height, width), dtype="uint8")
141141

142-
pos_idx: Dict[str, Tuple[int, int]] = {
142+
pos_idx: dict[str, tuple[int, int]] = {
143143
"C": (height // 2 - text_height // 2, width // 2 - text_width // 2),
144144
"T": (0, width // 2 - text_width // 2),
145145
"B": (height - text_height, width // 2 - text_width // 2),
@@ -166,7 +166,7 @@ def parse_grid(
166166
def add_grid_frame(
167167
grid: np.ndarray,
168168
generation: int,
169-
grid_frames: List[np.ndarray],
169+
grid_frames: list[np.ndarray],
170170
pixels_per_cell: int,
171171
) -> None:
172172
"""Add the grid to the grid_frames"""
@@ -185,7 +185,7 @@ def enlarge_image(image: np.ndarray, ratio: int) -> np.ndarray:
185185

186186
@timeit()
187187
def save_frames(
188-
grid_frames: List[Image.Image], filename: str, duration: int = 50
188+
grid_frames: list[Image.Image], filename: str, duration: int = 50
189189
) -> None:
190190
grid_frames[0].save(
191191
filename,
@@ -196,7 +196,7 @@ def save_frames(
196196
)
197197

198198

199-
def get_demo(name: str, size: Tuple[int, int], pos: str = "C") -> np.ndarray:
199+
def get_demo(name: str, size: tuple[int, int], pos: str = "C") -> np.ndarray:
200200
if name == "random":
201201
return np.random.randint(0, 2, size, dtype="uint8")
202202

@@ -321,7 +321,7 @@ def main() -> None:
321321
grid = get_demo(args.demo, size, pos)
322322

323323
# Run Game of Life
324-
grid_frames: List[Image.Image] = []
324+
grid_frames: list[Image.Image] = []
325325

326326
if args.debug_print:
327327
driver(grid, handler=grid_print, max_gen=max_gen)

golpy/util.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import time
22
from functools import wraps
3-
from typing import Dict
43

54

65
class timeit:
7-
records: Dict[str, float] = {}
6+
records: dict[str, float] = {}
87
on = False
98

109
def __call__(self, func):

0 commit comments

Comments
 (0)