Skip to content

Commit fea2be6

Browse files
committed
Initial commit
0 parents  commit fea2be6

File tree

145 files changed

+13815
-0
lines changed

Some content is hidden

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

145 files changed

+13815
-0
lines changed

.github/workflows/release.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Based on https://github.com/python-poetry/poetry/blob/main/.github/workflows/release.yml
2+
name: Release
3+
4+
on:
5+
push:
6+
tags:
7+
- '*.*.*'
8+
9+
jobs:
10+
11+
tests:
12+
uses: ./.github/workflows/tests.yml
13+
14+
release:
15+
name: Release
16+
runs-on: ubuntu-latest
17+
needs: [tests]
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Exit test
24+
run: exit 1
25+
26+
- name: Set up Python 3.12
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: "3.12"
30+
31+
- name: Install Poetry
32+
run: curl -sSL https://install.python-poetry.org | python - -y
33+
34+
- name: Update PATH
35+
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
36+
37+
- name: Show package version
38+
run: poetry version
39+
40+
- name: Build package
41+
run: poetry build
42+
43+
- name: Check version
44+
id: check-version
45+
run: |
46+
[[ "$(poetry version --short)" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo prerelease=true >> $GITHUB_OUTPUT
47+
48+
- name: Create GitHub release
49+
uses: ncipollo/release-action@v1
50+
with:
51+
artifacts: "dist/*"
52+
token: ${{ secrets.GITHUB_TOKEN }}
53+
draft: false
54+
generateReleaseNotes: true
55+
prerelease: steps.check-version.outputs.prerelease == 'true'
56+
57+
# - name: Publish to PyPI
58+
# env:
59+
# POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
60+
# run: poetry publish

.github/workflows/tests.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Tests
2+
3+
run-name: ${{ github.event.head_commit.message }}
4+
5+
on:
6+
push:
7+
branches: [ "master" ]
8+
pull_request:
9+
branches: [ "master" ]
10+
11+
jobs:
12+
13+
tests:
14+
strategy:
15+
fail-fast: true
16+
matrix:
17+
# No windows because make is not available there.
18+
os: [ubuntu-latest, macos-latest]
19+
python-version: ["3.9", "3.10", "3.11", "3.12"]
20+
21+
runs-on: ${{ matrix.os }}
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Python ${{ matrix.python-version }}
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
32+
- name: Install Poetry
33+
run: curl -sSL https://install.python-poetry.org | python - -y
34+
35+
- name: Update PATH
36+
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
37+
38+
- name: Install dependencies
39+
run: make dev
40+
41+
- name: Run checks
42+
run: make check_format
43+
44+
- name: Run tests
45+
run: make test

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
__pycache__/
2+
__pypackages__/
3+
build/
4+
dist/
5+
.coverage
6+
.env
7+
env/
8+
venv/
9+
.mypy_cache/
10+
.idea/
11+
poetry.lock
12+
.python-version
13+
CHANGELOG.md

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2015 Nelson Brochado (aka nbro)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
POETRY := $(shell command -v poetry 2> /dev/null)
2+
3+
.PHONY: help
4+
help: ## Show this help
5+
@egrep -h '\s##\s' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-30s\033[0m %s\n", $$1, $$2}'
6+
7+
.DEFAULT_GOAL := help
8+
9+
.PHONY: poetry_installed
10+
poetry_installed:
11+
ifndef POETRY
12+
@echo "Poetry does not seem to be installed, but it's required."
13+
@echo "You can install it by typing: make install_poetry"
14+
@echo "For more details about how you can install poetry, see https://python-poetry.org/"
15+
@exit 1
16+
endif
17+
18+
.PHONY: install_poetry
19+
install_poetry: ## Install poetry
20+
ifndef POETRY
21+
curl -sSL https://install.python-poetry.org | python3 -
22+
endif
23+
24+
.PHONY: dev
25+
dev: poetry_installed ## Setup the development environment
26+
poetry --version
27+
poetry run python --version
28+
poetry check || poetry update
29+
poetry install --all-extras
30+
poetry env info
31+
poetry show
32+
33+
.PHONY: test
34+
test: poetry_installed ## Run the tests
35+
# poetry run coverage run -m pytest
36+
poetry run coverage run --source=. -m unittest discover -s tests -v
37+
poetry run coverage report
38+
39+
.PHONY: format
40+
format: poetry_installed ## Format the code
41+
poetry run isort andz tests
42+
poetry run black andz tests
43+
44+
.PHONY: check_format
45+
check_format: poetry_installed ## Check if the code is formatted
46+
poetry run isort --check --diff andz tests
47+
poetry run black --check --diff andz tests
48+
49+
.PHONY: check_types
50+
check_types: poetry_installed ## Run type-checks
51+
poetry run mypy andz
52+
53+
.PHONY: check_style
54+
check_style: poetry_installed ## Run style checks
55+
poetry run pylint andz tests
56+
57+
.PHONY: check
58+
check: check_format check_types check_style ## Run all quality assurance checks

README.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Algorithms and Data Structures (andz)
2+
3+
[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
4+
[![](https://img.shields.io/badge/stability-experimental-red.svg)](http://www.engr.sjsu.edu/fayad/SoftwareStability/)
5+
[![Packagist](https://img.shields.io/packagist/l/doctrine/orm.svg?maxAge=2592000)](./LICENSE.md)
6+
7+
## Introduction
8+
9+
`andz` stands for **a**lgorithms a**n**d **d**ata structure**z**.
10+
11+
> The `s` was replaced with `z` because
12+
> there was already a dummy package called `ands` on PyPI.
13+
14+
In this package, you can find some of the most common algorithms and
15+
data structures studied in Computer Science,
16+
such as quick-sort or binary-search trees.
17+
The algorithms are divided into main categories,
18+
such as sorting algorithms or dynamic programming algorithms, but note that
19+
some algorithms and DS can fall into multiple categories .
20+
21+
> The current main goal of this project is for me to learn more about
22+
new algorithms and data structures, but I hope these implementations
23+
can also be useful to anyone interested in them.
24+
25+
## Development
26+
27+
I use
28+
29+
- [poetry](https://python-poetry.org/) for development
30+
- the [`Makefile`](./Makefile) to declare common commands
31+
- [`pyenv`](https://github.com/pyenv/pyenv) to manage different Python versions locally
32+
- GitHub Actions for CI/CD
33+
34+
For more info about how to develop,
35+
see [`./docs/how_to_develop.md`](docs/how_to_develop.md).
36+
37+
## How to install?
38+
39+
```
40+
pip install andz
41+
```
42+
43+
## Documentation
44+
45+
Most modules and functions have been thoroughly documented,
46+
so the best way to learn about the algorithms and data structures is
47+
to read the source code and the related docstrings and comments.
48+
49+
You can find more documentation under [`docs`](./docs).
50+
There you will find the history of the project,
51+
development conventions that should be adapted, etc.

andz/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
# File to allow this directory to be treated as a Python package.

0 commit comments

Comments
 (0)