Skip to content

Commit

Permalink
Updating to Read-the-docs and Codecov (#376)
Browse files Browse the repository at this point in the history
Co-authored-by: lamkina <lamkin@umich.edu>
  • Loading branch information
lamkina and lamkina authored Feb 4, 2022
1 parent e2e3c84 commit 95d0a0f
Show file tree
Hide file tree
Showing 32 changed files with 498 additions and 418 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
omit =
*/openaerostruct/utils/plot_wing.py
*/openaerostruct/utils/plot_wingbox.py
*/tests/*
*/docs/*
exclude_lines =
pragma: no cover
60 changes: 8 additions & 52 deletions .github/workflows/oas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ jobs:
run: |
python -m pip install --upgrade pip wheel
pip install .[test]
pip install coverage coveralls # for coveralls
# we need pySpline/pyGeo to run FFD tests.
- name: Install pySpline and pyGeo
run: |
cd ..
sudo apt-get install openmpi-bin libopenmpi-dev
pip install mpi4py
git clone https://github.com/mdolab/pyspline.git
Expand All @@ -40,22 +40,19 @@ jobs:
make
pip install -e .
cd ..
git clone https://github.com/mdolab/pygeo.git
pip install -e ./pygeo
pip install "pygeo[testing] @ git+https://github.com/mdolab/pygeo.git"
- name: Run tests
env:
OMPI_MCA_btl: ^openib # prevent OpenMPI warning messages
run: |
cd openaerostruct
testflo -n 2 openaerostruct --coverage --coverpkg openaerostruct --cover-omit \*tests/\* --cover-omit \*docs/\*
python -m pytest --cov-config=.coveragerc --cov=openaerostruct --cov-report=xml
- name: Run coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd openaerostruct
coveralls --service=github --rcfile=../.coveragerc;
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}

# --- code style check by flake8 ---
flake8:
Expand Down Expand Up @@ -91,44 +88,3 @@ jobs:
run: |
pip install black==21.6b0
black openaerostruct --check --diff -l 120 --target-version py38
# --- documentation build ---
docs-build:
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'

# build docs
- name: Build docs
run: |
python -m pip install --upgrade pip wheel
pip install .[docs]
cd openaerostruct/docs
make clean
make html
# deploy docs only when we're pushing to the master branch.
- name: Commit doc changes
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
run: |
git clone https://github.com/mdolab/OpenAeroStruct.git --branch gh-pages --single-branch gh-pages
cp -r ./openaerostruct/docs/_build/html/* gh-pages/
cd gh-pages
touch .nojekyll
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "Update documentation" -a || true
- name: Push changes to gh-pages
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: ad-m/github-push-action@master
with:
branch: gh-pages
directory: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
11 changes: 11 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# File: .readthedocs.yaml

version: 2

python:
install:
- method: pip
path: .
extra_requirements:
- docs
system_packages: true
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ OpenAeroStruct
==============

![GitHub Actions Status](https://github.com/mdolab/OpenAeroStruct/workflows/OAS%20build/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/mdolab/OpenAeroStruct/badge.svg?branch=master)](https://coveralls.io/github/mdolab/OpenAeroStruct?branch=master)
[![codecov](https://codecov.io/gh/mdolab/OpenAeroStruct/branch/master/graph/badge.svg?token=yOxeH7rT2H)](https://codecov.io/gh/mdolab/OpenAeroStruct)
[![Documentation Status](https://readthedocs.com/projects/mdolab-openaerostruct/badge/?version=latest)](https://mdolab-openaerostruct.readthedocs-hosted.com/en/latest/?badge=latest)

OpenAeroStruct is a lightweight tool that performs aerostructural optimization using OpenMDAO.
It couples a vortex-lattice method (VLM) and a 6 degrees of freedom 3-dimensional spatial beam model to simulate aerodynamic and structural analyses using lifting surfaces.
Expand All @@ -27,7 +28,7 @@ Then do:
Documentation
-------------

Please see the [documentation](https://mdolab.github.io/OpenAeroStruct/) for more installation details, walkthroughs, and examples.
Please see the [documentation](https://mdolab-openaerostruct.readthedocs-hosted.com/en/latest/) for more installation details, walkthroughs, and examples.

Citation
--------
Expand Down
114 changes: 114 additions & 0 deletions openaerostruct/docs/_exts/embed_n2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
"""
This file comes from OpenMDAO version 3.9.2 and provides functionality
to embed an N2 diagram as an HTML into the docs using a Sphinx
extension.
Link to OpenMDAO 3.9.2: https://github.com/OpenMDAO/OpenMDAO/releases/tag/3.9.2
"""

from docutils import nodes
from docutils.statemachine import ViewList
from docutils.parsers.rst import Directive
import subprocess
import sphinx
from sphinx.util.nodes import nested_parse_with_titles
import os.path


class EmbedN2Directive(Directive):
"""
EmbedN2Directive is a custom directive to build and embed an N2 diagram into docs
An example usage would look like this:
.. embed-n2::
../../examples/model.py
What the above will do is replace the directive and its arg with an N2 diagram.
The one required argument is the model file to be diagrammed.
Optional arguments are numerical width and height of the embedded object, and
"toolbar" if the toolbar should be visible by default.
Example with width of 1500, height of 800, and toolbar displayed:
.. embed-n2:
../../examples/model.py
1500
800
toolbar
"""

required_arguments = 1
optional_arguments = 3
has_content = True

def run(self):
path_to_model = self.arguments[0]
n2_dims = [1200, 700]
show_toolbar = False

if len(self.arguments) > 1 and self.arguments[1]:
n2_dim_idx = 0
for idx in range(1, len(self.arguments)):
if self.arguments[idx] == "toolbar":
show_toolbar = True
else:
n2_dims[n2_dim_idx] = self.arguments[idx]
n2_dim_idx = 1

np = os.path.normpath(os.path.join(os.getcwd(), path_to_model))

# check that the file exists
if not os.path.isfile(np):
raise IOError("File does not exist({0})".format(np))

# Generate N2 files into the target_dir. Those files are later copied
# into the top of the HTML hierarchy, so the HTML doc file needs a
# relative path to them.
target_dir = os.path.join(os.getcwd(), "_n2html")

rel_dir = os.path.relpath(os.getcwd(), os.path.dirname(self.state.document.settings._source))
html_base_name = os.path.basename(path_to_model).split(".")[0] + "_n2.html"
html_name = os.path.join(target_dir, html_base_name)
html_rel_name = os.path.join(rel_dir, html_base_name)
if show_toolbar:
html_rel_name += "#toolbar"

cmd = subprocess.Popen(["openmdao", "n2", np, "--no_browser", "--embed", "-o" + html_name])
cmd_out, cmd_err = cmd.communicate()

rst = ViewList()

# Add the content one line at a time.
# Second argument is the filename to report in any warnings
# or errors, third argument is the line number.
env = self.state.document.settings.env
docname = env.doc2path(env.docname)

object_tag = (
"<iframe width='" + str(n2_dims[0]) + "'"
" height='" + str(n2_dims[1]) + "'"
" style='border: 1px solid lightgray; resize: both;'"
" src='" + html_rel_name + "'></iframe>"
)

rst.append(".. raw:: html", docname, self.lineno)
rst.append("", docname, self.lineno) # leave an empty line
rst.append(" %s" % object_tag, docname, self.lineno)

# Create a node.
node = nodes.section()

# Parse the rst.
nested_parse_with_titles(self.state, rst, node)

# And return the result.
return node.children


def setup(app):
"""add custom directive into Sphinx so that it is found during document parsing"""
app.add_directive("embed-n2", EmbedN2Directive)

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

0 comments on commit 95d0a0f

Please sign in to comment.