Skip to content
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

Automate TPL callback registrations #3167

Merged
merged 20 commits into from
Feb 29, 2024

Conversation

jsiirola
Copy link
Member

Fixes IDAES/idaes-pse#1348

Summary/Motivation:

This PR updates how we handle registration of numpy types as native numeric types. This updates the attempt_import machinery to hook into Python's regular importlib process. Now deferred import modules with callbacks (including numpy) are registered with a custom module finder that ensures that if they are imported (even by code outside of Pyomo), the post-import callback is triggered.

Changes proposed in this PR:

  • add DeferredImportCallbackFinder / DeferredImportCallbackLoader to hook into importlib and endure deferred import modules with callbacks always have their callbacks called
  • rename attempt_import(defer_check= to attempt_import(defer_import=
  • by default attempt_import will immediately process modules that have already been imported

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

Copy link
Contributor

@mrmundt mrmundt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smallest of NFC changes, but it's good besides that.


_DeferredImportCallbackFinder = DeferredImportCallbackFinder()
# Insert the DeferredImportCallbackFinder at the beginning of the
# sys.meta_path to that it is found before the standard finders (so that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# sys.meta_path to that it is found before the standard finders (so that
# sys.meta_path so that it is found before the standard finders (so that

Copy link
Member

@blnicho blnicho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found one typo but otherwise this looks great

pyomo/common/dependencies.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 94.31818% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 88.44%. Comparing base (26e4970) to head (46bfee3).
Report is 13 commits behind head on main.

Files Patch % Lines
pyomo/common/dependencies.py 94.11% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3167      +/-   ##
==========================================
+ Coverage   88.38%   88.44%   +0.06%     
==========================================
  Files         846      846              
  Lines       94857    95473     +616     
==========================================
+ Hits        83835    84443     +608     
- Misses      11022    11030       +8     
Flag Coverage Δ
linux 86.33% <94.31%> (+<0.01%) ⬆️
osx 75.73% <94.31%> (+<0.01%) ⬆️
other 86.53% <94.31%> (+0.01%) ⬆️
win 83.82% <94.31%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jsiirola jsiirola merged commit 2954417 into Pyomo:main Feb 29, 2024
33 checks passed
@jsiirola jsiirola deleted the auto-module-import-callbacks branch February 29, 2024 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants