-
Notifications
You must be signed in to change notification settings - Fork 119
Improve conditional imports #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kanekosh
merged 14 commits into
mdolab:main
from
whophil:feature/improve-conditional-imports
Oct 8, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
37cac9f
Improve conditional imports
c635020
Add back env var handling for SNOPT
31c8ea8
Fix typehint
37c61b8
Fix value checking
af8016e
Permit strs
a4623d9
Merge branch 'main' into feature/improve-conditional-imports
kanekosh f51bda9
Formatting
A-CGray 3807ebf
Linting
A-CGray 1151c91
Merge branch 'main' into feature/improve-conditional-imports
A-CGray bb6bd3f
Add better tests
1803a56
Use context manager for prepend_path
553d8cc
Fix error check/raise in pyCONMIN
4e5ab3f
Update pyOpt_utils.py
ewu63 e7c46ac
version bump
ewu63 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,3 +28,5 @@ pyoptsparse/pyNLPQLP/source | |
| *.pdb | ||
|
|
||
| *.pyd | ||
|
|
||
| .DS_Store | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,15 +27,15 @@ | |
| INFINITY, | ||
| IROW, | ||
| extractRows, | ||
| import_module, | ||
| mapToCSC, | ||
| scaleRows, | ||
| try_import_compiled_module_from_path, | ||
| ) | ||
|
|
||
| # import the compiled module | ||
| THIS_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
| _IMPORT_SNOPT_FROM = os.environ.get("PYOPTSPARSE_IMPORT_SNOPT_FROM", THIS_DIR) | ||
| snopt = try_import_compiled_module_from_path("snopt", _IMPORT_SNOPT_FROM) | ||
| _IMPORT_SNOPT_FROM = os.environ.get("PYOPTSPARSE_IMPORT_SNOPT_FROM", None) or THIS_DIR | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to handle an empty str set to the var? |
||
| snopt = import_module("snopt", [_IMPORT_SNOPT_FROM]) | ||
|
|
||
|
|
||
| class SNOPT(Optimizer): | ||
|
|
@@ -68,9 +68,9 @@ def __init__(self, raiseError=True, options: Dict = {}): | |
|
|
||
| informs = self._getInforms() | ||
|
|
||
| if isinstance(snopt, str): | ||
| if isinstance(snopt, Exception): | ||
| if raiseError: | ||
| raise ImportError(snopt) | ||
| raise snopt | ||
| else: | ||
| version = None | ||
| else: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.