From bfe180d362254c4f9af027c1ae83fc837153cf2f Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 28 Oct 2021 15:05:28 +0200 Subject: [PATCH 1/7] GitHub Actions to lint Python code --- .github/workflows/lint_python.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/lint_python.yml diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml new file mode 100644 index 0000000..8212d12 --- /dev/null +++ b/.github/workflows/lint_python.yml @@ -0,0 +1,26 @@ +# TODO: Remove `|| true` from the end of tests to make them mandatory +name: lint_python +on: [pull_request, push] +jobs: + lint_python: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - run: pip install --upgrade pip wheel + - run: pip install bandit black codespell flake8 flake8-2020 flake8-bugbear + flake8-comprehensions isort mypy pytest pyupgrade safety + - run: bandit --recursive --skip B101 . || true # B101 is assert statements + - run: black --check . || true + - run: codespell || true # --ignore-words-list="" --skip="*.css,*.js,*.lock" + - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + - run: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 + --show-source --statistics + - run: isort --check-only --profile black . || true + - run: pip install -r requirements.txt || pip install --editable . || true + - run: mkdir --parents --verbose .mypy_cache + - run: mypy --ignore-missing-imports --install-types --non-interactive . || true + - run: pytest . || true + - run: pytest --doctest-modules . || true + - run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true + - run: safety check From e8fb67508b73a12a30c83a98a13e558841b82e85 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 28 Oct 2021 15:09:35 +0200 Subject: [PATCH 2/7] Create requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7e2fba5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Pillow From a8b50425780d50ee197d64fc20e45cde2e17d61f Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 28 Oct 2021 15:10:12 +0200 Subject: [PATCH 3/7] pip install -r requirements.txt --- .github/workflows/lint_python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 8212d12..8d0ea3a 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -17,7 +17,7 @@ jobs: - run: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --show-source --statistics - run: isort --check-only --profile black . || true - - run: pip install -r requirements.txt || pip install --editable . || true + - run: pip install -r requirements.txt - run: mkdir --parents --verbose .mypy_cache - run: mypy --ignore-missing-imports --install-types --non-interactive . || true - run: pytest . || true From c1db337ae4a6e7ecddc375ccc4491a75a5e586f7 Mon Sep 17 00:00:00 2001 From: Leoriem-code <73761711+Leoriem-code@users.noreply.github.com> Date: Thu, 28 Oct 2021 15:38:36 +0200 Subject: [PATCH 4/7] Rename NumericalBaseConverter to NumericalBaseConverter.py --- NumericalBaseConverter => NumericalBaseConverter.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename NumericalBaseConverter => NumericalBaseConverter.py (100%) diff --git a/NumericalBaseConverter b/NumericalBaseConverter.py similarity index 100% rename from NumericalBaseConverter rename to NumericalBaseConverter.py From f75e3445639c2dd187b8a4f8807f69176c853a7e Mon Sep 17 00:00:00 2001 From: Leoriem-code Date: Thu, 28 Oct 2021 17:17:51 +0200 Subject: [PATCH 5/7] Update files --- .gitignore | 79 +++++++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 36 +++++++++++++++++++ .pre-commit-hooks.yaml | 6 ++++ requirements.txt | 1 + sandpile.py | 70 ++++++++++++++++++++++++++++++++++++ 5 files changed, 192 insertions(+) create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 .pre-commit-hooks.yaml create mode 100644 sandpile.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a44d67b --- /dev/null +++ b/.gitignore @@ -0,0 +1,79 @@ +#File modified from TheAlgorithms/Python + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +.cache +.pytest_cache/ + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +.DS_Store +.idea +.try +.vscode/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..344efe4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,36 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: check-executables-have-shebangs + - id: check-yaml + - id: end-of-file-fixer + types: [python] + - id: trailing-whitespace + - id: requirements-txt-fixer + - repo: https://github.com/psf/black + rev: 21.9b0 + hooks: + - id: black + - repo: https://github.com/PyCQA/isort + rev: 5.9.3 + hooks: + - id: isort + args: + - --profile=black + - repo: https://github.com/PyCQA/flake8 + rev: 4.0.1 + hooks: + - id: flake8 + args: + - --ignore=E203,W503 + - --max-complexity=25 + - --max-line-length=88 + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.910 + hooks: + - id: mypy + - repo: https://github.com/codespell-project/codespell + rev: v2.1.0 + hooks: + - id: codespell diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 0000000..17124eb --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,6 @@ +- id: validate_manifest + name: validate pre-commit manifest + description: This validator validates a pre-commit hooks manifest file + entry: pre-commit-validate-manifest + language: python + files: ^(\.pre-commit-hooks\.yaml|hooks\.yaml)$ diff --git a/requirements.txt b/requirements.txt index 7e2fba5..3694f3c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ Pillow +Pygame diff --git a/sandpile.py b/sandpile.py new file mode 100644 index 0000000..9f4f328 --- /dev/null +++ b/sandpile.py @@ -0,0 +1,70 @@ +from random import randrange + +import pygame as pg + +SIZE = 100 +MAX_PILE = 4 +CASE = 5 +WIDTH, HEIGHT = SIZE * CASE, SIZE * CASE +R = 255 // MAX_PILE + 1 +COLORS = [(255 - i * R, 255 - i * R, 255 - i * R) for i in range(MAX_PILE)] + [ + (0, 0, 0) +] +MAX_ITERATIONS = 100000 +to_slide: list[tuple[int, int]] = [] + +pg.init() +SCREEN = pg.display.set_mode((WIDTH, HEIGHT), 0, 32) +pg.display.set_caption("Sandpile Simulation") +SCREEN.fill(COLORS[0]) +pg.display.update() + +grid = [] +for i in range(SIZE): + line = [] + for j in range(SIZE): + line.append(0) + grid.append(line) + + +def is_in_bound(x: int, y: int) -> bool: + if 0 > x or x >= SIZE or 0 > y or y >= SIZE: + return False + else: + return True + + +def dessiner(x: int, y: int) -> None: + pg.draw.rect(SCREEN, COLORS[grid[x][y]], (x * CASE, y * CASE, CASE, CASE)) + # pg.display.update() + + +for iteration in range(MAX_ITERATIONS): + longueur = len(to_slide) + if longueur == 0: + x = randrange(0, SIZE) + y = randrange(0, SIZE) + + grid[x][y] += 1 + if grid[x][y] == MAX_PILE: + grid[x][y] = 0 + to_slide.append((x - 1, y)) + to_slide.append((x + 1, y)) + to_slide.append((x, y + 1)) + to_slide.append((x, y - 1)) + dessiner(x, y) + else: + for i in range(longueur): + x, y = to_slide.pop(0) + if is_in_bound(x, y): + if grid[x][y] < MAX_PILE: + grid[x][y] += 1 + if grid[x][y] == MAX_PILE: + grid[x][y] = 0 + to_slide.append((x - 1, y)) + to_slide.append((x + 1, y)) + to_slide.append((x, y + 1)) + to_slide.append((x, y - 1)) + dessiner(x, y) + pg.display.update() + pg.display.set_caption(f"Itération n°{iteration}") From 187eb5b77d67bad4bf10700ee3e17cb69584e950 Mon Sep 17 00:00:00 2001 From: Leoriem-code <73761711+Leoriem-code@users.noreply.github.com> Date: Thu, 28 Oct 2021 21:09:55 +0200 Subject: [PATCH 6/7] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3694f3c..a4d2f57 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ Pillow -Pygame +https://github.com/pygame/pygame.git From 2dbc273dede1966b0d145c41f2d5a415835da406 Mon Sep 17 00:00:00 2001 From: Leoriem-code <73761711+Leoriem-code@users.noreply.github.com> Date: Thu, 28 Oct 2021 21:13:02 +0200 Subject: [PATCH 7/7] Update requirements.txt Removed pygame as it caused lint to fail --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a4d2f57..7e2fba5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ Pillow -https://github.com/pygame/pygame.git