Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve coding style #5

Merged
merged 19 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[flake8]
# Use less conservative limit for max. line length, we all have wider screens today.
max-line-length = 127
max-complexity = 15
# E741 - allow ambiguous variable names such as 'l'.
# W503 - line breaks should occur before the binary operator (this will become best-practise in the furture)
ignore = E741, W503

# Exclude some directories
exclude =
./virtualenv

# Deactivate too-complex warning(s)
per-file-ignores =
./loadskernel/trim_conditions.py:C901
./loadskernel/solution_sequences.py:C901
./loadskernel/plotting_extra.py:C901
./doc/jcl_template.py:E261

59 changes: 59 additions & 0 deletions .github/workflows/coding-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This workflow will install and then lint the code with Flake8 and Pylint.
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Coding style

on:
push:
branches: ['master', 'devel']
pull_request:
branches: '*'

permissions:
contents: read

jobs:
Flake8:
runs-on: ubuntu-latest
strategy:
matrix:
# Add multiple Python versions here to run tests on new(er) versions.
python-version: ["3.8"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# The GitHub editor is 127 chars wide
flake8 . --count --statistics

Pylint:
runs-on: ubuntu-latest
strategy:
matrix:
# Add multiple Python versions here to run tests on new(er) versions.
python-version: ["3.8"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
# Install the package itself to make sure that all imports work.
pip install .
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py') --fail-under=7.0
93 changes: 93 additions & 0 deletions .github/workflows/regression-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# This workflow will install and then lint the code with Flake8 and Pylint.
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Regression Tests

on:
push:
branches: ['master', 'devel']
pull_request:
branches: '*'

jobs:
pip-installation:
# This stage only tests if the installation is possible.
# The evironment created herein will be discared and re-created in the test stage.
runs-on: ubuntu-latest
strategy:
matrix:
# Add multiple Python versions here to run tests on new(er) versions.
python-version: ["3.8"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Build and install
run: |
python -m pip install --upgrade pip
# Install with -e (in editable mode) to allow the tracking of the test coverage
pip install -e .
# Check result of installation
which loads-kernel
which model-viewer
which loads-compare

Jupyter:
runs-on: ubuntu-latest
strategy:
matrix:
# Add multiple Python versions here to run tests on new(er) versions.
python-version: ["3.8"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install jupyter-book
pip install .
- name: Assemble the tutorials to a jupyter book and build htlm pages
run: |
jupyter-book build ./doc/tutorials
# Put the html into a 2nd-level sub-folder and use 1st-level subfolder for uploading
mkdir ./doc/html
mv ./doc/tutorials/_build/html ./doc/html/tutorials
- name: Upload Jupyter book as an artifact
uses: actions/upload-artifact@v3
with:
name: tutorials
path: ./doc/html
if-no-files-found: ignore
- name: Upload Jupyter book for pages
# This is not a normal artifact but one that can be deployed to the GitHub pages in the next step
uses: actions/upload-pages-artifact@v3
with:
name: github-pages # This name may not be changed according to the documentation
path: ./doc/html
if-no-files-found: ignore

deploy-pages:
# Add a dependency to the build job
needs: Jupyter

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source

# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Setup GitHub Pages
uses: actions/configure-pages@v4
- name: Deploy to Pages
id: deployment
uses: actions/deploy-pages@v4
54 changes: 43 additions & 11 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ stages:
# Check location
- pwd

build:
pip-installation:
# This stage only tests if the installation is possible.
# The evironment created herein will be discared and re-created in the test stage.
stage: build
Expand All @@ -36,26 +36,58 @@ build:
# Check result of installation
- which loads-kernel
- which model-viewer
- which loads-compare
- which loads-compare

test:
Jupyter:
stage: build
tags:
- lk
script:
- *virtualenv
# Assemble the tutorials to a jupyter book and build htlm pages
- jupyter-book build ./doc/tutorials
artifacts:
when: always
paths:
- ./doc/tutorials

Flake8:
stage: test
tags:
- lk
script:
- *virtualenv
- pip install flake8
# stop the build if there are Python syntax errors or undefined names
- flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# Lint with flake8
- flake8 . --count --statistics

Pylint:
stage: test
tags:
- lk
script:
- *virtualenv
- pip install pylint
# Install the package itself to make sure that all imports work.
- pip install .
# Analyse the code with pylint
- pylint $(git ls-files '*.py') --fail-under=7.0

Pytest:
stage: test
timeout: 3 hours
coverage: '/^TOTAL.+?(\d+\%)$/'
tags:
- lk
dependencies:
- build
script:
# Set-up the environement
- *virtualenv
# Install with -e (in editable mode) to allow the tracking of the test coverage
- pip install -e .
- which loads-kernel
# Get the examples repository
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.dlr.de/loads-kernel/loads-kernel-examples.git
# Assemble the tutorials to a jupyter book and build htlm pages
- jupyter-book build ./doc/tutorials
# Run the actual testing of the code with pytest
- pytest -v --basetemp=./test_tmp --cov=loadskernel --cov=modelviewer --cov=loadscompare --junitxml=testresult.xml
# Create some reports
Expand All @@ -68,19 +100,19 @@ test:
- coverage.xml
- testresult.xml
- coverage
- ./doc/tutorials
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
junit: testresult.xml

pages:
deploy-pages:
stage: deploy
tags:
- lk
dependencies:
- test
- Jupyter
- Pytest
script:
- mkdir public
# Publish the coverage htlm results
Expand Down
9 changes: 9 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[MESSAGES CONTROL]
# Disable the message, report, category or checker with the given id(s).
# C0103 - doesn't conform to snake_case naming style
# C0114/5/6 - Missing docstring
# W0105 - pointless-string-statement, disable it if you're using those strings as documentation, instead of comments.
disable=C0103,C0114,C0115,C0116,W0105

# Set same max. line length as with Flake8
max-line-length=127
19 changes: 10 additions & 9 deletions doc/efcs_template.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
'''
This is a template for an EFCS. For each aircraft, an EFCS must be written which maps the pilot
commands to control surface deflections Ux2. This is because every aircraft has different control
surfaces (e.g. one or two elevators, multiple ailerons, etc.)
This is a template for an EFCS. For each aircraft, an EFCS must be written which maps the pilot
commands to control surface deflections Ux2. This is because every aircraft has different control
surfaces (e.g. one or two elevators, multiple ailerons, etc.)
'''
import numpy as np

class Efcs:

class Efcs():

def __init__(self):
self.keys = ['dummy']
self.Ux2 = np.array([0.0])

def cs_mapping(self, commands):
"""
Do nothing in particular, this is just a dummy EFCS.
command_xi = commands[0]
command_xi = commands[0]
command_eta = commands[1]
command_zeta = commands[2]
...
"""


return self.Ux2

return self.Ux2
Loading
Loading