Skip to content

Commit

Permalink
Update flake8 and docs (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewu63 authored Aug 31, 2021
1 parent 40ce163 commit cc56917
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 98 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
extend-exclude =
baseclasses/problems/pyFieldPerformance_problem.py
17 changes: 17 additions & 0 deletions baseclasses/problems/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,20 @@
from .pyEngine_problem import EngineProblem
from .pyFieldPerformance_problem import FieldPerformanceProblem
from .pyLG_problem import LGProblem

__all__ = [
"AeroProblem",
"TransiProblem",
"StructProblem",
"AeroStructProblem",
"MissionProblem",
"MissionProfile",
"MissionSegment",
"WeightProblem",
"FuelCase",
"FluidProperties",
"ICAOAtmosphere",
"EngineProblem",
"FieldPerformanceProblem",
"LGProblem",
]
2 changes: 1 addition & 1 deletion baseclasses/problems/pyAero_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def __init__(self, name, **kwargs):
self.evalFuncs = set(kwargs["funcs"])

# we cast the set to a sorted list, so that each proc can loop over in the same order
self.evalFuncs = sorted(list(self.evalFuncs))
self.evalFuncs = sorted(self.evalFuncs)

# these are the possible input values
possibleInputStates = {"mach", "V", "P", "T", "rho", "altitude", "reynolds", "reynoldsLength"}
Expand Down
52 changes: 24 additions & 28 deletions baseclasses/problems/pyMission_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,13 @@ def _checkStateConsistancy(self):
pass
else:
if not self.firstSegSet:
setattr(seg, "isFirstStateSeg", True)
seg.isFirstStateSeg = True
self.firstSegSet = True
# end
if seg.isFirstStateSeg:
# this is the first segment.
# Need to have at least the start alt and V or M
if getattr(seg, "initAlt") is None:
if seg.initAlt is None:
raise Error(
"%s: Initial altitude must be\
specified for the first non fuel fraction\
Expand All @@ -412,11 +412,7 @@ def _checkStateConsistancy(self):
)
# end

if (
(getattr(seg, "initMach") is None)
and (getattr(seg, "initCAS") is None)
and (getattr(seg, "initTAS") is None)
):
if (seg.initMach is None) and (seg.initCAS is None) and (seg.initTAS is None):
raise Error(
"%s: One of initCAS,initTAS or initMach needs to be\
specified for the first non fuelfraction\
Expand All @@ -430,14 +426,14 @@ def _checkStateConsistancy(self):

else:
prevSeg = self.segments[i - 1]
refAlt = getattr(prevSeg, "finalAlt")
refCAS = getattr(prevSeg, "finalCAS")
refTAS = getattr(prevSeg, "finalTAS")
refMach = getattr(prevSeg, "finalMach")
TASi = getattr(seg, "initTAS")
CASi = getattr(seg, "initCAS")
Mi = getattr(seg, "initMach")
Alti = getattr(seg, "initAlt")
refAlt = prevSeg.finalAlt
refCAS = prevSeg.finalCAS
refTAS = prevSeg.finalTAS
refMach = prevSeg.finalMach
TASi = seg.initTAS
CASi = seg.initCAS
Mi = seg.initMach
Alti = seg.initAlt
if CASi is not None:
if not CASi == refCAS:
raise Error(
Expand All @@ -449,7 +445,7 @@ def _checkStateConsistancy(self):
)
# end
else:
setattr(seg, "initCAS", refCAS)
seg.initCAS = refCAS
# end
if TASi is not None:
if not TASi == refTAS:
Expand All @@ -462,7 +458,7 @@ def _checkStateConsistancy(self):
)
# end
else:
setattr(seg, "initTAS", refTAS)
seg.initTAS = refTAS
# end
if Alti is not None:
if not Alti == refAlt:
Expand All @@ -474,7 +470,7 @@ def _checkStateConsistancy(self):
)
# end
else:
setattr(seg, "initAlt", refAlt)
seg.initAlt = refAlt
# end
if Mi is not None:
if not Mi == refMach:
Expand All @@ -486,7 +482,7 @@ def _checkStateConsistancy(self):
)
# end
else:
setattr(seg, "initMach", refMach)
seg.initMach = refMach
# end

# Determine the remaining segment parameters (Alt, Mach, CAS, TAS)
Expand Down Expand Up @@ -1056,31 +1052,31 @@ def setMissionData(self, module, segTypeDict, engTypeDict, idx, segIdx):
"""
set the data for the current segment in the fortran module
"""
h1 = getattr(self, "initAlt")
h1 = self.initAlt
if h1 is None:
h1 = 0.0
h2 = getattr(self, "finalAlt")
h2 = self.finalAlt
if h2 is None:
h2 = 0.0
M1 = getattr(self, "initMach")
M1 = self.initMach
if M1 is None:
M1 = 0.0
M2 = getattr(self, "finalMach")
M2 = self.finalMach
if M2 is None:
M2 = 0.0
deltaTime = getattr(self, "segTime")
deltaTime = self.segTime
if deltaTime is None:
deltaTime = 0.0
# end

rangeFraction = getattr(self, "rangeFraction")
rangeFraction = self.rangeFraction
if rangeFraction is None:
rangeFraction = 1.0
# end

# Get the fuel-fraction, if provided, then segment is a generic fuel fraction type
fuelFraction = getattr(self, "fuelFraction")
throttle = getattr(self, "throttle")
fuelFraction = self.fuelFraction
throttle = self.throttle
if fuelFraction is None and throttle is None:
segTypeID = segTypeDict[getattr(self, "phase").lower()]
fuelFraction = 0.0
Expand All @@ -1098,7 +1094,7 @@ def setMissionData(self, module, segTypeDict, engTypeDict, idx, segIdx):
raise Error(f"engType {self.engType} defined in segment {self.phase} not defined in engTypeDict")
if self.engType is None:
self.engType = "None"
engTypeID = engTypeDict[getattr(self, "engType")]
engTypeID = engTypeDict[self.engType]

module.setmissionsegmentdata(
idx,
Expand Down
2 changes: 1 addition & 1 deletion baseclasses/problems/pyStruct_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, name, **kwargs):
self.evalFuncs = set(kwargs["funcs"])

# we cast the set to a sorted list, so that each proc can loop over in the same order
self.evalFuncs = sorted(list(self.evalFuncs))
self.evalFuncs = sorted(self.evalFuncs)

# When a solver calls its evalFunctions() it must write the
# unique name it gives to funcNames.
Expand Down
2 changes: 2 additions & 0 deletions baseclasses/solvers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from .BaseSolver import BaseSolver
from .pyAero_solver import AeroSolver

__all__ = ["BaseSolver", "AeroSolver"]
2 changes: 2 additions & 0 deletions baseclasses/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from .pyRegTest import BaseRegTest, getTol
from .decorators import require_mpi

__all__ = ["BaseRegTest", "getTol", "require_mpi"]
11 changes: 11 additions & 0 deletions baseclasses/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@


def require_mpi(func):
"""A decorator to skip tests unless ``mpi4py`` is available
Examples
--------
.. code-block:: python
@require_mpi
def test_mpi4py(self):
print(self.comm.rank)
"""
return base_require(func, "mpi4py")


Expand Down
2 changes: 2 additions & 0 deletions baseclasses/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .containers import CaseInsensitiveSet, CaseInsensitiveDict
from .error import Error
from .py3Util import getPy3SafeString

__all__ = ["CaseInsensitiveSet", "CaseInsensitiveDict", "Error", "getPy3SafeString"]
6 changes: 3 additions & 3 deletions baseclasses/utils/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CaseInsensitiveDict(MutableMapping):
--------
This container preserves the initial capitalization, such that
any operation which operates on an existing entry will not modify it.
This means that add() and update() will NOT update the original capitalization.
This means that for example :meth:`__setitem__()` will NOT update the original capitalization.
"""

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -119,7 +119,7 @@ class CaseInsensitiveSet(MutableSet):
--------
This container preserves the initial capitalization, such that
any operation which operates on an existing entry will not modify it.
This means that add() and update() will NOT update the original capitalization.
This means that :meth:`add()` and :meth:`update()` will NOT update the original capitalization.
"""

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -192,7 +192,7 @@ def union(self, d):
return new_set

def update(self, d):
"""Just call add() iteratively"""
"""Just call :meth:`add()` iteratively"""
for item in d:
self.add(item)

Expand Down
2 changes: 1 addition & 1 deletion baseclasses/utils/py3Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def getPy3SafeString(string):
"""Accepts a <string> and makes sure its converted to unicode for python 3.6 and above"""
"""Accepts a string and makes sure it's converted to unicode for python 3.6 and above"""

if string is None:
return None
Expand Down
12 changes: 4 additions & 8 deletions doc/BaseRegTest.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
.. _BaseRegTest:
Testing
-------

BaseRegTest
-----------

.. currentmodule:: baseclasses.BaseRegTest

.. autoclass:: BaseRegTest
.. autoclass:: baseclasses.BaseRegTest
:members:

.. automodule:: baseclasses.BaseRegTest
.. automodule:: baseclasses.testing
:members:
6 changes: 1 addition & 5 deletions doc/BaseSolver.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
.. _BaseSolver:

BaseSolver
----------

.. currentmodule:: baseclasses.BaseSolver

.. autoclass:: BaseSolver
.. autoclass:: baseclasses.BaseSolver
:members:
8 changes: 6 additions & 2 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
.. _baseClasses:

===========
baseClasses
===========
Expand Down Expand Up @@ -57,3 +55,9 @@ Or from source, by cloning the repo and then running (from the repo root)::

BaseRegTest
regression_example

.. toctree::
:maxdepth: 1
:caption: Utilities

utils
8 changes: 2 additions & 6 deletions doc/pyAeroStruct_problem.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
.. _pyAeroStruct_problem:

pyAeroStruct_problem
AeroStructProblem
--------------------

.. currentmodule:: baseclasses.pyAeroStruct_problem

.. autoclass:: AeroStructProblem
.. autoclass:: baseclasses.AeroStructProblem
:members:
10 changes: 3 additions & 7 deletions doc/pyAero_problem.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
.. _pyAero_problem:
AeroProblem
-----------

pyAero_problem
--------------

.. currentmodule:: baseclasses.pyAero_problem

.. autoclass:: AeroProblem
.. autoclass:: baseclasses.AeroProblem
:members:
8 changes: 3 additions & 5 deletions doc/pyAero_solver.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
.. _pyAero_solver:
AeroSolver
----------

pyAero_solver
-------------

.. currentmodule:: baseclasses.pyAero_solver
.. currentmodule:: baseclasses

.. autoclass:: AeroSolver
:members:
14 changes: 5 additions & 9 deletions doc/pyMission_problem.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
.. _pyMission_problem:
MissionProblem
--------------

pyMission_problem
-----------------

.. currentmodule:: baseclasses.pyMission_problem

.. autoclass:: MissionProblem
.. autoclass:: baseclasses.MissionProblem
:members:
.. autoclass:: MissionProfile
.. autoclass:: baseclasses.MissionProfile
:members:
.. autoclass:: MissionSegment
.. autoclass:: baseclasses.MissionSegment
:members:
10 changes: 3 additions & 7 deletions doc/pyStruct_problem.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
.. _pyStruct_problem:
StructProblem
-------------

pyStruct_problem
----------------

.. currentmodule:: baseclasses.pyStruct_problem

.. autoclass:: StructProblem
.. autoclass:: baseclasses.StructProblem
:members:
8 changes: 2 additions & 6 deletions doc/pyWeight_problem.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
.. _pyWeight_problem:

pyWeight_problem
WeightProblem
----------------

.. currentmodule:: baseclasses.pyWeight_problem

.. autoclass:: WeightProblem
.. autoclass:: baseclasses.WeightProblem
:members:
Loading

0 comments on commit cc56917

Please sign in to comment.