-
Notifications
You must be signed in to change notification settings - Fork 66
Strengthen tidy3d-extras packaging test #2884
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
Conversation
6c1a07b to
b263531
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (2)
-
tests/test_components/test_packaging.py, line 79 (link)style: Consider removing this print statement as it's debug output that shouldn't be in production tests
Context Used: Rule from
dashboard- Remove temporary debugging code (print() calls), commented-out code, and other workarounds before fi... (source) -
tests/test_components/test_packaging.py, line 5 (link)style: The
configimport is unused in this file - consider removing it if not needed
2 files reviewed, 2 comments
b263531 to
c47d63f
Compare
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/packaging.pyLines 197-205 197 if tidy3d_extras["mod"] is None:
198 tidy3d_extras["use_local_subpixel"] = False
199 module_exists = find_spec("tidy3d_extras") is not None
200 if config.use_local_subpixel is True and not module_exists:
! 201 raise Tidy3dImportError(
202 "The package 'tidy3d-extras' is required for this "
203 "operation when 'config.use_local_subpixel' is 'True'. "
204 "Please install the 'tidy3d-extras' package using, for "
205 "example, 'pip install tidy3d[extras]'."Lines 205-216 205 "example, 'pip install tidy3d[extras]'."
206 )
207
208 if module_exists:
! 209 try:
! 210 import tidy3d_extras as tidy3d_extras_mod
211
! 212 except ImportError as exc:
213 # this should not happen; if the API key is invalid,
214 # the package should still import but the version will be None
215 raise Tidy3dImportError(
216 "The package 'tidy3d-extras' did not initialize correctly. " |
c47d63f to
74694a9
Compare
|
@yaugenst-flex can we get this in? pretty minor changes |
Sorry this slipped the cracks, lgtm! |
74694a9 to
8e02cfc
Compare
8e02cfc to
6c33934
Compare
Some minor improvements to packaging:
disable_local_subpixelshould restore the config even if the function it wraps errorsGreptile Overview
Updated On: 2025-10-10 17:41:16 UTC
Greptile Summary
This PR strengthens the packaging system for the optional
tidy3d-extrasdependency by improving error handling and module detection logic. The changes refactor thesupports_local_subpixeldecorator intidy3d/packaging.pyto usefind_spec()for more robust module existence checking before attempting imports, providing clearer error differentiation between "module not found" vs "module failed to initialize". Thedisable_local_subpixeldecorator is also enhanced with proper try/finally blocks to ensure configuration state is always restored even when exceptions occur.Additionally, a new test function
test_tidy3d_extras()is added totests/test_components/test_packaging.pythat validates the packaging behavior for both scenarios when tidy3d-extras is available and when it's not. This test ensures that the@supports_local_subpixeldecorator correctly detects the module, loads features, and sets appropriate flags. The changes improve the reliability of Tidy3D's optional dependency handling, which is critical for a library that extends core functionality through optional packages.Important Files Changed
Changed Files
Confidence score: 4/5
supports_local_subpixeldecorator logic intidy3d/packaging.pySequence Diagram
sequenceDiagram participant User participant test_tidy3d_extras participant importlib participant supports_local_subpixel participant get_eps participant tidy3d_extras_global participant config participant tidy3d_extras_mod User->>test_tidy3d_extras: "Run test_tidy3d_extras()" test_tidy3d_extras->>importlib: "find_spec('tidy3d_extras')" importlib-->>test_tidy3d_extras: "spec or None" test_tidy3d_extras->>test_tidy3d_extras: "has_tidy3d_extras = spec is not None" test_tidy3d_extras->>get_eps: "@supports_local_subpixel decorated call" supports_local_subpixel->>config: "Check config.use_local_subpixel" alt config.use_local_subpixel is False supports_local_subpixel->>tidy3d_extras_global: "Set use_local_subpixel = False" supports_local_subpixel->>tidy3d_extras_global: "Set mod = None" else config.use_local_subpixel is not False and mod is None supports_local_subpixel->>tidy3d_extras_global: "Set use_local_subpixel = False" supports_local_subpixel->>importlib: "find_spec('tidy3d_extras')" importlib-->>supports_local_subpixel: "spec or None" alt module exists supports_local_subpixel->>tidy3d_extras_mod: "import tidy3d_extras" tidy3d_extras_mod-->>supports_local_subpixel: "tidy3d_extras_mod" supports_local_subpixel->>tidy3d_extras_mod: "Check __version__" supports_local_subpixel->>tidy3d_extras_mod: "extension._features()" tidy3d_extras_mod-->>supports_local_subpixel: "features list" supports_local_subpixel->>tidy3d_extras_global: "Set mod = tidy3d_extras_mod" supports_local_subpixel->>tidy3d_extras_global: "Set use_local_subpixel = 'local_subpixel' in features" end end supports_local_subpixel->>get_eps: "Call original function" alt has_tidy3d_extras is True get_eps->>tidy3d_extras_global: "Assert mod is not None" get_eps->>tidy3d_extras_global: "Get mod.extension._features()" get_eps->>get_eps: "Assert use_local_subpixel == ('local_subpixel' in features)" else has_tidy3d_extras is False get_eps->>tidy3d_extras_global: "Assert use_local_subpixel is False" get_eps->>tidy3d_extras_global: "Assert mod is None" end get_eps-->>test_tidy3d_extras: "Function execution complete" test_tidy3d_extras-->>User: "Test complete"