Skip to content

Commit

Permalink
Cleanups (#30)
Browse files Browse the repository at this point in the history
Okay, this PR got a bit larger than anticipated.
But there were just too many small things which I want to cleanup:

- General code-style:
  - Formatting via [black](https://github.com/psf/black)
- PEP-8 compliance via
[flake8](https://flake8.pycqa.org/en/3.1.1/index.html)
  - Fix a bunch of  code-smells detected by Sonar Cloud
- Improve code-quality
  - Remove `print()` and replace by `logging` module
- Replace `.format()`-style string formatting by printf-style for
logging module
- Revamp CI pipelines:
- I removed the in-repo CI action for building the documentation and
converted it to a normal workflow
    - This allowed removing a lot of stuff:
      - Dockerfile
      - docu.sh
      - action.yaml
      - entrypoint.sh
    - Removal of GitLab CI config
- The documentation is now also build in PR pipelines, but just not
deployed.
- Migrate to more modern Python packaging practices:
  - `setup.py` has been replace by `pyproject.toml`
- Check code-style, formatting and more with
[pre-commit](https://pre-commit.com/)
  - Will also be enforced by CI workflow
  • Loading branch information
m-mirz authored Jun 19, 2024
2 parents b49972e + 5eb9238 commit d23596b
Show file tree
Hide file tree
Showing 56 changed files with 931 additions and 818 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 120
61 changes: 61 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Documentation

on:
pull_request:

push:
branches:
- master

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.8

- name: Install Graphviz
shell: bash
run: |
sudo apt-get -y install graphviz
- name: Install Python dependencies
run: |
pip install .[doc]
- name: Build documentation
working-directory: documentation
run: |
sphinx-apidoc \
--full \
--doc-project "cimpy" \
--separate \
--output-dir "." \
"../"
python3 set_inheritance_diagram.py
make html
touch _build/html/.nojekyll
ls -l _build/html
- name: Upload Artifact
uses: actions/upload-pages-artifact@v3
with:
path: documentation/_build/html

- name: Deploy to GitHub Pages
if: github.ref == 'refs/heads/master'
uses: actions/deploy-pages@v4
14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/[email protected]
38 changes: 0 additions & 38 deletions .github/workflows/pytest.yaml

This file was deleted.

40 changes: 40 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Pytest

on:
push:
branches:
- master
pull_request:

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: 3.8

- name: Install Graphviz
shell: bash
run: |
sudo apt-get -y install graphviz
- name: Install Python dependencies
run: |
pip install .[dev]
- name: Run pytest
run: |
pytest -v -cov --junitxml=report.xml
- name: Upload pytest test results
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: pytest-results
path: cimpy/report.xml
35 changes: 0 additions & 35 deletions .github/workflows/workflow.yaml

This file was deleted.

9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# python folders
# Python folders
*.egg-info/
__pycache__
.idea
.venv
./cimpy/__pycache__
*.egg
build/
dist/

# log files
*.log

# vs code
# VSCode
.vscode/*

# documentation
# documentation/
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
exclude: ^cimpy/cgmes_

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
hooks:
- id: flake8
32 changes: 0 additions & 32 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
recursive-include cimpy/examples *.xml *.py
recursive-include cimpy *.mustache
recursive-include cimpy *.mustache
7 changes: 0 additions & 7 deletions action.yaml

This file was deleted.

6 changes: 4 additions & 2 deletions cimpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# flake8: noqa

from cimpy.cimexport import cim_export
from cimpy.cimimport import cim_import
import cimpy.utils
from cimpy.cimexamples import import_example
from cimpy.cimexamples import export_example
from cimpy.cimexamples import addExternalNetworkInjection_example
from cimpy.cimexamples import convertToBusBranch_example
from cimpy.cimexamples import add_external_network_injection_example
from cimpy.cimexamples import convert_to_bus_branch_example
24 changes: 10 additions & 14 deletions cimpy/cimexamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,28 @@


def import_example():
"""TODO: Add documentation
"""
"""TODO: Add documentation"""
base = Path(__file__).resolve().parent
example = base / 'examples' / 'importCIGREMV.py'
example = base / "examples" / "import_cigre_mv.py"
exec(open(example).read())


def export_example():
"""TODO: Add documentation
"""
"""TODO: Add documentation"""
base = Path(__file__).resolve().parent
example = base / 'examples' / 'exportCIGREMV.py'
example = base / "examples" / "export_cigre_mv.py"
exec(open(example).read())


def convertToBusBranch_example():
"""TODO: Add documentation
"""
def convert_to_bus_branch_example():
"""TODO: Add documentation"""
base = Path(__file__).resolve().parent
example = base / 'examples' / 'convertToBusBranch.py'
example = base / "examples" / "convert_to_bus_branch.py"
exec(open(example).read())


def addExternalNetworkInjection_example():
"""TODO: Add documentation
"""
def add_external_network_injection_example():
"""TODO: Add documentation"""
base = Path(__file__).resolve().parent
example = base / 'examples' / 'addExternalNetworkInjection.py'
example = base / "examples" / "add_external_network_injection.py"
exec(open(example).read())
Loading

0 comments on commit d23596b

Please sign in to comment.