Skip to content

Commit 6d28e45

Browse files
authored
Merge branch 'master' into add-docstring-all-permutations
2 parents 58e12b0 + aa1c853 commit 6d28e45

151 files changed

Lines changed: 10434 additions & 1794 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: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
> **Optional hint:** When a PR hand-writes a simple class that is mostly a
37+
> bundle of fields (a manual `__init__` plus `__repr__`/`__eq__`), it is worth
38+
> **suggesting** `from typing import NamedTuple` or
39+
> `from dataclasses import dataclass` where they would simplify the code. These
40+
> are underutilized tools that our contributors would benefit from using where
41+
> they make sense. Offer it as an optional improvement, not a blocker — do not
42+
> request changes solely because a class was written the longhand way.
43+
44+
#### When a PR fails `ruff check`
45+
46+
Don't just report the failure — try the mechanical fixes and recommend the one
47+
that works, in this order:
48+
49+
1. Run `ruff check --fix file_path.py`. If that makes the file pass, recommend
50+
that solution — these are the fixes `ruff` considers **safe**.
51+
2. If it still fails, run `ruff check --fix --unsafe-fixes file_path.py`. If that
52+
makes the file pass **and** the resulting diff is genuinely safe (it preserves
53+
behavior — review it, don't trust it blindly), recommend that solution and note
54+
that it required `--unsafe-fixes`.
55+
3. If neither passes, or the unsafe fix would change behavior, describe the
56+
remaining rule violations and the manual change the author needs to make.
57+
58+
Always quote the exact rule code(s) `ruff` reports (e.g., `ruff rule UP047`,
59+
`ruff rule RUF100`) so the author can run those commands to read the rules being
60+
flagged. Also, paste the concrete command you ran.
61+
62+
### 3. Other Requirements for Submissions
63+
64+
- [ ] At least one **Wikipedia (or equivalent) URL** documenting the algorithm.
65+
- [ ] Docstring explains what the function does and its parameters/returns.
66+
- [ ] No unnecessary third-party dependencies.
67+
68+
### 4. Verdict — fixed output shape
69+
70+
Emit exactly these headings so reviews are comparable and easy to automate:
71+
72+
```
73+
### Is this an algorithm? — <yes/no + one-line why>
74+
### Duplicate / prior-art check — <#NNNN | none found>
75+
### Coding style — <pass | issues: …>
76+
### Other requirements (doctests, type hints, descriptive names, Wikipedia URL) — <pass | issues: …>
77+
### Verdict — <approve | request changes | close> + one-line reason
78+
```
79+
80+
## Tone
81+
82+
Be specific and kind. Point at the exact `CONTRIBUTING.md` rule and offer the fix
83+
rather than a bare rejection — first-time and Hacktoberfest contributors are more
84+
likely to come back and improve the PR when the path forward is clear.
85+
86+
## Map findings to labels
87+
88+
Where a finding matches an existing label, name it so the review lines up with the
89+
maintenance/cleanup tooling:
90+
91+
- missing/failing doctests → `require tests`
92+
- missing type hints → `require type hints`
93+
- non-descriptive names → `require descriptive names`
94+
- CI red → `tests are failing`
95+
- otherwise ready for a maintainer → `awaiting reviews`
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
- [ ] For a simple class that is mostly a bundle of fields, **consider**
45+
`from typing import NamedTuple` or `from dataclasses import dataclass`
46+
instead of a hand-written `__init__`/`__repr__`/`__eq__`. These are
47+
underutilized tools that make simple classes shorter and clearer — use
48+
them where they genuinely simplify the code, not everywhere.
49+
- [ ] Code is formatted and lint-clean (`ruff`, `pre-commit`).
50+
- [ ] `DIRECTORY.md` and `README.md` are **not hand-edited** — the
51+
`algorithms-keeper` bot regenerates them automatically after merge.
52+
53+
### 3. Other Requirements for Submissions
54+
55+
- [ ] At least one **Wikipedia (or equivalent) URL** documenting the algorithm.
56+
- [ ] Docstring explains what the function does and its parameters/returns.
57+
- [ ] No unnecessary third-party dependencies.

.github/workflows/build.yml

Lines changed: 18 additions & 5 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
1312
- uses: actions/checkout@v7
1413
- uses: astral-sh/setup-uv@v7
1514
with:
1615
enable-cache: true
1716
cache-dependency-glob: uv.lock
1817
- 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ 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:

.github/workflows/directory_writer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
fetch-depth: 0
1212
- 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: |
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Daily refresh of the Hacktoberfest 2026 open-PR cleanup tracker.
2+
# Ticks off any tracked pull request that has since been merged/closed, and
3+
# rewrites the "Automated statistics" section (open issue/PR counts + the top
4+
# three `awaiting reviews` directories). The job fails on purpose once
5+
# Hacktoberfest 2026 has begun (>= 2026-10-01), which is the signal to retire it.
6+
name: hacktoberfest_prep
7+
8+
on:
9+
push:
10+
paths:
11+
- ".github/workflows/hacktoberfest_prep.yml"
12+
- "scripts/hacktoberfest_prep_update.py"
13+
pull_request:
14+
paths:
15+
- ".github/workflows/hacktoberfest_prep.yml"
16+
- "scripts/hacktoberfest_prep_update.py"
17+
schedule:
18+
- cron: "50 11 * * *" # 11:50 UTC every day
19+
workflow_dispatch: # allow a manual run while testing
20+
21+
permissions:
22+
contents: write
23+
24+
jobs:
25+
hacktoberfest-prep:
26+
# No point running on forks — this pushes to the repo's own docs file.
27+
if: github.repository == 'TheAlgorithms/Python'
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v7
31+
- uses: actions/setup-python@v7
32+
with:
33+
python-version-file: .python-version
34+
allow-prereleases: true
35+
- name: Install dependencies
36+
run: python -m pip install --upgrade "httpx2>=2.0.1"
37+
- name: Update the tracker
38+
id: update
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
GITHUB_REPOSITORY: ${{ github.repository }}
42+
# Don't let the intentional post-Oct-1 failure stop the commit step;
43+
# capture the exit code and re-raise it after pushing any changes.
44+
run: |
45+
set +e
46+
python scripts/hacktoberfest_prep_update.py
47+
echo "exit_code=$?" >> "$GITHUB_OUTPUT"
48+
# Dry run on push / pull_request: show the diff the script produced but
49+
# do NOT commit or push. This lets a PR prove the tracker still gathers
50+
# its data and rewrites docs/hacktober_2026_prep.md correctly without
51+
# leaving a permanent commit. Only the schedule/manual runs persist.
52+
- name: Show changes (dry run)
53+
if: github.event_name == 'push' || github.event_name == 'pull_request'
54+
run: |
55+
echo "Dry run (${{ github.event_name }}): showing git diff, not committing."
56+
git --no-pager diff -- docs/hacktober_2026_prep.md
57+
if git diff --quiet -- docs/hacktober_2026_prep.md; then
58+
echo "No changes to docs/hacktober_2026_prep.md."
59+
fi
60+
- name: Commit any changes
61+
if: github.event_name != 'push' && github.event_name != 'pull_request'
62+
run: |
63+
git config --global user.name "$GITHUB_ACTOR"
64+
git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com"
65+
git add docs/hacktober_2026_prep.md
66+
git commit -m "chore: refresh Hacktoberfest 2026 prep tracker" || echo "No changes to commit"
67+
git push || echo "Nothing to push"
68+
- name: Propagate the script's exit code
69+
run: exit ${{ steps.update.outputs.exit_code }}

0 commit comments

Comments
 (0)