From f61ddf026e03b16d0d8d5ecef6d367a08d7557b8 Mon Sep 17 00:00:00 2001 From: Alasdair Gray Date: Tue, 12 Aug 2025 16:06:39 -0400 Subject: [PATCH 1/3] Test using pre-commit/ruff GHA from https://github.com/mdolab/.github/pull/74 --- .github/workflows/format-and-lint.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/format-and-lint.yaml diff --git a/.github/workflows/format-and-lint.yaml b/.github/workflows/format-and-lint.yaml new file mode 100644 index 0000000..5607a79 --- /dev/null +++ b/.github/workflows/format-and-lint.yaml @@ -0,0 +1,12 @@ +name: Format and Lint + +on: + push: + branches: [main] + tags: + - v*.*.* + pull_request: + +jobs: + pre-commit: + uses: mdolab/.github/.github/workflows/format-and-lint.yaml@ruffConfig From 65c698d3ec50ff19947481edc2b52ff48e840d7f Mon Sep 17 00:00:00 2001 From: Alasdair Gray Date: Tue, 12 Aug 2025 16:36:02 -0400 Subject: [PATCH 2/3] Formatting --- .gitignore | 6 +++++- LICENSE.md | 5 +---- baseclasses/problems/pyAeroStruct_problem.py | 1 + baseclasses/problems/pyAero_problem.py | 2 +- baseclasses/problems/pyFieldPerformance_problem.py | 2 +- baseclasses/problems/pyMission_problem.py | 2 +- baseclasses/problems/pyStruct_problem.py | 2 +- baseclasses/problems/pyTransi_problem.py | 1 + baseclasses/problems/pyWeight_problem.py | 6 +++--- baseclasses/solvers/BaseSolver.py | 8 +++++--- baseclasses/solvers/pyAero_solver.py | 8 +++----- baseclasses/utils/utils.py | 1 + doc/regression_example.rst | 2 +- 13 files changed, 25 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index f5956b1..62ae286 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,8 @@ doc/_build # VS code configurations -*.vscode \ No newline at end of file +*.vscode + +# pre-commit/ruff configuration +.pre-commit-config.yaml +ruff.toml diff --git a/LICENSE.md b/LICENSE.md index 526dee3..33cebf4 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -10,13 +10,10 @@ All rights reserved. ______________________________________________________________________________ baseClasses is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at:\ -http://www.apache.org/licenses/LICENSE-2.0 +http://www.apache.org/licenses/LICENSE-2.0 ______________________________________________________________________________ University of Michigan's Multidisciplinary Design Optimization Laboratory (MDO Lab)\ College of Engineering, Aerospace Engineering Department\ http://mdolab.engin.umich.edu/ ______________________________________________________________________________ - - - diff --git a/baseclasses/problems/pyAeroStruct_problem.py b/baseclasses/problems/pyAeroStruct_problem.py index aa10157..9463150 100644 --- a/baseclasses/problems/pyAeroStruct_problem.py +++ b/baseclasses/problems/pyAeroStruct_problem.py @@ -1,6 +1,7 @@ """ pyAeroStruct_problem """ + # ====================================================================== # Imports # ====================================================================== diff --git a/baseclasses/problems/pyAero_problem.py b/baseclasses/problems/pyAero_problem.py index 89b600f..f116a08 100644 --- a/baseclasses/problems/pyAero_problem.py +++ b/baseclasses/problems/pyAero_problem.py @@ -585,7 +585,7 @@ def addDV( Examples -------- >>> # Add alpha variable with typical bounds - >>> ap.addDV('alpha', value=2.5, lower=0.0, upper=10.0, scale=0.1) + >>> ap.addDV("alpha", value=2.5, lower=0.0, upper=10.0, scale=0.1) """ if (key not in self.allVarFuncs) and (key not in self.possibleBCDVs): diff --git a/baseclasses/problems/pyFieldPerformance_problem.py b/baseclasses/problems/pyFieldPerformance_problem.py index f93658b..d9664f9 100644 --- a/baseclasses/problems/pyFieldPerformance_problem.py +++ b/baseclasses/problems/pyFieldPerformance_problem.py @@ -275,7 +275,7 @@ def addDV(self, key, value=None, lower=None, upper=None, scale=1.0, name=None, d Examples -------- >>> # Add alpha variable with typical bounds - >>> fpp.addDV('TOW', value=250000, lower=0.0, upper=300000.0, scale=0.1) + >>> fpp.addDV("TOW", value=250000, lower=0.0, upper=300000.0, scale=0.1) """ # First check if we are allowed to add the DV: diff --git a/baseclasses/problems/pyMission_problem.py b/baseclasses/problems/pyMission_problem.py index 01006cd..7a557a3 100644 --- a/baseclasses/problems/pyMission_problem.py +++ b/baseclasses/problems/pyMission_problem.py @@ -1152,7 +1152,7 @@ def addDV(self, paramKey, lower=-1e20, upper=1e20, scale=1.0, name=None): Examples -------- >>> # Add initMach variable with typical bounds - >>> seg.addDV('initMach', value=0.75, lower=0.0, upper=1.0, scale=1.0) + >>> seg.addDV("initMach", value=0.75, lower=0.0, upper=1.0, scale=1.0) """ # First check if we are allowed to add the DV: diff --git a/baseclasses/problems/pyStruct_problem.py b/baseclasses/problems/pyStruct_problem.py index 47ee8d1..59fcdba 100644 --- a/baseclasses/problems/pyStruct_problem.py +++ b/baseclasses/problems/pyStruct_problem.py @@ -26,7 +26,7 @@ class StructProblem: Examples -------- - >>> sp = StructProblem('lc0', loadFile='loads.txt') + >>> sp = StructProblem("lc0", loadFile="loads.txt") """ def __init__(self, name, loadFile=None, loadFactor=None, evalFuncs=None): diff --git a/baseclasses/problems/pyTransi_problem.py b/baseclasses/problems/pyTransi_problem.py index d36becd..231ec18 100644 --- a/baseclasses/problems/pyTransi_problem.py +++ b/baseclasses/problems/pyTransi_problem.py @@ -2,6 +2,7 @@ pyAero_problem """ + from ..utils import Error diff --git a/baseclasses/problems/pyWeight_problem.py b/baseclasses/problems/pyWeight_problem.py index 4c84392..986ebc9 100644 --- a/baseclasses/problems/pyWeight_problem.py +++ b/baseclasses/problems/pyWeight_problem.py @@ -127,7 +127,7 @@ def setSurface(self, surf): >>> surf = CFDsolver.getTriangulatedMeshSurface() >>> wp.setSurface(surf) >>> # Or using a pyGeo surface object: - >>> surf = pyGeo('iges',fileName='wing.igs') + >>> surf = pyGeo("iges", fileName="wing.igs") >>> wp.setSurface(surf) """ @@ -642,8 +642,8 @@ def addDV( Examples -------- >>> # Add W variable with typical bounds - >>> fuelCase.addDV('fuelFraction', value=0.5, lower=0.0, upper=1.0, scale=0.1) - >>> fuelCase.addDV('reserveFraction', value=0.1, lower=0.0, upper=1.0, scale=0.1) + >>> fuelCase.addDV("fuelFraction", value=0.5, lower=0.0, upper=1.0, scale=0.1) + >>> fuelCase.addDV("reserveFraction", value=0.1, lower=0.0, upper=1.0, scale=0.1) """ # First check if we are allowed to add the DV: diff --git a/baseclasses/solvers/BaseSolver.py b/baseclasses/solvers/BaseSolver.py index 2eb1d58..e44bdfb 100644 --- a/baseclasses/solvers/BaseSolver.py +++ b/baseclasses/solvers/BaseSolver.py @@ -3,6 +3,7 @@ Holds a basic Python Analysis Classes (base and inherited). """ + from difflib import get_close_matches import copy import warnings @@ -22,7 +23,7 @@ def __init__( name, category, defaultOptions={}, - options={}, + options=None, immutableOptions=set(), deprecatedOptions={}, comm=None, @@ -86,8 +87,9 @@ def __init__( else: self.setOption(key, optionValue) - for key in options: - self.setOption(key, options[key]) + if options is not None: + for key in options: + self.setOption(key, options[key]) self.solverCreated = True diff --git a/baseclasses/solvers/pyAero_solver.py b/baseclasses/solvers/pyAero_solver.py index 27c3ae6..6eb5f54 100644 --- a/baseclasses/solvers/pyAero_solver.py +++ b/baseclasses/solvers/pyAero_solver.py @@ -21,7 +21,6 @@ class AeroSolver(BaseSolver): - """ Abstract Class for Aerodynamic Solver Object """ @@ -317,7 +316,7 @@ def addFamilyGroup(self, groupName, families): # Do some error checking if groupName in self.families: raise Error( - "The specified groupName '%s' already exists in the " "cgns file or has already been added." % groupName + "The specified groupName '%s' already exists in the cgns file or has already been added." % groupName ) # We can actually allow for nested groups. That is, an entry @@ -389,7 +388,7 @@ def setSurfaceCoordinates(self, coordinates, groupName=None): self._updateGeomInfo = True if self.mesh is None: - raise Error("Cannot set new surface coordinate locations without a mesh" "warping object present.") + raise Error("Cannot set new surface coordinate locations without a meshwarping object present.") # First get the surface coordinates of the meshFamily in case # the groupName is a subset, those values will remain unchanged. @@ -500,8 +499,7 @@ def _getFamilyList(self, groupName): if groupName not in self.families: raise Error( - "'%s' is not a family in the CGNS file or has not been added" - " as a combination of families" % groupName + "'%s' is not a family in the CGNS file or has not been added as a combination of families" % groupName ) return self.families[groupName] diff --git a/baseclasses/utils/utils.py b/baseclasses/utils/utils.py index bf2264c..71c022d 100644 --- a/baseclasses/utils/utils.py +++ b/baseclasses/utils/utils.py @@ -1,6 +1,7 @@ """ Helper methods for supporting python3 and python2 at the same time """ + import re import sys from pprint import pformat diff --git a/doc/regression_example.rst b/doc/regression_example.rst index 61afec4..6c3ce78 100644 --- a/doc/regression_example.rst +++ b/doc/regression_example.rst @@ -38,5 +38,5 @@ Then, when running ``testflo`` we can specify to run all of the training functio Normally, when ``testflo`` is run, it looks for all functions that begin with ``test_``. The ``-m`` flag allows us to specify a different prefix. -In this case, by using the ``train_`` prefix on all of the training functions we can run them all at once with the above command. +In this case, by using the ``train_`` prefix on all of the training functions we can run them all at once with the above command. Once the reference files are created, just calling ``testflo`` will run all the regression tests. From bd6c7e96079d329fde919615f6cd0dfe515eee19 Mon Sep 17 00:00:00 2001 From: Alasdair Gray Date: Wed, 20 Aug 2025 17:29:56 -0400 Subject: [PATCH 3/3] Trigger Build