Skip to content

Commit

Permalink
Merge pull request #197 from timryanb/ci-linting
Browse files Browse the repository at this point in the history
Adding isort, black, and flake8 to GH workflows
  • Loading branch information
timryanb authored Jan 15, 2025
2 parents 3e74f72 + 3b935a1 commit e69610b
Show file tree
Hide file tree
Showing 129 changed files with 7,297 additions and 4,512 deletions.
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# black, isort, flake8 formatting (#197)
bab9331b0f7ade5aca6e7e7c1aba9ff80d879358
8eb21b68d574f810c3aee380611a3f71552c9d8b
537bc991ace0ecf662cd0f8632605f49ef2164c1
15 changes: 15 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: black

on:
push:
branches: [ master ]
pull_request:

jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
version: "~= 22.0"
23 changes: 23 additions & 0 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: flake8

on:
push:
branches: [ master ]
pull_request:
jobs:
# --- code style check by flake8 ---
flake8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: '3.8'

# use both MDO Lab standard config
- name: Code style (flake8)
run: |
pip install flake8
wget https://raw.githubusercontent.com/mdolab/.github/master/.flake8 -O .flake8_mdolab
python -m flake8 mphys --append-config .flake8_mdolab --count --show-source --statistics
15 changes: 15 additions & 0 deletions .github/workflows/isort.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Run isort
on:
push:
branches: [ master ]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: isort/isort-action@master
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<img src="docs/logo/mphys_logo_no_background.png" alt= “MPhys” width="250">

[![Unit Tests and Docs](https://github.com/OpenMDAO/mphys/actions/workflows/unit_tests_and_docs.yml/badge.svg)](https://github.com/OpenMDAO/mphys/actions/workflows/unit_tests_and_docs.yml)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)

MPhys is a package that standardizes high-fidelity multiphysics problems in OpenMDAO.
MPhys eases the problem set up, provides straightforward extension to new disciplines, and has a library of OpenMDAO groups for multidisciplinary problems addressed by its standard.
Expand Down Expand Up @@ -86,6 +88,18 @@ to run the tests execute in the root directory
testflo -v tests
```

## Code Formatting
All pull requests automatically check for code formatting compliance using `flake8`, `black`, and `isort`.
Before submitting a PR check code changes adheres to this formating.
To run `flake8`, `black`, and `isort` locally, use the folowing commands:
```commandline
$ pip install flake8 black isort
$ wget https://raw.githubusercontent.com/mdolab/.github/main/.flake8 -O .flake8_mdolab # download flake8 configuration for mdolab
$ python -m flake8 . --append-config .flake8_mdolab --count --show-source --statistics
$ python -m black . --check --diff
$ python -m isort . --check-only --diff
```

# Software Assurance Plan

MPhys has been deemed as Class-E software, according to the [7120.5D Specification](https://www.nasa.gov/pdf/423715main_NPR_7120-5_HB_FINAL-02-25-10.pdf).
Expand Down
19 changes: 9 additions & 10 deletions docs/_exts/embed_bibtex.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@

import sys
import importlib

from docutils import nodes
import sys

import sphinx
from docutils import nodes
from docutils.parsers.rst import Directive

from sphinx.errors import SphinxError
from sphinx.writers.html import HTMLTranslator
from sphinx.writers.html5 import HTML5Translator
from sphinx.errors import SphinxError


class bibtex_node(nodes.Element):
Expand All @@ -32,7 +29,9 @@ def depart_bibtex_node(self, node):
html = """
<div class="cell border-box-sizing code_cell rendered">
<div class="output_area"><pre>{}</pre></div>
</div>""".format(node["text"])
</div>""".format(
node["text"]
)

self.body.append(html)

Expand Down Expand Up @@ -62,15 +61,15 @@ def run(self):
mod = importlib.import_module(module_path)
obj = getattr(mod, class_name)()

if not hasattr(obj, 'cite') or not obj.cite:
if not hasattr(obj, "cite") or not obj.cite:
raise SphinxError("Couldn't find 'cite' in class '%s'" % class_name)

return [bibtex_node(text=obj.cite)]


def setup(app):
"""add custom directive into Sphinx so that it is found during document parsing"""
app.add_directive('embed-bibtex', EmbedBibtexDirective)
app.add_directive("embed-bibtex", EmbedBibtexDirective)
app.add_node(bibtex_node, html=(visit_bibtex_node, depart_bibtex_node))

return {'version': sphinx.__display_version__, 'parallel_read_safe': True}
return {"version": sphinx.__display_version__, "parallel_read_safe": True}
Loading

0 comments on commit e69610b

Please sign in to comment.