Compare commits

..

No commits in common. "151c158bd986a7d1c257727dec0de37a436a6011" and "67aa70edfa45f33f5aceb228744fec093f86cc99" have entirely different histories.

30 changed files with 117 additions and 238 deletions

View File

@ -1,18 +0,0 @@
[run]
source="."
[report]
show_missing = true
omit =
# ignore tests folder
tests/*
# ignore thirdparty imports
src/thirdparty/*
# ignore __init__ files (only used for exports)
**/__init__.py
# ignore main.py
main.py
# TODO: increase code-coverage:
precision = 0
exclude_lines =
pragma: no cover

View File

@ -6,11 +6,10 @@
################################################################
!/.env
!/justfile
!/.coveragerc
!/Makefile
!/README.md
!/LICENSE
!/requirements.txt
!/requirements
!/pyproject.toml
################################################################
@ -20,7 +19,6 @@
!/src
!/src/**/
!/src/**/*.py
!/main.py
!/tests
!/tests/**/

94
code/python/Makefile Normal file
View File

@ -0,0 +1,94 @@
SHELL:=/usr/bin/env bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Makefile
# NOTE: Do not change the contents of this file!
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include .env
################################
# VARIABLES
################################
ARTEFACT_NAME:=${APPNAME}
PYTHON:=python3
ifeq ($(OS),Windows_NT)
ARTEFACT_NAME:=${APPNAME}.exe
PYTHON=py -3
endif
################################
# Macros
################################
define create_file_if_not_exists
@touch "$(1)";
endef
define create_folder_if_not_exists
if ! [ -d "$(1)" ]; then mkdir "$(1)"; fi
endef
define delete_if_file_exists
@if [ -f "$(1)" ]; then rm "$(1)"; fi
endef
define delete_if_folder_exists
@if [ -d "$(1)" ]; then rm -rf "$(1)"; fi
endef
define clean_all_files
@find . -type f -name "$(1)" -exec basename {} \;
@find . -type f -name "$(1)" -exec rm {} \; 2> /dev/null
endef
define clean_all_folders
@find . -type d -name "$(1)" -exec basename {} \;
@find . -type d -name "$(1)" -exec rm -rf {} \; 2> /dev/null
endef
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
################################
# BASIC TARGETS: setup, build, run
################################
setup: check-system-requirements setup-no-checks
setup-no-checks:
@${PYTHON} -m pip install -r "requirements"
run:
@${PYTHON} src/main.py;
all: setup run
################################
# TARGETS: testing
################################
tests: unit-tests
unit-tests:
@# For logging purposes (since stdout is rechanneled):
@$(call delete_if_file_exists,logs/debug.log)
@$(call create_folder_if_not_exists,logs)
@$(call create_file_if_not_exists,logs/debug.log)
@# for python unit tests:
@${PYTHON} -m pytest tests --cache-clear --verbose -k test_
@cat logs/debug.log
################################
# AUXILIARY (INTERNAL TARGETS)
################################
check-system-requirements:
@if ! ( ${PYTHON} --version >> /dev/null 2> /dev/null ); then \
echo "Install Python 3.10.x first!"; \
exit 1; \
fi
@${PYTHON} --version
################################
# TARGETS: clean
################################
clean:
@echo "All system artefacts will be force removed."
@$(call clean_all_files,.DS_Store)
@echo "All build artefacts will be force removed."
@$(call clean_all_folders,__pycache__)
@$(call clean_all_folders,.pytest_cache)
@$(call delete_if_file_exists,dist/${ARTEFACT_NAME})
@exit 0

View File

@ -10,7 +10,9 @@ die Methoden mit Daten ausprobieren.
## Voraussetzungen ##
1. Der Python-Compiler **`^3.10.*`** wird benötigt.
2. Es ist auch empfehlenswert, **`justfile`** zu installieren (siehe <https://github.com/casey/just#installation>).
2. Es ist auch empfehlenswert, **`make`** zu installieren.
- Linux/OSX: siehe <https://formulae.brew.sh/formula/make>.
- Windows: siehe <https://community.chocolatey.org/packages/make>.
## Setup -> Test -> Run ##
@ -18,27 +20,25 @@ In einem IDE in dem Repo zu diesem Ordner navigieren.
</br>
Eine bash-Konsole aufmachen und folgende Befehle ausführen:
Wer das **justfile**-Tool hat:
Wer **make** installiert hat:
```bash
# Zeige alle Befehle:
just
# Zur Installation der Requirements (nur nach Änderungen):
just setup;
make setup;
# Zur Ausführung der unit tests:
just tests;
make tests;
# Zur Ausführung des Programms
just run;
make run;
# Zur Bereinigung aller Artefakte
just clean;
make clean;
```
Wer das justfile-Tool hat:
Wer _kein_ make hat:
```bash
# Zur Installation der Requirements (nur nach Änderungen):
python3 -m pip install -r requirements.txt;
python3 -m pip install -r requirements;
# Zur Ausführung der unit tests:
python3 -m pytest tests --cache-clear --verbose -k test_;
# Zur Ausführung des Programms:
python3 main.py
python3 src/main.py
```
Auf Windows verwendet man `py -3` od. `py -310` statt `python3`.

View File

@ -1,147 +0,0 @@
set shell := [ "bash", "-uc" ]
_default:
@- just --unsorted --choose
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Justfile
# NOTE: Do not change the contents of this file!
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# VARIABLES
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PYTHON := if os_family() == "windows" { "py -3" } else { "python3" }
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Macros
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_create-file-if-not-exists fname:
@touch "{{fname}}";
_create-folder-if-not-exists path:
@if ! [ -d "{{path}}" ]; then mkdir "{{path}}"; fi
_delete-if-file-exists fname:
@if [ -f "{{fname}}" ]; then rm "{{fname}}"; fi
_delete-if-folder-exists path:
@if [ -d "{{path}}" ]; then rm -rf "{{path}}"; fi
_clean-all-files pattern:
@find . -type f -name "{{pattern}}" -exec basename {} \; 2> /dev/null
@- find . -type f -name "{{pattern}}" -exec rm {} \; 2> /dev/null
_clean-all-folders pattern:
@find . -type d -name "{{pattern}}" -exec basename {} \; 2> /dev/null
@- find . -type d -name "{{pattern}}" -exec rm -rf {} \; 2> /dev/null
_docker-build-and-log service:
@docker compose up --build -d {{service}} && docker compose logs -f --tail=0 {{service}}
_docker-build-and-interact service container:
@docker compose up --build -d {{service}} && docker attach {{container}}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: build
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
build:
@{{PYTHON}} -m pip install --disable-pip-version-check -r requirements.txt
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: run
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
run:
@{{PYTHON}} main.py
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: tests
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tests: tests-unit
tests-logs:
@just _create-logs
@- just tests
@just _display-logs
tests-unit-logs:
@just _create-logs
@- just tests-unit
@just _display-logs
tests-unit:
@{{PYTHON}} -m pytest tests \
--ignore=tests/integration \
--cov-reset \
--cov=. \
2> /dev/null
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: qa
# NOTE: use for development only.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
qa:
@{{PYTHON}} -m coverage report -m
coverage source_path tests_path:
@just _create-logs
@-just _coverage-no-logs "{{source_path}}" "{{tests_path}}"
@just _display-logs
_coverage-no-logs source_path tests_path:
@{{PYTHON}} -m pytest {{tests_path}} \
--ignore=tests/integration \
--cov-reset \
--cov={{source_path}} \
--capture=tee-sys \
2> /dev/null
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: clean
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clean:
@-just clean-basic
@-just clean-sessions
clean-sessions:
@echo "All sessions will be force removed."
@- just _delete-if-folder-exists ".secrets" 2> /dev/null
clean-basic:
@echo "All system artefacts will be force removed."
@- just _clean-all-files ".DS_Store" 2> /dev/null
@echo "All test artefacts will be force removed."
@- just _clean-all-folders ".pytest_cache" 2> /dev/null
@- just _delete-if-file-exists ".coverage" 2> /dev/null
@- just _delete-if-folder-exists "logs"
@echo "All build artefacts will be force removed."
@- just _clean-all-folders "__pycache__" 2> /dev/null
@- just _delete-if-folder-exists "models/generated" 2> /dev/null
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: logging, session
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_create-logs:
@# For logging purposes (since stdout is rechanneled):
@just _delete-if-file-exists "logs/debug.log"
@just _create-folder-if-not-exists "logs"
@just _create-file-if-not-exists "logs/debug.log"
_display-logs:
@echo ""
@echo "Content of logs/debug.log:"
@echo "----------------"
@echo ""
@- cat logs/debug.log
@echo ""
@echo "----------------"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: requirements
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check-system:
@echo "Operating System detected: {{os_family()}}."
@echo "Python command used: {{PYTHON}}."

View File

@ -1,56 +1,8 @@
[project]
name = "uni-leipzig-ads-2-2022"
version = "1.0.0"
description = "Open HPI Kurs Quantum Computing Teil 1"
authors = [ "Raj Dahya" ]
maintainers = [ "raj_mathe" ]
license = "MIT"
readme = "README.md"
python = "^3.10"
homepage = "https://gitea.math.uni-leipzig.de/raj_mathe"
repository = "https://gitea.math.uni-leipzig.de/raj_mathe/ads2_2022"
documentation = "https://gitea.math.uni-leipzig.de/raj_mathe/ads2_2022/README.md"
keywords = [
"algorithmmen und datenstrukturen 2",
"sommersemester",
"2022",
"universität leipzig",
]
# cf. https://pypi.org/classifiers
classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: Developers",
"Operating System :: Unix",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
]
[tool.pytest.ini_options]
minversion = "7.1.1"
testpaths = [
"tests",
]
python_files = [
"**/tests_*.py",
]
asyncio_mode = "auto"
filterwarnings = [
"error",
"ignore::UserWarning",
"ignore::DeprecationWarning",
]
# NOTE: appends (not prepends) flags:
addopts = [
"--order-dependencies",
"--order-group-scope=module",
"--cache-clear",
"--verbose",
"--maxfail=1",
"-k test_",
"--no-cov-on-fail",
"--cov-report=term",
"--cov-config=.coveragerc",
"**/test_*.py",
]

View File

@ -7,7 +7,7 @@
from __future__ import annotations;
from src.thirdparty.typing import *;
from src.local.typing import *;
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# EXPORTS

View File

@ -11,7 +11,7 @@ from dataclasses import dataclass;
from dataclasses import field
from platform import node;
from src.thirdparty.typing import *;
from src.local.typing import *;
from src.core.log import *;
from src.stacks.stack import *;

View File

@ -12,7 +12,7 @@ os.chdir(os.path.join(os.path.dirname(__file__), '..'));
sys.path.insert(0, os.getcwd());
from src.core.log import *;
from src.thirdparty.maths import *;
from src.local.maths import *;
from src.graphs.graph import *;
from src.graphs.tarjan import *;
from src.travel.naive import *;

View File

@ -5,7 +5,7 @@
# IMPORTS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from src.thirdparty.typing import *;
from src.local.typing import *;
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# EXPORTS

View File

@ -6,8 +6,8 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from __future__ import annotations;
from src.thirdparty.typing import *;
from src.thirdparty.maths import *;
from src.local.typing import *;
from src.local.maths import *;

View File

@ -6,8 +6,8 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from __future__ import annotations;
from src.thirdparty.typing import *;
from src.thirdparty.maths import *;
from src.local.typing import *;
from src.local.maths import *;
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# EXPORTS

View File

@ -12,7 +12,7 @@ from pytest import lazy_fixture;
from unittest import TestCase;
from unittest.mock import patch;
from src.thirdparty.typing import *;
from src.local.typing import *;
from src.graphs.graph import *;
from src.graphs.tarjan import *;