Skip to content

Commit 23d3b13

Browse files
authored
Merge branch 'master' into master
2 parents 2dfeac1 + da48fb8 commit 23d3b13

433 files changed

Lines changed: 18357 additions & 2924 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/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ ARG VARIANT=3.13-bookworm
33
FROM mcr.microsoft.com/vscode/devcontainers/python:${VARIANT}
44
COPY requirements.txt /tmp/pip-tmp/
55
RUN python3 -m pip install --upgrade pip \
6-
&& python3 -m pip install --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
7-
&& pipx install pre-commit ruff \
8-
&& pre-commit install
6+
&& python3 -m pip install --no-cache-dir -r /tmp/pip-tmp/requirements.txt \
7+
&& pipx install pre-commit ruff

.devcontainer/README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
1-
https://code.visualstudio.com/docs/devcontainers/tutorial
1+
# Development Container
2+
3+
This is **Devcontainer** configuration to provide a consistent development environment for all contributors.
4+
5+
## Features
6+
7+
- [x] Pre-configured **Python environment**
8+
- [x] Automatic installation of **pre-commit hooks**
9+
- [x] **Ruff** linter ready to check your code
10+
- [x] **Oh My Zsh** with plugins:
11+
- `zsh-autosuggestions`
12+
- `zsh-syntax-highlighting`
13+
14+
## Usage
15+
16+
1. Install [**Docker** ](https://www.docker.com/get-started/) and [**Visual Studio Code**](https://code.visualstudio.com/)
17+
2. Install the **Remote - Containers** extension in VS Code
18+
19+
- Do `CTRL+P`, paste this command and press `Enter`
20+
21+
```shell
22+
ext install ms-vscode-remote.remote-containers
23+
```
24+
3. Open this repository in VS Code
25+
4. When prompted, click **"Reopen in Container"**
26+
5. Wait for the environment to build and initialize
27+
28+
After setup:
29+
30+
- `pre-commit` hooks are installed
31+
- `ruff` and other tools are available
32+
- The shell uses Zsh by default
33+
34+
## Tips
35+
36+
To manually run checks on all files:
37+
38+
```bash
39+
pre-commit run --all-files
40+
```
41+
42+
> For further information here's [Microsoft tutorial about devcontainers.](https://code.visualstudio.com/docs/devcontainers/tutorial)

.devcontainer/devcontainer.json

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +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-
},
3+
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",
1323

1424
// Configure tool-specific properties.
1525
"customizations": {
@@ -18,25 +28,30 @@
1828
// Set *default* container specific settings.json values on container create.
1929
"settings": {
2030
"python.defaultInterpreterPath": "/usr/local/bin/python",
21-
"python.linting.enabled": true,
22-
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
23-
"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+
},
40+
"terminal.integrated.defaultProfile.linux": "zsh"
2441
},
2542

2643
// Add the IDs of extensions you want installed when the container is created.
2744
"extensions": [
2845
"ms-python.python",
29-
"ms-python.vscode-pylance"
46+
"ms-python.vscode-pylance",
47+
"charliermarsh.ruff"
3048
]
3149
}
3250
},
3351

3452
// Use 'forwardPorts' to make a list of ports inside the container available locally.
3553
// "forwardPorts": [],
3654

37-
// Use 'postCreateCommand' to run commands after the container is created.
38-
// "postCreateCommand": "pip3 install --user -r requirements.txt",
39-
4055
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
4156
"remoteUser": "vscode"
4257
}

.devcontainer/post_install

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Begin post-installation steps..."
4+
5+
set -e
6+
7+
echo "Installing pre-commit hooks..."
8+
pre-commit install
9+
10+
echo "Installing Oh My Zsh plugins..."
11+
12+
# Install zsh-autosuggestions if not present
13+
if [ ! -d "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions" ]; then
14+
echo "Cloning zsh-autosuggestions..."
15+
git clone https://github.com/zsh-users/zsh-autosuggestions \
16+
"${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions"
17+
fi
18+
19+
# Install zsh-syntax-highlighting if not present
20+
if [ ! -d "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting" ]; then
21+
echo "Cloning zsh-syntax-highlighting..."
22+
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git \
23+
"${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting"
24+
fi
25+
26+
echo "Configuring plugins in ~/.zshrc..."
27+
sed -i '/^plugins=/c\plugins=(git zsh-autosuggestions zsh-syntax-highlighting)' ~/.zshrc
28+
29+
echo "Post-installation steps completed successfully. Enjoy!"
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: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,45 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v4
13-
- uses: actions/setup-python@v5
12+
- uses: actions/checkout@v7
13+
- uses: astral-sh/setup-uv@v7
1414
with:
15-
python-version: 3.13
16-
allow-prereleases: true
17-
- uses: actions/cache@v4
15+
enable-cache: true
16+
cache-dependency-glob: uv.lock
17+
- uses: actions/setup-python@v7
1818
with:
19-
path: ~/.cache/pip
20-
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
21-
- name: Install dependencies
22-
run: |
23-
python -m pip install --upgrade pip setuptools wheel
24-
python -m pip install pytest-cov -r requirements.txt
19+
python-version-file: .python-version
20+
allow-prereleases: true
21+
- run: uv sync --group=test
2522
- name: Run tests
26-
# TODO: #8818 Re-enable quantum tests
27-
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
2836
--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/
2942
--ignore=docs/conf.py
3043
--ignore=dynamic_programming/k_means_clustering_tensorflow.py
3144
--ignore=machine_learning/lstm/lstm_prediction.py
3245
--ignore=neural_network/input_data.py
3346
--ignore=project_euler/
3447
--ignore=quantum/q_fourier_transform.py
3548
--ignore=scripts/validate_solutions.py
49+
--ignore=web_programming/current_stock_price.py
50+
--ignore=web_programming/fetch_anime_and_play.py
3651
--cov-report=term-missing:skip-covered
3752
--cov=. .
3853
- if: ${{ success() }}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Test DevContainer Build
2+
3+
on:
4+
push:
5+
paths:
6+
- ".devcontainer/**"
7+
- ".github/workflows/devcontainer_ci.yml"
8+
pull_request:
9+
paths:
10+
- ".devcontainer/**"
11+
- ".github/workflows/devcontainer_ci.yml"
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v7
18+
- uses: devcontainers/ci@v0.3
19+
with:
20+
push: never
21+
runCmd: "true"

0 commit comments

Comments
 (0)