Skip to content

Commit e3ecf39

Browse files
authored
Merge branch 'master' into add-doctests-game-of-life
2 parents 898cb45 + 4e9b874 commit e3ecf39

168 files changed

Lines changed: 7951 additions & 1495 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.devcontainer/devcontainer.json

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
{
22
"name": "Python 3",
3-
"build": {
4-
"dockerfile": "Dockerfile",
5-
"context": "..",
6-
"args": {
7-
// Update 'VARIANT' to pick a Python version: 3, 3.11, 3.10, 3.9, 3.8
8-
// Append -bullseye or -buster to pin to an OS version.
9-
// Use -bullseye variants on local on arm64/Apple Silicon.
10-
"VARIANT": "3.13-bookworm"
11-
}
12-
},
133

14-
"postCreateCommand": "zsh .devcontainer/post_install",
4+
// Use a prebuilt dev container image instead of building from a local
5+
// Dockerfile. The repo migrated its dependencies to pyproject.toml, so the
6+
// old Dockerfile's `COPY requirements.txt` step no longer had a file to copy
7+
// and the image build failed. The upstream images already ship Python + a
8+
// full toolchain, so pulling one is both faster and less to maintain.
9+
//
10+
// This repo tracks the latest-and-greatest CPython on the newest stable
11+
// Debian. Images are published per CPython minor version on Debian 13
12+
// "Trixie" (3.11-trixie ... 3.14-trixie); bump this to the newest available
13+
// when a new stable CPython ships.
14+
// NOTE: these images do not publish free-threaded (`t`) variants, so 3.14t
15+
// cannot be selected via the tag alone -- but the repo's `.python-version`
16+
// pins 3.14t, and `uv run`/`uv sync` in the container honor it, so uv gives
17+
// contributors free-threaded 3.14t regardless of the base tag.
18+
"image": "mcr.microsoft.com/devcontainers/python:latest",
19+
20+
// Install the tools post_install and CI expect (pre-commit + ruff), plus uv
21+
// for the free-threaded workflow above, then run the existing setup script.
22+
"postCreateCommand": "pipx install pre-commit ruff uv && zsh .devcontainer/post_install",
1523

1624
// Configure tool-specific properties.
1725
"customizations": {
@@ -20,26 +28,30 @@
2028
// Set *default* container specific settings.json values on container create.
2129
"settings": {
2230
"python.defaultInterpreterPath": "/usr/local/bin/python",
23-
"python.linting.enabled": true,
24-
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
25-
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
31+
// Formatting/linting is handled by Ruff (matches pre-commit and CI).
32+
"editor.formatOnSave": true,
33+
"[python]": {
34+
"editor.defaultFormatter": "charliermarsh.ruff",
35+
"editor.codeActionsOnSave": {
36+
"source.fixAll": "explicit",
37+
"source.organizeImports": "explicit"
38+
}
39+
},
2640
"terminal.integrated.defaultProfile.linux": "zsh"
2741
},
2842

2943
// Add the IDs of extensions you want installed when the container is created.
3044
"extensions": [
3145
"ms-python.python",
32-
"ms-python.vscode-pylance"
46+
"ms-python.vscode-pylance",
47+
"charliermarsh.ruff"
3348
]
3449
}
3550
},
3651

3752
// Use 'forwardPorts' to make a list of ports inside the container available locally.
3853
// "forwardPorts": [],
3954

40-
// Use 'postCreateCommand' to run commands after the container is created.
41-
// "postCreateCommand": "pip3 install --user -r requirements.txt",
42-
4355
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
4456
"remoteUser": "vscode"
4557
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Skill: Code review for TheAlgorithms/Python
2+
3+
Review a pull request against the rules already written in
4+
[`CONTRIBUTING.md`](../../../CONTRIBUTING.md). The goal is a review that any
5+
reviewer (human or AI) can run the same way every time, and that produces a clear,
6+
kind, actionable verdict.
7+
8+
## How to run this skill
9+
10+
Read the PR diff, then work through the four `CONTRIBUTING.md` sections in order
11+
and emit the fixed output shape below. Cite the exact rule you are applying and
12+
suggest the fix — never just "rejected".
13+
14+
### 1. Before contributing / Is this an algorithm?
15+
16+
- [ ] The change adds, fixes, or documents **one algorithm** — not multiple, and
17+
not both code and doctest changes in the same PR.
18+
- [ ] It is a genuine algorithm or data structure (see the *What is an Algorithm?*
19+
section), not a script, snippet, how-to-use for an existing API, or exercise
20+
dump.
21+
- [ ] It is **not already in the repository** (search the existing directories).
22+
- [ ] **No earlier open PR** already does the same thing — link it if one exists.
23+
- [ ] Properly attributed — no plagiarism; prior sources credited.
24+
25+
### 2. Coding Style
26+
27+
- [ ] `from __future__ import annotations` is not needed because this repo only uses
28+
the latest version of CPython.
29+
- [ ] File and directory names are lowercase, use underscores, and land inside an
30+
existing directory.
31+
- [ ] Public functions/classes have **type hints**.
32+
- [ ] Public functions have **doctests that actually pass**.
33+
- [ ] Descriptive variable and function names (no single letters where a word helps).
34+
- [ ] Code is formatted and lint-clean (`ruff`, `pre-commit`).
35+
36+
### 3. Other Requirements for Submissions
37+
38+
- [ ] At least one **Wikipedia (or equivalent) URL** documenting the algorithm.
39+
- [ ] Docstring explains what the function does and its parameters/returns.
40+
- [ ] No unnecessary third-party dependencies.
41+
42+
### 4. Verdict — fixed output shape
43+
44+
Emit exactly these headings so reviews are comparable and easy to automate:
45+
46+
```
47+
### Is this an algorithm? — <yes/no + one-line why>
48+
### Duplicate / prior-art check — <#NNNN | none found>
49+
### Coding style — <pass | issues: …>
50+
### Other requirements (doctests, type hints, descriptive names, Wikipedia URL) — <pass | issues: …>
51+
### Verdict — <approve | request changes | close> + one-line reason
52+
```
53+
54+
## Tone
55+
56+
Be specific and kind. Point at the exact `CONTRIBUTING.md` rule and offer the fix
57+
rather than a bare rejection — first-time and Hacktoberfest contributors are more
58+
likely to come back and improve the PR when the path forward is clear.
59+
60+
## Map findings to labels
61+
62+
Where a finding matches an existing label, name it so the review lines up with the
63+
maintenance/cleanup tooling:
64+
65+
- missing/failing doctests → `require tests`
66+
- missing type hints → `require type hints`
67+
- non-descriptive names → `require descriptive names`
68+
- CI red → `tests are failing`
69+
- otherwise ready for a maintainer → `awaiting reviews`

.github/workflows/build.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,36 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v5
13-
- uses: astral-sh/setup-uv@v6
12+
- uses: actions/checkout@v7
13+
- uses: astral-sh/setup-uv@v7
1414
with:
1515
enable-cache: true
1616
cache-dependency-glob: uv.lock
17-
- uses: actions/setup-python@v6
17+
- uses: actions/setup-python@v7
1818
with:
19-
python-version: 3.x
19+
python-version-file: .python-version
2020
allow-prereleases: true
2121
- run: uv sync --group=test
2222
- name: Run tests
23-
# TODO: #8818 Re-enable quantum tests
24-
run: uv run pytest
23+
# opencv-python is gated out on 3.14t (no cp314t wheel yet), so skip the
24+
# files that import cv2. Pure-Python algorithms in computer_vision/ and
25+
# data_compression/ still run; digital_image_processing/ is almost entirely
26+
# cv2-based so it is skipped as a tree. Re-enable when a cp314t wheel ships.
27+
# --ignore-gil-enabled: some compiled deps (sklearn, xgboost, ...) don't
28+
# yet ship the Py_mod_gil slot, so importing them re-enables the GIL under
29+
# 3.14t. That's an upstream-wheel gap, not our code; the flag lets the suite
30+
# run anyway and pytest-run-parallel still reports which tests are not
31+
# thread-safe. Drop the flag once the scientific stack ships free-threaded wheels.
32+
# qiskit is likewise gated out of the 3.14t deps (Qiskit/qiskit#16893), so the
33+
# single file that imports it (quantum/q_fourier_transform.py) is skipped too.
34+
run: uv run --with=pytest-run-parallel pytest
35+
--iterations=8 --parallel-threads=auto --ignore-gil-enabled
2536
--ignore=computer_vision/cnn_classification.py
37+
--ignore=computer_vision/flip_augmentation.py
38+
--ignore=computer_vision/harris_corner.py
39+
--ignore=computer_vision/mosaic_augmentation.py
40+
--ignore=data_compression/peak_signal_to_noise_ratio.py
41+
--ignore=digital_image_processing/
2642
--ignore=docs/conf.py
2743
--ignore=dynamic_programming/k_means_clustering_tensorflow.py
2844
--ignore=machine_learning/lstm/lstm_prediction.py

.github/workflows/devcontainer_ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ on:
44
push:
55
paths:
66
- ".devcontainer/**"
7+
- ".github/workflows/devcontainer_ci.yml"
78
pull_request:
89
paths:
910
- ".devcontainer/**"
11+
- ".github/workflows/devcontainer_ci.yml"
1012

1113
jobs:
1214
build:
1315
runs-on: ubuntu-latest
1416
steps:
15-
- uses: actions/checkout@v5
17+
- uses: actions/checkout@v7
1618
- uses: devcontainers/ci@v0.3
1719
with:
1820
push: never

.github/workflows/directory_writer.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ jobs:
66
directory_writer:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v5
9+
- uses: actions/checkout@v7
1010
with:
1111
fetch-depth: 0
12-
- uses: actions/setup-python@v6
12+
- uses: actions/setup-python@v7
1313
with:
14-
python-version: 3.x
14+
python-version-file: .python-version
15+
allow-prereleases: true
1516
- name: Write DIRECTORY.md
1617
run: |
1718
scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md

.github/workflows/project_euler.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,23 @@ jobs:
1414
project-euler:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v5
18-
- uses: astral-sh/setup-uv@v6
19-
- uses: actions/setup-python@v6
17+
- uses: actions/checkout@v7
18+
- uses: astral-sh/setup-uv@v7
19+
- uses: actions/setup-python@v7
2020
with:
21-
python-version: 3.x
21+
python-version-file: .python-version
22+
allow-prereleases: true
2223
- run: uv sync --group=euler-validate --group=test
2324
- run: uv run pytest --doctest-modules --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/
2425
validate-solutions:
2526
runs-on: ubuntu-latest
2627
steps:
27-
- uses: actions/checkout@v5
28-
- uses: astral-sh/setup-uv@v6
29-
- uses: actions/setup-python@v6
28+
- uses: actions/checkout@v7
29+
- uses: astral-sh/setup-uv@v7
30+
- uses: actions/setup-python@v7
3031
with:
31-
python-version: 3.x
32+
python-version-file: .python-version
33+
allow-prereleases: true
3234
- run: uv sync --group=euler-validate --group=test
3335
- run: uv run pytest scripts/validate_solutions.py
3436
env:

.github/workflows/ruff.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ jobs:
1111
ruff:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v5
15-
- uses: astral-sh/setup-uv@v6
14+
- uses: actions/checkout@v7
15+
- uses: astral-sh/setup-uv@v7
1616
- run: uvx ruff check --output-format=github .

.github/workflows/sphinx.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ jobs:
2525
build_docs:
2626
runs-on: ubuntu-24.04-arm
2727
steps:
28-
- uses: actions/checkout@v5
29-
- uses: astral-sh/setup-uv@v6
30-
- uses: actions/setup-python@v6
28+
- uses: actions/checkout@v7
29+
- uses: astral-sh/setup-uv@v7
30+
- uses: actions/setup-python@v7
3131
with:
32-
python-version: 3.13
32+
python-version-file: .python-version
3333
allow-prereleases: true
3434
- run: uv sync --group=docs
35-
- uses: actions/configure-pages@v5
35+
- uses: actions/configure-pages@v6
3636
- run: uv run sphinx-build -c docs . docs/_build/html
37-
- uses: actions/upload-pages-artifact@v4
37+
- uses: actions/upload-pages-artifact@v5
3838
with:
3939
path: docs/_build/html
4040

@@ -46,5 +46,5 @@ jobs:
4646
needs: build_docs
4747
runs-on: ubuntu-latest
4848
steps:
49-
- uses: actions/deploy-pages@v4
49+
- uses: actions/deploy-pages@v5
5050
id: deployment

.github/workflows/ty.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# https://docs.astral.sh/ty/
2+
name: ty
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
jobs:
11+
ty:
12+
runs-on: ubuntu-latest
13+
# Informational only: ty is not yet a required gate. This job surfaces
14+
# type-check findings in the logs so they can be triaged into gradual
15+
# [tool.ty] rules without blocking merges. Flip `continue-on-error` to
16+
# false once the baseline is clean.
17+
continue-on-error: true
18+
steps:
19+
- uses: actions/checkout@v7
20+
- uses: astral-sh/setup-uv@v7
21+
with:
22+
enable-cache: true
23+
cache-dependency-glob: uv.lock
24+
# Mirror the `build` job: `uv sync` installs the dependencies without
25+
# building this flat-layout repo as a wheel. pyproject.toml has no
26+
# [build-system], so uv treats the project as virtual and installs only
27+
# its dependencies -- no "Multiple top-level packages discovered in a
28+
# flat-layout" error and no need for a src-layout. (`uv pip install .`
29+
# would force that wheel build and fail.) Pin a regular GIL 3.14 so typed
30+
# third-party dependencies resolve; the free-threaded 3.14t interpreter the
31+
# test matrix uses lacks wheels for several of them. ty itself is pulled in
32+
# ephemerally with `--with` so it needn't be added to the lockfile.
33+
- run: uv sync --python 3.14
34+
# Pin the *run* to the same regular-GIL 3.14 too. Without `--python 3.14`
35+
# here, `uv run` re-resolved the project's default interpreter -- the
36+
# free-threaded 3.14t used by the test matrix -- so ty type-checked against
37+
# an env where many third-party stubs don't resolve, drowning real findings
38+
# in `unresolved-import` / `unresolved-attribute` noise. Pinning 3.14 lets
39+
# ty see the synced dependencies, so the `[tool.ty.rules]` severities in
40+
# pyproject.toml apply to a meaningful baseline.
41+
#
42+
# `--exit-zero` is ty's native advisory switch (the analog of ruff's
43+
# `ruff check --exit-zero`): the step always exits 0, yet with
44+
# `--output-format=github` ty still emits ::error annotations that render
45+
# inline on the diff, so findings stay visible without a red X. Promotion
46+
# path: `--exit-zero` (informational, always green) -> `--exit-zero-on-warning`
47+
# (fail only on error-severity, tolerate warnings) -> drop the flag entirely
48+
# to make ty a required gate once the [tool.ty] baseline is clean.
49+
# `continue-on-error: true` above stays as a belt-and-suspenders guard so a
50+
# ty *crash* (not a diagnostic) can never block a merge either.
51+
- run: uv run --python 3.14 --with ty ty check --output-format=github --exit-zero

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ target/
7373
.ipynb_checkpoints
7474

7575
# pyenv
76-
.python-version
7776

7877
# celery beat schedule file
7978
celerybeat-schedule

0 commit comments

Comments
 (0)