Fail nicely when trying to use petsc4py methods without petsc4py available - #6
Merged
Conversation
JHopeCollins
requested changes
Jul 14, 2025
JHopeCollins
left a comment
Member
There was a problem hiding this comment.
This is a very good addition, thanks @connorjward.
I just have one suggestion to improve the error message even further, other than that I think it's good to go.
For the record, if I "forget" to pass --no-build-isolation with the current petsctools main branch then I get this error:
AttributeError: module 'petsctools' has no attribute 'init'
error: subprocess-exited-with-error
× Getting requirements to build editable did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
Whereas if I "forget" using this branch then I get:
ImportError: Cannot load 'init' from module 'petsctools' because petsc4py is not available
error: subprocess-exited-with-error
× Getting requirements to build editable did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
Co-authored-by: Josh Hope-Collins <jhc.jss@gmail.com>
JHopeCollins
approved these changes
Jul 14, 2025
JHopeCollins
left a comment
Member
There was a problem hiding this comment.
I fixed a syntax error in my suggestion. LGTM now.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is particularly important for when someone forgets to pass
--no-build-isolationwhen pip installing firedrake (or some other downstream library). Ifpetsc4pyisn't in the isolated build environment then you get an unhelpful missing attribute error forpetsctools.init, which doesn't explain whyinitis missing`.