Skip to content

Commit 9889d28

Browse files
committed
2 parents 6dcbab0 + e9e7c96 commit 9889d28

File tree

18 files changed

+202
-11
lines changed

18 files changed

+202
-11
lines changed

.devcontainer/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# https://github.com/microsoft/vscode-dev-containers/blob/main/containers/python-3/README.md
2-
ARG VARIANT=3.12-bookworm
2+
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 \

.devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Update 'VARIANT' to pick a Python version: 3, 3.11, 3.10, 3.9, 3.8
88
// Append -bullseye or -buster to pin to an OS version.
99
// Use -bullseye variants on local on arm64/Apple Silicon.
10-
"VARIANT": "3.12-bookworm",
10+
"VARIANT": "3.13-bookworm",
1111
}
1212
},
1313

.github/CODEOWNERS

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
/.* @cclauss
1111

12-
# /arithmetic_analysis/
13-
1412
# /backtracking/
1513

1614
# /bit_manipulation/

.github/workflows/build.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ jobs:
2525
- name: Run tests
2626
# TODO: #8818 Re-enable quantum tests
2727
run: pytest
28-
--ignore=quantum/q_fourier_transform.py
2928
--ignore=computer_vision/cnn_classification.py
29+
--ignore=docs/conf.py
3030
--ignore=dynamic_programming/k_means_clustering_tensorflow.py
3131
--ignore=machine_learning/lstm/lstm_prediction.py
3232
--ignore=neural_network/input_data.py
3333
--ignore=project_euler/
34+
--ignore=quantum/q_fourier_transform.py
3435
--ignore=scripts/validate_solutions.py
3536
--cov-report=term-missing:skip-covered
3637
--cov=. .

.github/workflows/sphinx.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: sphinx
2+
3+
on:
4+
# Triggers the workflow on push or pull request events but only for the "master" branch
5+
push:
6+
branches: ["master"]
7+
pull_request:
8+
branches: ["master"]
9+
# Or manually from the Actions tab
10+
workflow_dispatch:
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
build_docs:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: actions/setup-python@v5
30+
with:
31+
python-version: 3.13
32+
allow-prereleases: true
33+
- run: pip install --upgrade pip
34+
- run: pip install myst-parser sphinx-autoapi sphinx-pyproject
35+
- uses: actions/configure-pages@v5
36+
- run: sphinx-build -c docs . docs/_build/html
37+
- uses: actions/upload-pages-artifact@v3
38+
with:
39+
path: docs/_build/html
40+
41+
deploy_docs:
42+
environment:
43+
name: github-pages
44+
url: ${{ steps.deployment.outputs.page_url }}
45+
if: github.event_name != 'pull_request'
46+
needs: build_docs
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/deploy-pages@v4
50+
id: deployment

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.6.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-executables-have-shebangs
66
- id: check-toml
@@ -16,7 +16,7 @@ repos:
1616
- id: auto-walrus
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.6.8
19+
rev: v0.6.9
2020
hooks:
2121
- id: ruff
2222
- id: ruff-format

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pre-commit run --all-files --show-diff-on-failure
7777

7878
We want your work to be readable by others; therefore, we encourage you to note the following:
7979

80-
- Please write in Python 3.12+. For instance: `print()` is a function in Python 3 so `print "Hello"` will *not* work but `print("Hello")` will.
80+
- Please write in Python 3.13+. For instance: `print()` is a function in Python 3 so `print "Hello"` will *not* work but `print("Hello")` will.
8181
- Please focus hard on the naming of functions, classes, and variables. Help your reader by using __descriptive names__ that can help you to remove redundant comments.
8282
- Single letter variable names are *old school* so please avoid them unless their life only spans a few lines.
8383
- Expand acronyms because `gcd()` is hard to understand but `greatest_common_divisor()` is not.

DIRECTORY.md

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* [Rat In Maze](backtracking/rat_in_maze.py)
2323
* [Sudoku](backtracking/sudoku.py)
2424
* [Sum Of Subsets](backtracking/sum_of_subsets.py)
25+
* [Word Break](backtracking/word_break.py)
2526
* [Word Ladder](backtracking/word_ladder.py)
2627
* [Word Search](backtracking/word_search.py)
2728

@@ -99,6 +100,7 @@
99100
* [Elgamal Key Generator](ciphers/elgamal_key_generator.py)
100101
* [Enigma Machine2](ciphers/enigma_machine2.py)
101102
* [Fractionated Morse Cipher](ciphers/fractionated_morse_cipher.py)
103+
* [Gronsfeld Cipher](ciphers/gronsfeld_cipher.py)
102104
* [Hill Cipher](ciphers/hill_cipher.py)
103105
* [Mixed Keyword Cypher](ciphers/mixed_keyword_cypher.py)
104106
* [Mono Alphabetic Ciphers](ciphers/mono_alphabetic_ciphers.py)
@@ -211,6 +213,7 @@
211213
* [Lazy Segment Tree](data_structures/binary_tree/lazy_segment_tree.py)
212214
* [Lowest Common Ancestor](data_structures/binary_tree/lowest_common_ancestor.py)
213215
* [Maximum Fenwick Tree](data_structures/binary_tree/maximum_fenwick_tree.py)
216+
* [Maximum Sum Bst](data_structures/binary_tree/maximum_sum_bst.py)
214217
* [Merge Two Binary Trees](data_structures/binary_tree/merge_two_binary_trees.py)
215218
* [Mirror Binary Tree](data_structures/binary_tree/mirror_binary_tree.py)
216219
* [Non Recursive Segment Tree](data_structures/binary_tree/non_recursive_segment_tree.py)
@@ -284,6 +287,7 @@
284287
* [Dijkstras Two Stack Algorithm](data_structures/stacks/dijkstras_two_stack_algorithm.py)
285288
* [Infix To Postfix Conversion](data_structures/stacks/infix_to_postfix_conversion.py)
286289
* [Infix To Prefix Conversion](data_structures/stacks/infix_to_prefix_conversion.py)
290+
* [Lexicographical Numbers](data_structures/stacks/lexicographical_numbers.py)
287291
* [Next Greater Element](data_structures/stacks/next_greater_element.py)
288292
* [Postfix Evaluation](data_structures/stacks/postfix_evaluation.py)
289293
* [Prefix Evaluation](data_structures/stacks/prefix_evaluation.py)
@@ -347,6 +351,9 @@
347351
* [Power](divide_and_conquer/power.py)
348352
* [Strassen Matrix Multiplication](divide_and_conquer/strassen_matrix_multiplication.py)
349353

354+
## Docs
355+
* [Conf](docs/conf.py)
356+
350357
## Dynamic Programming
351358
* [Abbreviation](dynamic_programming/abbreviation.py)
352359
* [All Construct](dynamic_programming/all_construct.py)
@@ -1201,6 +1208,7 @@
12011208
* [Binary Tree Traversal](searches/binary_tree_traversal.py)
12021209
* [Double Linear Search](searches/double_linear_search.py)
12031210
* [Double Linear Search Recursion](searches/double_linear_search_recursion.py)
1211+
* [Exponential Search](searches/exponential_search.py)
12041212
* [Fibonacci Search](searches/fibonacci_search.py)
12051213
* [Hill Climbing](searches/hill_climbing.py)
12061214
* [Interpolation Search](searches/interpolation_search.py)

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
MIT License
1+
## MIT License
22

33
Copyright (c) 2016-2022 TheAlgorithms and contributors
44

ciphers/autokey.py

+16
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ def encrypt(plaintext: str, key: str) -> str:
2424
Traceback (most recent call last):
2525
...
2626
ValueError: plaintext is empty
27+
>>> encrypt("coffee is good as python", "")
28+
Traceback (most recent call last):
29+
...
30+
ValueError: key is empty
31+
>>> encrypt(527.26, "TheAlgorithms")
32+
Traceback (most recent call last):
33+
...
34+
TypeError: plaintext must be a string
2735
"""
2836
if not isinstance(plaintext, str):
2937
raise TypeError("plaintext must be a string")
@@ -80,6 +88,14 @@ def decrypt(ciphertext: str, key: str) -> str:
8088
Traceback (most recent call last):
8189
...
8290
TypeError: ciphertext must be a string
91+
>>> decrypt("", "TheAlgorithms")
92+
Traceback (most recent call last):
93+
...
94+
ValueError: ciphertext is empty
95+
>>> decrypt("vvjfpk wj ohvp su ddylsv", 2)
96+
Traceback (most recent call last):
97+
...
98+
TypeError: key must be a string
8399
"""
84100
if not isinstance(ciphertext, str):
85101
raise TypeError("ciphertext must be a string")
File renamed without changes.

docs/conf.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from sphinx_pyproject import SphinxConfig
2+
3+
project = SphinxConfig("../pyproject.toml", globalns=globals()).name
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Interest
1+
# Interest
22

33
* Compound Interest: "Compound interest is calculated by multiplying the initial principal amount by one plus the annual interest rate raised to the number of compound periods minus one." [Compound Interest](https://www.investopedia.com/)
44
* Simple Interest: "Simple interest paid or received over a certain period is a fixed percentage of the principal amount that was borrowed or lent. " [Simple Interest](https://www.investopedia.com/)

index.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# TheAlgorithms/Python
2+
```{toctree}
3+
:maxdepth: 2
4+
:caption: index.md
5+
6+
<!-- CONTRIBUTING.md must be the FIRST doc and README.md can come after. -->
7+
CONTRIBUTING.md
8+
README.md
9+
LICENSE.md
10+
```

pyproject.toml

+105-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1+
[project]
2+
name = "thealgorithms-python"
3+
version = "0.0.1"
4+
description = "TheAlgorithms in Python"
5+
authors = [ { name = "TheAlgorithms Contributors" } ]
6+
requires-python = ">=3.13"
7+
classifiers = [
8+
"Programming Language :: Python :: 3 :: Only",
9+
"Programming Language :: Python :: 3.13",
10+
11+
]
12+
optional-dependencies.docs = [
13+
"myst-parser",
14+
"sphinx-autoapi",
15+
"sphinx-pyproject",
16+
]
17+
118
[tool.ruff]
2-
target-version = "py312"
19+
target-version = "py313"
320

421
output-format = "full"
522
lint.select = [
@@ -113,6 +130,9 @@ lint.pylint.max-statements = 88 # default: 50
113130
ignore-words-list = "3rt,ans,bitap,crate,damon,fo,followings,hist,iff,kwanza,manuel,mater,secant,som,sur,tim,toi,zar"
114131
skip = "./.*,*.json,ciphers/prehistoric_men.txt,project_euler/problem_022/p022_names.txt,pyproject.toml,strings/dictionary.txt,strings/words.txt"
115132

133+
[tool.pyproject-fmt]
134+
max_supported_python = "3.13"
135+
116136
[tool.pytest.ini_options]
117137
markers = [
118138
"mat_ops: mark a test as utilizing matrix operations.",
@@ -129,3 +149,87 @@ omit = [
129149
"project_euler/*",
130150
]
131151
sort = "Cover"
152+
153+
[tool.sphinx-pyproject]
154+
copyright = "2014, TheAlgorithms"
155+
autoapi_dirs = [
156+
"audio_filters",
157+
"backtracking",
158+
"bit_manipulation",
159+
"blockchain",
160+
"boolean_algebra",
161+
"cellular_automata",
162+
"ciphers",
163+
"compression",
164+
"computer_vision",
165+
"conversions",
166+
"data_structures",
167+
"digital_image_processing",
168+
"divide_and_conquer",
169+
"dynamic_programming",
170+
"electronics",
171+
"file_transfer",
172+
"financial",
173+
"fractals",
174+
"fuzzy_logic",
175+
"genetic_algorithm",
176+
"geodesy",
177+
"geometry",
178+
"graphics",
179+
"graphs",
180+
"greedy_methods",
181+
"hashes",
182+
"knapsack",
183+
"linear_algebra",
184+
"linear_programming",
185+
"machine_learning",
186+
"maths",
187+
"matrix",
188+
"networking_flow",
189+
"neural_network",
190+
"other",
191+
"physics",
192+
"project_euler",
193+
"quantum",
194+
"scheduling",
195+
"searches",
196+
"sorts",
197+
"strings",
198+
"web_programming",
199+
]
200+
autoapi_member_order = "groupwise"
201+
# autoapi_python_use_implicit_namespaces = true
202+
exclude_patterns = [
203+
".*/*",
204+
"docs/",
205+
]
206+
extensions = [
207+
"autoapi.extension",
208+
"myst_parser",
209+
]
210+
html_static_path = [ "_static" ]
211+
html_theme = "alabaster"
212+
myst_enable_extensions = [
213+
"amsmath",
214+
"attrs_inline",
215+
"colon_fence",
216+
"deflist",
217+
"dollarmath",
218+
"fieldlist",
219+
"html_admonition",
220+
"html_image",
221+
# "linkify",
222+
"replacements",
223+
"smartquotes",
224+
"strikethrough",
225+
"substitution",
226+
"tasklist",
227+
]
228+
myst_fence_as_directive = [
229+
"include",
230+
]
231+
templates_path = [ "_templates" ]
232+
[tool.sphinx-pyproject.source_suffix]
233+
".rst" = "restructuredtext"
234+
# ".txt" = "markdown"
235+
".md" = "markdown"

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ requests
1515
rich
1616
# scikit-fuzzy # uncomment once fuzzy_logic/fuzzy_operations.py is fixed
1717
scikit-learn
18+
sphinx_pyproject
1819
statsmodels
1920
sympy
2021
tensorflow ; python_version < '3.13'

source/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)