From e4f219a6f28ed7b24fa4f9f2678d63c5b64228e2 Mon Sep 17 00:00:00 2001 From: Sebastiaan la Fleur Date: Tue, 9 Jul 2024 10:22:49 +0200 Subject: [PATCH] Initial commit from Cookiecutter template --- .github/workflows/BuildTest_win32.yml | 33 +++ .github/workflows/ci.yml | 112 +++++++++ .github/workflows/codeql-analysis.yml | 72 ++++++ .github/workflows/publish_container_image.yml | 28 +++ .github/workflows/release.yml | 39 +++ .gitignore | 224 ++++++++++++++++++ .taplo.toml | 5 + .vscode/extensions.json | 10 + .vscode/settings.json | 28 +++ CHANGELOG.md | 32 +++ CONTRIBUTING.md | 51 ++++ Dockerfile | 11 + LICENSE | 0 README.md | 5 + VERSION | 1 + ci/linux/build_python_package.sh | 4 + ci/linux/create_venv.sh | 5 + ci/linux/install_dependencies.sh | 4 + ci/linux/lint.sh | 4 + ci/linux/test_unit.sh | 4 + ci/linux/typecheck.sh | 4 + ci/linux/update_dependencies.sh | 5 + ci/win32/create_venv.cmd | 9 + ci/win32/install_dependencies.cmd | 6 + ci/win32/lint.cmd | 8 + ci/win32/test_unit.cmd | 9 + ci/win32/typecheck.cmd | 8 + ci/win32/update_dependencies.cmd | 6 + doc/dev_documentation/Makefile | 20 ++ doc/dev_documentation/Tools.rst | 60 +++++ doc/dev_documentation/conf.py | 57 +++++ doc/dev_documentation/index.rst | 24 ++ doc/dev_documentation/make.bat | 35 +++ doc/user_documentation/Makefile | 20 ++ doc/user_documentation/conf.py | 52 ++++ doc/user_documentation/index.rst | 20 ++ doc/user_documentation/make.bat | 35 +++ pyproject.toml | 102 ++++++++ run.sh | 5 + src/kpicalculator/__init__.py | 17 ++ src/kpicalculator/__main__.py | 19 ++ src/kpicalculator/app_logging.py | 90 +++++++ src/kpicalculator/kpicalculator.py | 44 ++++ src/kpicalculator/py.typed | 0 unit_test/test_main.py | 56 +++++ 45 files changed, 1383 insertions(+) create mode 100644 .github/workflows/BuildTest_win32.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/publish_container_image.yml create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 .taplo.toml create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 VERSION create mode 100755 ci/linux/build_python_package.sh create mode 100755 ci/linux/create_venv.sh create mode 100755 ci/linux/install_dependencies.sh create mode 100755 ci/linux/lint.sh create mode 100755 ci/linux/test_unit.sh create mode 100755 ci/linux/typecheck.sh create mode 100755 ci/linux/update_dependencies.sh create mode 100644 ci/win32/create_venv.cmd create mode 100644 ci/win32/install_dependencies.cmd create mode 100644 ci/win32/lint.cmd create mode 100644 ci/win32/test_unit.cmd create mode 100644 ci/win32/typecheck.cmd create mode 100644 ci/win32/update_dependencies.cmd create mode 100644 doc/dev_documentation/Makefile create mode 100644 doc/dev_documentation/Tools.rst create mode 100644 doc/dev_documentation/conf.py create mode 100644 doc/dev_documentation/index.rst create mode 100644 doc/dev_documentation/make.bat create mode 100644 doc/user_documentation/Makefile create mode 100644 doc/user_documentation/conf.py create mode 100644 doc/user_documentation/index.rst create mode 100644 doc/user_documentation/make.bat create mode 100644 pyproject.toml create mode 100644 run.sh create mode 100644 src/kpicalculator/__init__.py create mode 100644 src/kpicalculator/__main__.py create mode 100644 src/kpicalculator/app_logging.py create mode 100644 src/kpicalculator/kpicalculator.py create mode 100644 src/kpicalculator/py.typed create mode 100644 unit_test/test_main.py diff --git a/.github/workflows/BuildTest_win32.yml b/.github/workflows/BuildTest_win32.yml new file mode 100644 index 0000000..7ab15ab --- /dev/null +++ b/.github/workflows/BuildTest_win32.yml @@ -0,0 +1,33 @@ +name: Build-Test-Lint (win32) + +on: + pull_request: + types: [ opened, reopened, synchronize ] + +jobs: + build: + runs-on: windows-latest + strategy: + matrix: + python-version: ["3.11"] +# python-version: [3.8, 3.9, 3.10, 3.11] + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + - run: | + .\ci\win32\create_venv.cmd + .\ci\win32\install_dependencies.cmd + + - name: run unit tests + run: | + .\ci\win32\test_unit.cmd + + - name: Lint + run: | + .\ci\win32\lint.cmd diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6a5cdcf --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,112 @@ +name: Build-Test-Lint-etc (linux) + +on: [push] + +jobs: + + flake8-lint: + runs-on: ubuntu-latest + name: Lint + steps: + - name: Check out source repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Python environment + uses: actions/setup-python@v4 + with: + python-version: 3.11 + - name: flake8 Lint + uses: TrueBrain/actions-flake8@v2 + with: + plugins: Flake8-pyproject==1.2.3 flake8-docstrings==1.7.0 flake8-quotes==3.3.2 flake8-bugbear==23.9.16 flake8-mock==0.4 flake8-tuple==0.4.1 + # only_warn: 1 #causes action to always be succesful, but still provide annotations + + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.11"] +# python-version: [3.8, 3.9, 3.10, 3.11] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + - run: | + ./ci/linux/create_venv.sh + ./ci/linux/install_dependencies.sh + + - name: run unit tests + run: | + ./ci/linux/test_unit.sh + + - name: Surface failing tests + if: always() + uses: pmeier/pytest-results-action@main + with: + # A list of JUnit XML files, directories containing the former, and wildcard + # patterns to process. + # See @actions/glob for supported patterns. + path: test-results.xml + + # Add a summary of the results at the top of the report + # Default: true + summary: true + + # Select which results should be included in the report. + # Follows the same syntax as + # `pytest -r` + # Default: fEX + display-options: fEX + + # Fail the workflow if no JUnit XML was found. + # Default: true + fail-on-empty: true + + typecheck: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.11"] +# python-version: [3.8, 3.9, 3.10, 3.11] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + - run: | + ./ci/linux/create_venv.sh + ./ci/linux/install_dependencies.sh + + - name: Add mypy annotator + uses: pr-annotators/mypy-pr-annotator@v1.0.0 + + - name: run typechecker + run: | + ./ci/linux/typecheck.sh + + build: + name: Build the python package + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.11" ] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + - run: | + ./ci/linux/create_venv.sh + ./ci/linux/install_dependencies.sh + + - name: build + run: | + ./ci/linux/build_python_package.sh diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..1e74fca --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,72 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ main ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ main ] + schedule: + - cron: '22 6 * * 2' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'python' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://git.io/codeql-language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/publish_container_image.yml b/.github/workflows/publish_container_image.yml new file mode 100644 index 0000000..8a1a2bc --- /dev/null +++ b/.github/workflows/publish_container_image.yml @@ -0,0 +1,28 @@ +name: Deply to GitHub Container Registry +on: + push: + tags: + - v*.* + +jobs: + publish-container-image: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build the container image + run: | + docker build . --tag ghcr.io/n/omotes_kpi_calculator:latest --tag ghcr.io/n/omotes_kpi_calculator:${{github.ref_name}} + docker push ghcr.io/n/omotes_kpi_calculator:latest + docker push ghcr.io/n/omotes_kpi_calculator:${{github.ref_name}} + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e8e4974 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,39 @@ +name: PyPi release +run-name: Releasing next version 🚀 +on: + push: + tags: + - '*' + +jobs: + pypi-publish: + name: upload release to PyPI + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.11" ] + # Specifying a GitHub environment is optional, but strongly encouraged + environment: release + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + - run: | + ./ci/linux/create_venv.sh + ./ci/linux/update_dependencies.sh + ./ci/linux/install_dependencies.sh + + - name: build + run: | + ./ci/linux/build_python_package.sh + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85047aa --- /dev/null +++ b/.gitignore @@ -0,0 +1,224 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +doc/*/_build/ +doc/*/_static/ +doc/*/_templates/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +### PyCharm+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### PyCharm+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + +.idea/* + +!.idea/codeStyles +!.idea/runConfigurations + +unit_test_coverage/ +test-results.xml + +.env.* \ No newline at end of file diff --git a/.taplo.toml b/.taplo.toml new file mode 100644 index 0000000..66d8049 --- /dev/null +++ b/.taplo.toml @@ -0,0 +1,5 @@ +include = ["pyproject.toml"] + + +[schema] +path = "https://json.schemastore.org/pyproject.json" diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..742cb59 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + "recommendations": [ + "ms-python.python", + "ms-python.black-formatter", + "ms-python.flake8", + "ms-python.isort", + "matangover.mypy", + "lextudio.restructuredtext", + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6728f09 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,28 @@ +{ + "[python]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "ms-python.black-formatter", + "editor.codeActionsOnSave": { + "source.organizeImports": true + }, + }, + "python.analysis.typeCheckingMode": "basic", + "python.testing.unittestArgs": [ + "-v", + "-s", + "./unit_test", + "-p", + "test_*.py" + ], + "python.testing.pytestEnabled": true, + "python.testing.unittestEnabled": false, + "python.testing.autoTestDiscoverOnSaveEnabled": true, + "mypy.runUsingActiveInterpreter": true, + "isort.args": [ + "--profile", + "black" + ], + "terminal.integrated.env.windows": { + "PYTHONPATH": "${workspaceFolder}/src" + }, +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..149a75c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,32 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] - 2024-3-31 +### Added +- New functionality added to the project, with reference to issue-ticket (#123) +- Another new item (#1234) + +### Fixed +- bugfixes, with references to your issue-tickets (#123) +- another bugfix (#1234) + +### Changed +- Changes, for example code structure +- but also changed/updated dependencies +- Add references to tickets where applicable (#123) + +### Removed +- Files that have been removed +- Functionality that has been removed +- Add references to tickets where applicable (#123) + +## [0.0.1] - 2023-09-21 +### Added +- Kickoff of Nieuwe Warmte Nu!. +- initialized repo from template. + +### Changed +- everything. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..cf3607f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,51 @@ +# This file +This file should describe the development process for this project and include instruction on +how to run/build your project. Any environment settings/requirements? + +# Development guidelines +The general proces is as follows: +* Create a branch on your local working copy +* make code modifications, including tests, documentation, etc +* commit/push changes to remote/origin +* submit a pull request for merging into master +* Discuss with code reviewer if/what changes are needed +* when all discussions are resolved, the PR will be merged by the reviewer +* Update Changelog! + + +# Code Quality guide lines +Quality guide lines serve to improve quality. They should not be busy work nor work against developers. +They should be of value. + +## Code review +- Every commit should be created on its own branch and submitted per pull request to be merged with the main branch. +- Every pull request must be reviewed by at least one other developer and all comments must be resolved. +- No linting issues may remain before merging. +- No type checking issues may remain before merging. +- Code reviews are not about distrust. They are about sharing knowledge about the code base, sharing knowledge about + writing code and increasing quality by collaboration. + +## Documentation +- Every function must have documentation explaining what the function does in a summary and explaining + each argument and return type. + +## Linting +- Linting maintains a shared quality of the code base across repositories. +- Rules of the linter may only be ignored when approved by the software leads. Prefer to silence individual lines by ' + +## Type checking +- Every function must have a return type and an argument list annotated with functions. +- Rules of the type checker may only be ignored when approved by the software leads. +- + +## Testing +### Unit testing +- Every function should be covered by a unit test. Some functions allow more easily for unit tests and some are not + worth unit testing. This is up to the teams discretion. +- A unit test should test some significant amount of code. If the test function is similar or equal to the logic being tested, +the amount of code being tested is too small. If the test function tests whole modules or multiple layers of code, the amount +of code being tested is too big. The amount of code being tested is referred to as the 'unit-under-test'. +- Use mocks to isolate 'unit-under-test' where applicable. +- Coverage percentage should be >80%. This is a guideline, not a hard rule. Breaking this guideline is allowed if the + arguments has swayed the developersteam and not just the developer and reviewer. + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8a93d08 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.11-bookworm + +WORKDIR /app + +COPY ./requirements.txt . + +RUN pip install -r requirements.txt + +COPY . . + +ENTRYPOINT ./run.sh \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..1200ec0 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# KPI Calculator + +This repository is part of the 'Nieuwe Warmte Nu Design Toolkit' project. + +Extend ESDL's with relevant key performance indicators. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..8a9ecc2 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.1 \ No newline at end of file diff --git a/ci/linux/build_python_package.sh b/ci/linux/build_python_package.sh new file mode 100755 index 0000000..5f4244f --- /dev/null +++ b/ci/linux/build_python_package.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +. .venv/bin/activate +python -m build diff --git a/ci/linux/create_venv.sh b/ci/linux/create_venv.sh new file mode 100755 index 0000000..b6345ed --- /dev/null +++ b/ci/linux/create_venv.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +python3.11 -m venv ./.venv +. .venv/bin/activate +pip3 install pip-tools diff --git a/ci/linux/install_dependencies.sh b/ci/linux/install_dependencies.sh new file mode 100755 index 0000000..0447bed --- /dev/null +++ b/ci/linux/install_dependencies.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +. .venv/bin/activate +pip-sync ./dev-requirements.txt ./requirements.txt diff --git a/ci/linux/lint.sh b/ci/linux/lint.sh new file mode 100755 index 0000000..c359ba1 --- /dev/null +++ b/ci/linux/lint.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +. .venv/bin/activate +flake8 ./src/kpicalculator diff --git a/ci/linux/test_unit.sh b/ci/linux/test_unit.sh new file mode 100755 index 0000000..b810a25 --- /dev/null +++ b/ci/linux/test_unit.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +. .venv/bin/activate +PYTHONPATH='$PYTHONPATH:src/' pytest --junit-xml=test-results.xml unit_test/ diff --git a/ci/linux/typecheck.sh b/ci/linux/typecheck.sh new file mode 100755 index 0000000..ec43d83 --- /dev/null +++ b/ci/linux/typecheck.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +. .venv/bin/activate +python -m mypy ./src/kpicalculator ./unit_test/ diff --git a/ci/linux/update_dependencies.sh b/ci/linux/update_dependencies.sh new file mode 100755 index 0000000..cfb00aa --- /dev/null +++ b/ci/linux/update_dependencies.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +. .venv/bin/activate +pip-compile --output-file=requirements.txt pyproject.toml +pip-compile --extra=dev --output-file=dev-requirements.txt -c requirements.txt pyproject.toml diff --git a/ci/win32/create_venv.cmd b/ci/win32/create_venv.cmd new file mode 100644 index 0000000..edb05f0 --- /dev/null +++ b/ci/win32/create_venv.cmd @@ -0,0 +1,9 @@ +rem Short script to initialize virtual environment using venv and pip +rem @echo off + +pushd . +cd /D "%~dp0" +py -3.11 -m venv ..\..\venv +call ..\..\venv\Scripts\activate.bat +python -m pip install pip-tools +popd diff --git a/ci/win32/install_dependencies.cmd b/ci/win32/install_dependencies.cmd new file mode 100644 index 0000000..e76c29d --- /dev/null +++ b/ci/win32/install_dependencies.cmd @@ -0,0 +1,6 @@ + +pushd . +cd /D "%~dp0" +cd ..\..\ +pip-sync .\dev-requirements.txt .\requirements.txt +popd \ No newline at end of file diff --git a/ci/win32/lint.cmd b/ci/win32/lint.cmd new file mode 100644 index 0000000..a15fdf4 --- /dev/null +++ b/ci/win32/lint.cmd @@ -0,0 +1,8 @@ +rem Short script to run linting +rem @echo off + +pushd . +cd /D "%~dp0" +cd ..\..\ +flake8 .\src\kpicalculator +popd diff --git a/ci/win32/test_unit.cmd b/ci/win32/test_unit.cmd new file mode 100644 index 0000000..c2d51b8 --- /dev/null +++ b/ci/win32/test_unit.cmd @@ -0,0 +1,9 @@ + +pushd . +cd /D "%~dp0" + +cd ..\..\ +call .\venv\Scripts\activate +set PYTHONPATH=.\src\;%$PYTHONPATH% +pytest unit_test/ +popd \ No newline at end of file diff --git a/ci/win32/typecheck.cmd b/ci/win32/typecheck.cmd new file mode 100644 index 0000000..6e49c27 --- /dev/null +++ b/ci/win32/typecheck.cmd @@ -0,0 +1,8 @@ +REM script to run mypy type checker on this source tree. +pushd . +cd /D "%~dp0" +cd ..\..\ +call .\venv\Scripts\activate +set PYTHONPATH=.\src\kpicalculator;%$PYTHONPATH% +python -m mypy ./src/kpicalculator ./unit_test/ +popd \ No newline at end of file diff --git a/ci/win32/update_dependencies.cmd b/ci/win32/update_dependencies.cmd new file mode 100644 index 0000000..061ee6d --- /dev/null +++ b/ci/win32/update_dependencies.cmd @@ -0,0 +1,6 @@ + +pushd . +cd /D "%~dp0" +pip-compile --output-file=..\..\requirements.txt ..\..\pyproject.toml +pip-compile --extra=dev --output-file=..\..\dev-requirements.txt -c ..\..\requirements.txt ..\..\pyproject.toml +popd \ No newline at end of file diff --git a/doc/dev_documentation/Makefile b/doc/dev_documentation/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/doc/dev_documentation/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/doc/dev_documentation/Tools.rst b/doc/dev_documentation/Tools.rst new file mode 100644 index 0000000..2f4653f --- /dev/null +++ b/doc/dev_documentation/Tools.rst @@ -0,0 +1,60 @@ +Tools & IDE's +=================================================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + +There are numerous IDE's for developing python applications, but we +will focus on two: Visual Studio Code and PyCharm + +General +------- +Python code can be writtin using any text editor. However, we've chosen the following tools to support us: + +- **Black** for code formatting +- **Flake8** for code linting +- **MyPy** for typehints/typeChecking +- **pytest** for unit testing +- + +PyCharm +------- + + + + + +VS Code +------- + +The following extensions should be installed: + +* https://marketplace.visualstudio.com/items?itemName=ms-python.python +* https://marketplace.visualstudio.com/items?itemName=ms-python.flake8 +* https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter +* https://marketplace.visualstudio.com/items?itemName=matangover.mypy + +settings.json for vscode: + +.. code-block:: JSON + + { + "python.analysis.typeCheckingMode": "basic", + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + }, + "python.formatting.provider": "black", + "mypy.runUsingActiveInterpreter": true, + } + + + + +Indices and tables +------------------ + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/doc/dev_documentation/conf.py b/doc/dev_documentation/conf.py new file mode 100644 index 0000000..6cec812 --- /dev/null +++ b/doc/dev_documentation/conf.py @@ -0,0 +1,57 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = 'Nieuwe Warmte Nu! python user documentation' +copyright = '2023, NieuweWarmteNu Design Toolkit' +author = 'Jesús Andrés Rodríguez Sarasty' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.autosummary", + "sphinx.ext.napoleon", + "sphinx_copybutton", +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = "furo" + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] diff --git a/doc/dev_documentation/index.rst b/doc/dev_documentation/index.rst new file mode 100644 index 0000000..77be81e --- /dev/null +++ b/doc/dev_documentation/index.rst @@ -0,0 +1,24 @@ +.. Deltares python Developer documentation documentation master file, created by + sphinx-quickstart on Fri Apr 21 15:13:59 2023. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to Design Toolkit python Developer documentation's documentation! +=================================================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + Tools + +This is the developer documentation for this project. This documentation provides +information on tools, configurations and howto's for developers. + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/doc/dev_documentation/make.bat b/doc/dev_documentation/make.bat new file mode 100644 index 0000000..954237b --- /dev/null +++ b/doc/dev_documentation/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/doc/user_documentation/Makefile b/doc/user_documentation/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/doc/user_documentation/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/doc/user_documentation/conf.py b/doc/user_documentation/conf.py new file mode 100644 index 0000000..db818d0 --- /dev/null +++ b/doc/user_documentation/conf.py @@ -0,0 +1,52 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = 'Nieuwe Warmte Nu! python user documentation' +copyright = '2023, NieuweWarmteNu Design Toolkit' +author = 'Jesús Andrés Rodríguez Sarasty' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] \ No newline at end of file diff --git a/doc/user_documentation/index.rst b/doc/user_documentation/index.rst new file mode 100644 index 0000000..097493f --- /dev/null +++ b/doc/user_documentation/index.rst @@ -0,0 +1,20 @@ +.. Deltares python user documentation documentation master file, created by + sphinx-quickstart on Fri Apr 21 15:13:29 2023. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to Design Toolkit python user documentation's documentation! +============================================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/doc/user_documentation/make.bat b/doc/user_documentation/make.bat new file mode 100644 index 0000000..954237b --- /dev/null +++ b/doc/user_documentation/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..cdd030c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,102 @@ +[project] +name = "kpi-calculator" +dynamic = ["version"] +authors = [ + { name = "Jesús Andrés Rodríguez Sarasty", email = "jesusandres.rodriguez@deltares.nl" }, +] +description = "Extend ESDL's with relevant key performance indicators." +readme = "README.md" +classifiers = [ + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.11", + "Operating System :: OS Independent", + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "Intended Audience :: Information Technology", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Mathematics", + "Topic :: Scientific/Engineering :: Physics", +] + +dependencies = ["coloredlogs~=15.0.1"] + +[project.optional-dependencies] +dev = [ + "setuptools ~= 69.0.3", + "wheel ~= 0.40.0", + "setuptools-git-versioning < 2", + "black~=22.1.0", + "flake8==6.0.0", + "Flake8-pyproject==1.2.3", + "pytest ~=7.3.1", + "pytest-cov ~=4.0.0", + "bump2version==1.0.1", + "mypy ~= 1.5.1", + "isort==5.13.2", + "build ~= 1.0.3", +] + +[project.urls] +homepage = "https://www.nwn.nu" +documentation = "https://readthedocs.org" +repository = "https://github.com/Nieuwe-Warmte-Nu/kpi-calculator" +changelog = "https://github.com/Nieuwe-Warmte-Nu/kpi-calculator/blob/main/CHANGELOG.md" + +[project.scripts] +kpicalculator = "kpicalculator:main" + +[build-system] +build-backend = "setuptools.build_meta" +requires = [ + "setuptools ~= 69.0.3", + "wheel ~= 0.40.0", + "setuptools-git-versioning<2", +] + +[tool.setuptools-git-versioning] +enabled = true +version_file = "VERSION" +count_commits_from_version_file = true +dev_template = "{tag}.dev{ccount}" +dirty_template = "{tag}.dev{ccount}" + +[tool.pytest.ini_options] +addopts = "--cov=kpicalculator --cov-report html --cov-report term-missing --cov-fail-under 80" +testpaths = ["unit_test"] + +[tool.coverage.run] +source = ["src"] + +[tool.flake8] +exclude = ['.venv/*', 'venv/*', 'doc/*'] +ignore = [ + 'Q000', # Remove bad quotes + 'D401', # Docstring First line should be imperative + 'E203', # Space before colon (not PEP-8 compliant, and conflicts with black) + 'C408', # Suggestion to use dict() over {} + 'W503', # Starting lines with operators. +] +per-file-ignores = ['__init__.py:F401', 'test_main.py:D100,D101,D102,D103'] +max-line-length = 100 +count = true + +[tool.black] +line-length = 100 + +[tool.isort] +profile = "black" + +[tool.mypy] +python_version = "3.11" +warn_return_any = true +warn_unused_configs = true +disallow_untyped_defs = true +disallow_incomplete_defs = true +exclude = ['.venv/*', 'venv/*', 'doc/*', 'ci/*'] + +# mypy per-module options: +[[tool.mypy.overrides]] +module = ["unit_test.*", "coloredlogs.*"] +check_untyped_defs = true +ignore_missing_imports = true diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..5af2ee5 --- /dev/null +++ b/run.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +. .venv/bin/activate +cd src/ +python -m kpicalculator diff --git a/src/kpicalculator/__init__.py b/src/kpicalculator/__init__.py new file mode 100644 index 0000000..65189aa --- /dev/null +++ b/src/kpicalculator/__init__.py @@ -0,0 +1,17 @@ +# Copyright (c) 2024 Deltares / TNO. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +"""__init__.py file containing the defaults.""" +from kpicalculator.kpicalculator import start_app \ No newline at end of file diff --git a/src/kpicalculator/__main__.py b/src/kpicalculator/__main__.py new file mode 100644 index 0000000..c7db0b8 --- /dev/null +++ b/src/kpicalculator/__main__.py @@ -0,0 +1,19 @@ +# Copyright (c) 2024 Deltares / TNO. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +"""__main__.py file for testing/running application.""" +from kpicalculator import start_app + +start_app(loglevel="DEBUG", colors=True) \ No newline at end of file diff --git a/src/kpicalculator/app_logging.py b/src/kpicalculator/app_logging.py new file mode 100644 index 0000000..828a276 --- /dev/null +++ b/src/kpicalculator/app_logging.py @@ -0,0 +1,90 @@ +# Copyright (c) 2024 Deltares / TNO. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +"""Setup logging for this python application.""" + +import logging +import sys +from enum import Enum + +import coloredlogs + + +class LogLevel(Enum): + """Loglevel enum.""" + + DEBUG = logging.DEBUG + INFO = logging.INFO + WARNING = logging.WARNING + ERROR = logging.ERROR + + @staticmethod + def parse(value: str) -> "LogLevel": + """ + Parses a given string for LogLevel's. + + Parameters + ---------- + value : str + user provided string containing the requested log level + + Returns + ------- + LogLevel + Loglevel for this logger + """ + lowered = value.lower() + + if lowered == "debug": + result = LogLevel.DEBUG + elif lowered == "info": + result = LogLevel.INFO + elif lowered in ["warning", "warn"]: + result = LogLevel.WARNING + elif lowered in ["err", "error"]: + result = LogLevel.ERROR + else: + raise ValueError(f"Value {value} is not a valid log level.") + + return result + + +LOG_LEVEL: LogLevel | None = None + + +def setup_logging(log_level: LogLevel, colors: bool = True) -> None: + """ + Initializes logging. + + Parameters + ---------- + log_level : LogLevel + The LogLevel for this logger. + """ + global LOG_LEVEL + root_logger = logging.getLogger() + root_logger.info("Will use log level:", str(log_level)) + root_logger.setLevel(log_level.value) + LOG_LEVEL = log_level + if colors: + coloredlogs.install(log_level.value, logger=root_logger) + else: + log_handler = logging.StreamHandler(sys.stdout) + formatter = logging.Formatter( + fmt="%(asctime)s [%(threadName)s][%(filename)s:%(lineno)d][%(levelname)s]: %(message)s" + ) + log_handler.setFormatter(formatter) + root_logger.addHandler(log_handler) + pass diff --git a/src/kpicalculator/kpicalculator.py b/src/kpicalculator/kpicalculator.py new file mode 100644 index 0000000..9b9bcf0 --- /dev/null +++ b/src/kpicalculator/kpicalculator.py @@ -0,0 +1,44 @@ +# Copyright (c) 2024 Deltares / TNO. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +"""Main python file for KPI Calculator.""" +from datetime import datetime, timedelta +from kpicalculator.app_logging import setup_logging, LogLevel +import logging +import traceback + +logger = logging.getLogger(__name__) + + +def testable_function(input: datetime) -> datetime: + """Testable function.""" + return input + + timedelta(hours=1) + + +def start_app(loglevel: str, colors: bool) -> None: + """KPI Calculator application.""" + setup_logging(LogLevel.parse(loglevel), colors) + try: + logger.info(f"The time + 1 hour is: {testable_function(datetime.now())}") + + # TODO insert your code here + + except Exception as error: + logger.error(f"Error occured: {error} at: {traceback.format_exc(limit=-1)}") + logger.debug(traceback.format_exc()) + + +if __name__ == '__main__': + start_app(loglevel="DEBUG", colors=True) diff --git a/src/kpicalculator/py.typed b/src/kpicalculator/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/unit_test/test_main.py b/unit_test/test_main.py new file mode 100644 index 0000000..194c1c7 --- /dev/null +++ b/unit_test/test_main.py @@ -0,0 +1,56 @@ +# Copyright (c) 2023. {cookiecutter.cookiecutter.maintainer_name}} +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +"""Test script for python template.""" +from datetime import datetime +import unittest +from kpicalculator import kpicalculator + + +class MyTest(unittest.TestCase): + def tearDown(self) -> None: + import logging + from importlib import reload + + logging.shutdown() + reload(logging) + return super().tearDown() + + def test__testable_function__is_correct(self) -> None: + # Arrange + current_time = datetime(1970, 1, 1, 13, 00) + + # Act + result = simulator_worker.testable_function(current_time) + + # Assert + expected_result = datetime(1970, 1, 1, 14, 00) + self.assertEqual(expected_result, result) + + def test_start_app_info(self) -> None: + try: + simulator_worker.start_app(loglevel="INFO", colors=True) + except Exception as e: + self.fail(f"simulator_worker.start_app() raised an exception: {e}") + + def test_start_app_debug(self) -> None: + try: + simulator_worker.start_app(loglevel="DEBUG", colors=False) + except Exception as e: + self.fail(f"simulator_worker.start_app() raised an exception: {e}") + + def test_start_app_wrong_logtype(self) -> None: + with self.assertRaises(ValueError): + simulator_worker.start_app(loglevel="WRONG_LOG_TYPE", colors=False)