Skip to content

Fix init imports - #5413

Open
nwng04 wants to merge 28 commits into
mainfrom
nwng04/fix-init-imports
Open

Fix init imports#5413
nwng04 wants to merge 28 commits into
mainfrom
nwng04/fix-init-imports

Conversation

@nwng04

@nwng04 nwng04 commented Sep 1, 2026

Copy link
Copy Markdown

Description

Fixes #4736.

This PR adds __all__ to the Firedrake __init__.py file, refining the imported objects when from firedrake import * is used.

Removed Objects:
['slope_limiter', 'eigensolver', 'parloops', 'function', 'matrix_free', 'configuration', 'hdivcurl', 'mixedelement', 'PETSC_SUPPORTED_VERSIONS', 'ensemble', 'linear_solver', 'elementlist', 'setup_cache_dirs', 'checkpointing', 'utility_meshes', 'enrichedelement', 'functionspaceimpl', 'output', 'finiteelement', 'progress_bar', 'halo', 'slate', 'dmhooks', 'tsfc_interface', 'logging', 'ufl_expr', 'randomfunctiongen', 'projection', 'solving_utils', 'pointeval_utils', 'solving', 'cython', 'mg', 'functionspace', 'brokenelement', 'pyplot', 'functionspacedata', 'init_petsc', 'adjoint_utils', 'deflation', 'pointquery_utils', 'restrictedelement', 'constant', 'external_operators', 'tensorproductelement', 'matrix', 'norms', 'finiteelementbase', 'extrusion_utils', 'mesh', 'cofunction', 'exceptions', 'embedding', 'variational_solver', 'firedrake', 'interpolation', 'nullspace', 'bcs', 'formmanipulation', 'preconditioners']

Added Object: 'utils'
This object is added because 9 Firedrake tests use it when testing.

@nwng04 nwng04 changed the title Nwng04/fix init imports Fix init imports Sep 1, 2026

@connorjward connorjward left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

utils = SpikedModule("utils")
__all__ += ["utils"]

class SpikedModule:
  def __getattr__(self, key):
    raise SomeException

Comment thread firedrake/__init__.py Outdated
@connorjward
connorjward marked this pull request as ready for review September 1, 2026 16:03
Comment thread firedrake/__init__.py Outdated
from firedrake.petsc import PETSc # noqa: F401
__all__ += ["PETSc"]

from firedrake.assemble import assemble # noqa: F401

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think # noqa: F401 is no longer needed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because it's in __all__? I would be surprised if that counts as a used import.

Comment thread firedrake/__init__.py
Comment on lines +294 to +297
__all__ += ["set_level", "set_log_handlers", "set_log_level", "DEBUG", "INFO",
"WARNING", "ERROR", "CRITICAL", "log", "debug", "info", "warning", "error",
"critical", "info_red", "info_green", "info_blue", "RED", "GREEN", "BLUE"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want these in the public API?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would say no, but I also think that that is out of scope of this PR as it introduces a whole new set of breaking changes.

Comment thread firedrake/__init__.py
Comment thread firedrake/__init__.py
Comment on lines +294 to +297
__all__ += ["set_level", "set_log_handlers", "set_log_level", "DEBUG", "INFO",
"WARNING", "ERROR", "CRITICAL", "log", "debug", "info", "warning", "error",
"critical", "info_red", "info_green", "info_blue", "RED", "GREEN", "BLUE"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would say no, but I also think that that is out of scope of this PR as it introduces a whole new set of breaking changes.

Comment thread firedrake/__init__.py Outdated
del _plot


class SpikedModule:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can this get a docstring and be moved in _deprecation.py?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add __all__ to Firedrake __init__.py

4 participants