Common data structures and algorithms written in Python for learning
Project description
dsap: Data Structures & Algorithms & Practice
Python data structures & algorithms repository (for learning).
Usage
Note: Requires installation first!
To actually import and use this package, you can start in the root directory.
Open a python3 interpreter, and try the following:
>>> from dsap.sort import heap_sort
>>> heap_sort([5, 1, 3, 2, 4])
[1, 2, 3, 4, 5]
Setup
This repo assumes you have a modern Python 3+ version installed. The repo is set up to work with VS Code. Default settings and extensions are recommended to use across the projects.
This includes:
- Python language server
- Python Black Formatter
- Python linting using Ruff
- Python strict type checking using pylance + mypy
- Testing using pytest + plugins
- ...a few more! (check
.vscode/extensions.json)
venv
It is highly recommended to set up a virtual env to isolate the project setup from your global system Python / packages. We install the core project dependencies, and the set of test dependencies to enable testing commands.
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install ".[test]"
After initial setup, VSCode should automatically pick up the environment and iniitalize future terminal sessions in the venv.
Testing
Note: Tests are written in a separate (but parallel structure) tests/
directory.
pytest
Recommended: To test code in "watch" mode, try the following command (re-runs only affected tests):
ptw . --clear --doctest-modules --testmon
To run pytest for all files, including doctests on modules:
pytest --doctest-modules
To collect test coverage reports (# of lines covered by tests):
pytest --cov=src --cov=examples --cov-report=term-missing:skip-covered --cov-report xml:coverage.xml
To run pytest with the python debugger for debugging failed tests, run the following (optionally set breakpoints to debug non-failures):
pytest --doctest-modules --pdb
In the python debugger, there are many useful commands to inspect the stack, variables, and such. Some starter commands (more at pdb reference):
l # List the code around the current line (e.g., breakpoint).
p my_variable # Print the given variable with its value at the current line.
q # Quit.
Packaging
To build the project for packaging / distribution, you can run the following:
python3 -m build
Test PyPi
To deploy the package to Test PyPi, follow these instructions, make sure to update the version number, and then run the commands:
rm -r dist/
python3 -m build
python3 -m twine upload --repository testpypi dist/*
To install the package locally from TestPyPi, you can do the following:
python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps dsap
>>> from dsap.sort import heap_sort
>>> heap_sort([5, 1, 3, 2, 4])
[1, 2, 3, 4, 5]
Production PyPi
To deploy the package to PyPi, follow these instructions, make sure to update the version number, and then run the commands:
rm -r dist/
python3 -m build
python3 -m twine upload dist/*
To install the package locally from PyPi, you can do the following:
python3 -m pip install dsap
>>> from dsap.sort import heap_sort
>>> heap_sort([5, 1, 3, 2, 4])
[1, 2, 3, 4, 5]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dsap-0.0.2.tar.gz.
File metadata
- Download URL: dsap-0.0.2.tar.gz
- Upload date:
- Size: 52.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
874362fe4d78759129d76e8282b815361036925037df4094cbf210213075a448
|
|
| MD5 |
fd856d2e1adcc75cdffdb2044eb322a8
|
|
| BLAKE2b-256 |
a4cbcf804848c207a2a7198736905c0903266a5f06fa066c0bde966465e88639
|
File details
Details for the file dsap-0.0.2-py3-none-any.whl.
File metadata
- Download URL: dsap-0.0.2-py3-none-any.whl
- Upload date:
- Size: 50.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dea9f2c4df7c009ac7569f1c3881b7d885743e30d402490e796764604345287e
|
|
| MD5 |
861d962691034067194cc68d7b75a71f
|
|
| BLAKE2b-256 |
73d59b728b11e180bb6ff932fda4eae468feb78f5ec4b3c0b879690d62d38faa
|