Skip to content

Commit

Permalink
Fixing import errors, adding isort, cleaned up regression tests, and …
Browse files Browse the repository at this point in the history
…added unit tests for new import procedure (mdolab#180)

* Fixing error handling, sorting imports with isort, and standardizing test formats

* Added unit tests for the new import gaurds

* Adding isort to pipeline and fixing imports on dvgeo tests

* Fixing failed tests

* Addressing PR review comments
  • Loading branch information
lamkina authored Feb 2, 2023
1 parent 94909eb commit 1f6a7c3
Show file tree
Hide file tree
Showing 74 changed files with 572 additions and 307 deletions.
1 change: 1 addition & 0 deletions .github/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ extends:
template: azure/azure_template.yaml@azure_template
parameters:
REPO_NAME: pygeo
ISORT: true
COVERAGE: true
7 changes: 5 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Standard Python modules
import os
import sys

# External modules
from sphinx_mdolab_theme.config import *

# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

import os
import sys

sys.path.insert(0, os.path.abspath("../"))
sys.path.insert(0, os.path.abspath("../../"))
Expand Down
5 changes: 4 additions & 1 deletion examples/bwb/bwb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# External modules
import numpy as np
from pygeo import pyGeo
from pyspline import Curve

# First party modules
from pygeo import pyGeo

# ==============================================================================
# Start of Script
# ==============================================================================
Expand Down
3 changes: 3 additions & 0 deletions examples/c172_wing/c172.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# External modules
import numpy as np

# First party modules
from pygeo import pyGeo

# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions examples/c172_wing/genFFD.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# External modules
import numpy as np

nstreamwise = 10
Expand Down
5 changes: 4 additions & 1 deletion examples/c172_wing/runFFDExample.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from pygeo import DVGeometry
# External modules
import numpy as np
from stl import mesh

# First party modules
from pygeo import DVGeometry


def create_fresh_dvgeo():
# The Plot3D file ffdbox.xyz contains the coordinates of the free-form deformation (FFD) volume
Expand Down
12 changes: 9 additions & 3 deletions examples/cst/CSTTutorial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from pygeo import DVGeometryCST
import numpy as np
import matplotlib.pyplot as plt
# Standard Python modules
import os

# External modules
import matplotlib.pyplot as plt
import numpy as np

# First party modules
from pygeo import DVGeometryCST


# rst Plot func (beg)
def plot_points(points, filename=None):
fig, ax = plt.subplots(figsize=[10, 3])
Expand Down
1 change: 1 addition & 0 deletions examples/deform_geometry/ffd/simple_ffd.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# External modules
import numpy as np

# Bounding box for root airfoil
Expand Down
4 changes: 3 additions & 1 deletion examples/deform_geometry/geo/generate_wing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# rst Imports
# External modules
import numpy as np

# First party modules
from pygeo import pyGeo

# Number of airfoil sections
Expand Down
9 changes: 7 additions & 2 deletions examples/deform_geometry/runScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
This script demonstrates the deformation of a geometry object using FFD and
the process for exporting the geometry as a tecplot or IGES file.
"""
from pygeo import pyGeo, DVGeometry
import numpy as np
# Standard Python modules
import argparse

# External modules
import numpy as np

# First party modules
from pygeo import DVGeometry, pyGeo

input_files = "../../input_files/"


Expand Down
8 changes: 4 additions & 4 deletions examples/esp_airfoil/esp_airfoil.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# ======================================================================
# Import modules
# ======================================================================
from pygeo import DVGeometryESP
# External modules
from stl import mesh

# First party modules
from pygeo import DVGeometryESP

# rst create dvgeo start
# initialize the DVGeometry object with the csm file
csm_file = "naca0012.csm"
Expand Down
1 change: 1 addition & 0 deletions examples/ffd/generateBWBFFD.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# External modules
import numpy as np

# rst Dimensions
Expand Down
1 change: 1 addition & 0 deletions examples/ffd/generateFFD.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# External modules
import numpy as np


Expand Down
1 change: 1 addition & 0 deletions examples/ffd/generatec172FFD.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# External modules
import numpy as np

# rst Dimensions
Expand Down
1 change: 1 addition & 0 deletions examples/ffd/generaterectFFD.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# External modules
import numpy as np

# rst Dimensions
Expand Down
1 change: 1 addition & 0 deletions examples/ffd_cylinder/genFFD.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# External modules
import numpy as np

nffd = 10
Expand Down
7 changes: 5 additions & 2 deletions examples/ffd_cylinder/runFFDExample.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from pygeo import DVGeometry
import numpy as np
# External modules
import matplotlib.pyplot as plt
import numpy as np

# First party modules
from pygeo import DVGeometry

# create a pointset. pointsets are of shape npts by 3 (the second dim is xyz coordinate)
# we'll generate a cylinder in parametric coordinates
Expand Down
21 changes: 4 additions & 17 deletions pygeo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,7 @@
from .constraints import DVConstraints
from .parameterization import DVGeometry
from .parameterization import DVGeometryAxi

try:
from .parameterization import DVGeometryCST
except ImportError:
pass
try:
from .parameterization import DVGeometryVSP
except ImportError:
pass
try:
from .parameterization import DVGeometryESP
except ImportError:
pass
try:
from .parameterization import DVGeometryMulti
except ImportError:
pass
from .parameterization import DVGeometryCST
from .parameterization import DVGeometryVSP
from .parameterization import DVGeometryESP
from .parameterization import DVGeometryMulti
35 changes: 19 additions & 16 deletions pygeo/constraints/DVCon.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# ======================================================================
# Imports
# ======================================================================
import numpy as np
from .. import geo_utils, pyGeo
from pyspline import Curve
# Standard Python modules
from collections import OrderedDict

# External modules
from baseclasses.utils import Error
from .baseConstraint import LinearConstraint, GlobalLinearConstraint
from .thicknessConstraint import ThicknessConstraint, ThicknessToChordConstraint
from .radiusConstraint import RadiusConstraint
from .locationConstraint import LocationConstraint
from .areaConstraint import TriangulatedSurfaceConstraint, SurfaceAreaConstraint, ProjectedAreaConstraint
from .volumeConstraint import VolumeConstraint, TriangulatedVolumeConstraint, CompositeVolumeConstraint
import numpy as np
from pyspline import Curve

# Local modules
from .. import geo_utils, pyGeo
from ..geo_utils.file_io import readPlot3DSurfFile
from ..geo_utils.misc import convertTo2D
from .areaConstraint import ProjectedAreaConstraint, SurfaceAreaConstraint, TriangulatedSurfaceConstraint
from .baseConstraint import GlobalLinearConstraint, LinearConstraint
from .circularityConstraint import CircularityConstraint
from .colinearityConstraint import ColinearityConstraint
from .curvatureConstraint import CurvatureConstraint, CurvatureConstraint1D
from .gearPostConstraint import GearPostConstraint
from .circularityConstraint import CircularityConstraint
from .locationConstraint import LocationConstraint
from .planarityConstraint import PlanarityConstraint
from .curvatureConstraint import CurvatureConstraint, CurvatureConstraint1D
from ..geo_utils.misc import convertTo2D
from ..geo_utils.file_io import readPlot3DSurfFile
from .radiusConstraint import RadiusConstraint
from .thicknessConstraint import ThicknessConstraint, ThicknessToChordConstraint
from .volumeConstraint import CompositeVolumeConstraint, TriangulatedVolumeConstraint, VolumeConstraint


class DVConstraints:
Expand Down Expand Up @@ -401,6 +403,7 @@ def writeSurfaceSTL(self, fileName, surfaceName="default", fromDVGeo=None):
Name of the DVGeo object to obtain the surface from (default is 'None')
"""
try:
# External modules
from stl import mesh
except ImportError as e:
raise ImportError("numpy-stl package must be installed") from e
Expand Down
11 changes: 6 additions & 5 deletions pygeo/constraints/areaConstraint.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# ======================================================================
# Imports
# ======================================================================
# External modules
from mpi4py import MPI
import numpy as np

# Local modules
from .. import geo_utils
from mpi4py import MPI
from .baseConstraint import GeometricConstraint
from ..geo_utils.polygon import areaTri
from .baseConstraint import GeometricConstraint

try:
# External modules
from geograd import geograd_parallel # noqa
except ImportError:
geograd_parallel = None
Expand Down
8 changes: 4 additions & 4 deletions pygeo/constraints/baseConstraint.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# ======================================================================
# Imports
# ======================================================================
# Standard Python modules
from abc import ABC, abstractmethod
from collections import OrderedDict
import numpy as np

# External modules
from baseclasses.utils import Error
import numpy as np


class GeometricConstraint(ABC):
Expand Down
6 changes: 3 additions & 3 deletions pygeo/constraints/circularityConstraint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ======================================================================
# Imports
# ======================================================================
# External modules
import numpy as np

# Local modules
from .baseConstraint import GeometricConstraint


Expand Down
6 changes: 3 additions & 3 deletions pygeo/constraints/colinearityConstraint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ======================================================================
# Imports
# ======================================================================
# External modules
import numpy as np

# Local modules
from .. import geo_utils
from .baseConstraint import GeometricConstraint

Expand Down
10 changes: 5 additions & 5 deletions pygeo/constraints/curvatureConstraint.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# ======================================================================
# Imports
# ======================================================================
import numpy as np
# External modules
from baseclasses.utils import Error
from mpi4py import MPI
import numpy as np
from scipy.sparse import csr_matrix
from baseclasses.utils import Error

# Local modules
from .baseConstraint import GeometricConstraint


Expand Down
6 changes: 3 additions & 3 deletions pygeo/constraints/gearPostConstraint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ======================================================================
# Imports
# ======================================================================
# External modules
import numpy as np

# Local modules
from .. import geo_utils
from .baseConstraint import GeometricConstraint

Expand Down
6 changes: 3 additions & 3 deletions pygeo/constraints/locationConstraint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ======================================================================
# Imports
# ======================================================================
# External modules
import numpy as np

# Local modules
from .baseConstraint import GeometricConstraint


Expand Down
6 changes: 3 additions & 3 deletions pygeo/constraints/planarityConstraint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ======================================================================
# Imports
# ======================================================================
# External modules
import numpy as np

# Local modules
from .. import geo_utils
from .baseConstraint import GeometricConstraint

Expand Down
6 changes: 3 additions & 3 deletions pygeo/constraints/radiusConstraint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ======================================================================
# Imports
# ======================================================================
# External modules
import numpy as np

# Local modules
from .. import geo_utils
from .baseConstraint import GeometricConstraint

Expand Down
6 changes: 3 additions & 3 deletions pygeo/constraints/thicknessConstraint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ======================================================================
# Imports
# ======================================================================
# External modules
import numpy as np

# Local modules
from .. import geo_utils
from .baseConstraint import GeometricConstraint

Expand Down
13 changes: 4 additions & 9 deletions pygeo/constraints/volumeConstraint.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# ======================================================================
# Imports
# ======================================================================
# External modules
import numpy as np

# Local modules
from ..geo_utils.polygon import volumeHex, volumeHex_b, volumeTriangulatedMesh, volumeTriangulatedMesh_b
from .baseConstraint import GeometricConstraint
from ..geo_utils.polygon import (
volumeHex,
volumeHex_b,
volumeTriangulatedMesh,
volumeTriangulatedMesh_b,
)


class VolumeConstraint(GeometricConstraint):
Expand Down
1 change: 1 addition & 0 deletions pygeo/geo_utils/bilinear_map.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# External modules
import numpy as np


Expand Down
Loading

0 comments on commit 1f6a7c3

Please sign in to comment.