Skip to content

Commit 2c3299a

Browse files
authored
Merge branch 'master' into master
2 parents 9ff273b + ece9b39 commit 2c3299a

178 files changed

Lines changed: 10257 additions & 1680 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`
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Skill: New pull request for TheAlgorithms/Python
2+
3+
Create a new pull request using the rules already written in
4+
[`CONTRIBUTING.md`](../../../CONTRIBUTING.md). The goal is that creating a new
5+
pull request (human or AI) can run the same way every time, and that produces a
6+
clear, kind, tested, type-hinted, mergeable contribution.
7+
8+
## How to run this skill
9+
10+
Make sure that the local `master` branch is synced with `upstream/master` before
11+
creating a new pull request.
12+
13+
Create a new clearly named branch for the pull request. Pull request changes must
14+
not be made or submitted on the `master` branch.
15+
16+
Never hand-edit or revert the `uv.lock` file. If you add a legitimate
17+
dependency, let the `uv-lock` pre-commit hook regenerate it — do not touch it by
18+
hand. A hand-modified `uv.lock` makes the `algorithms-keeper` bot close the pull
19+
request as invalid, and even a repo maintainer cannot undo that.
20+
21+
Always check at least one Markdown checkbox in the pull request description (the "Describe your change" section), or the
22+
`algorithms-keeper` bot will close the pull request as invalid. Any repo maintainer can undo this if you @mention them on the closed pull request.
23+
24+
### 1. Before contributing / Is this an algorithm?
25+
26+
- [ ] The change adds, fixes, or documents **one algorithm** — not multiple, and
27+
not both code and doctest changes in the same PR.
28+
- [ ] It is a genuine algorithm or data structure (see the *What is an Algorithm?*
29+
section), not a script, snippet, how-to-use for an existing API, or exercise
30+
dump.
31+
- [ ] It is **not already in the repository** (search the existing directories).
32+
- [ ] **No earlier open PR** already does the same thing — link it if one exists.
33+
- [ ] Properly attributed — no plagiarism; prior sources credited.
34+
35+
### 2. Coding Style
36+
37+
- [ ] `from __future__ import annotations` is not needed because this repo only uses
38+
the latest version of CPython.
39+
- [ ] File and directory names are lowercase, use underscores, and land inside an
40+
existing directory.
41+
- [ ] Public functions/classes have **type hints**.
42+
- [ ] Public functions have **doctests that actually pass**.
43+
- [ ] Descriptive variable and function names (no single letters where a word helps).
44+
- [ ] Code is formatted and lint-clean (`ruff`, `pre-commit`).
45+
- [ ] `DIRECTORY.md` and `README.md` are **not hand-edited** — the
46+
`algorithms-keeper` bot regenerates them automatically after merge.
47+
48+
### 3. Other Requirements for Submissions
49+
50+
- [ ] At least one **Wikipedia (or equivalent) URL** documenting the algorithm.
51+
- [ ] Docstring explains what the function does and its parameters/returns.
52+
- [ ] No unnecessary third-party dependencies.

.github/workflows/build.yml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,38 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- run: sudo apt-get update && sudo apt-get install -y libhdf5-dev
13-
- uses: actions/checkout@v6
12+
- uses: actions/checkout@v7
1413
- uses: astral-sh/setup-uv@v7
1514
with:
1615
enable-cache: true
1716
cache-dependency-glob: uv.lock
18-
- uses: actions/setup-python@v6
17+
- uses: actions/setup-python@v7
1918
with:
20-
python-version: 3.14
19+
python-version-file: .python-version
2120
allow-prereleases: true
2221
- run: uv sync --group=test
2322
- name: Run tests
24-
# TODO: #8818 Re-enable quantum tests
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.
2534
run: uv run --with=pytest-run-parallel pytest
26-
--iterations=8 --parallel-threads=auto
35+
--iterations=8 --parallel-threads=auto --ignore-gil-enabled
2736
--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/
2842
--ignore=docs/conf.py
2943
--ignore=dynamic_programming/k_means_clustering_tensorflow.py
30-
--ignore=machine_learning/local_weighted_learning/local_weighted_learning.py
3144
--ignore=machine_learning/lstm/lstm_prediction.py
3245
--ignore=neural_network/input_data.py
3346
--ignore=project_euler/

.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@v6
17+
- uses: actions/checkout@v7
1618
- uses: devcontainers/ci@v0.3
1719
with:
1820
push: never

.github/workflows/directory_writer.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ jobs:
66
directory_writer:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v6
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.14
14+
python-version-file: .python-version
1515
allow-prereleases: true
1616
- name: Write DIRECTORY.md
1717
run: |

.github/workflows/project_euler.yml

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,22 @@ jobs:
1414
project-euler:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- run:
18-
sudo apt-get update && sudo apt-get install -y libtiff5-dev libjpeg8-dev libopenjp2-7-dev
19-
zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk
20-
libharfbuzz-dev libfribidi-dev libxcb1-dev
21-
libxml2-dev libxslt-dev
22-
libhdf5-dev
23-
libopenblas-dev
24-
- uses: actions/checkout@v6
17+
- uses: actions/checkout@v7
2518
- uses: astral-sh/setup-uv@v7
26-
- uses: actions/setup-python@v6
19+
- uses: actions/setup-python@v7
2720
with:
28-
python-version: 3.14
21+
python-version-file: .python-version
2922
allow-prereleases: true
3023
- run: uv sync --group=euler-validate --group=test
3124
- run: uv run pytest --doctest-modules --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/
3225
validate-solutions:
3326
runs-on: ubuntu-latest
3427
steps:
35-
- run:
36-
sudo apt-get update && sudo apt-get install -y libtiff5-dev libjpeg8-dev libopenjp2-7-dev
37-
zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk
38-
libharfbuzz-dev libfribidi-dev libxcb1-dev
39-
libxml2-dev libxslt-dev
40-
libhdf5-dev
41-
libopenblas-dev
42-
- uses: actions/checkout@v6
28+
- uses: actions/checkout@v7
4329
- uses: astral-sh/setup-uv@v7
44-
- uses: actions/setup-python@v6
30+
- uses: actions/setup-python@v7
4531
with:
46-
python-version: 3.14
32+
python-version-file: .python-version
4733
allow-prereleases: true
4834
- run: uv sync --group=euler-validate --group=test
4935
- run: uv run pytest scripts/validate_solutions.py

.github/workflows/ruff.yml

Lines changed: 1 addition & 1 deletion
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@v6
14+
- uses: actions/checkout@v7
1515
- uses: astral-sh/setup-uv@v7
1616
- run: uvx ruff check --output-format=github .

.github/workflows/sphinx.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,16 @@ jobs:
2525
build_docs:
2626
runs-on: ubuntu-24.04-arm
2727
steps:
28-
- run:
29-
sudo apt-get update && sudo apt-get install -y libtiff5-dev libjpeg8-dev libopenjp2-7-dev
30-
zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk
31-
libharfbuzz-dev libfribidi-dev libxcb1-dev
32-
libxml2-dev libxslt-dev
33-
libhdf5-dev
34-
libopenblas-dev
35-
- uses: actions/checkout@v6
28+
- uses: actions/checkout@v7
3629
- uses: astral-sh/setup-uv@v7
37-
- uses: actions/setup-python@v6
30+
- uses: actions/setup-python@v7
3831
with:
39-
python-version: 3.14
32+
python-version-file: .python-version
4033
allow-prereleases: true
4134
- run: uv sync --group=docs
42-
- uses: actions/configure-pages@v5
35+
- uses: actions/configure-pages@v6
4336
- run: uv run sphinx-build -c docs . docs/_build/html
44-
- uses: actions/upload-pages-artifact@v4
37+
- uses: actions/upload-pages-artifact@v5
4538
with:
4639
path: docs/_build/html
4740

@@ -53,5 +46,5 @@ jobs:
5346
needs: build_docs
5447
runs-on: ubuntu-latest
5548
steps:
56-
- uses: actions/deploy-pages@v4
49+
- uses: actions/deploy-pages@v5
5750
id: deployment

0 commit comments

Comments
 (0)