Skip to content

Remove unnecessary imports from __init__.py files #181

@yguclu

Description

@yguclu

Problem Description

Importing modules from SymPDE is slow and should be speeded up.

One of the reasons is that (almost) all of our __init__.py files import everything from our subpackages and modules. For example, file sympde/__init__.py reads

from .version             import __version__
from .old_sympy_utilities import with_metaclass
from .core                import *
from .topology            import *
from .exterior            import *
from .printing            import *
from .utilities           import *

and file sympde/topology/__init__.py reads

from .basic              import *
from .derivatives        import *
from .datatype           import *
from .domain             import *
from .mapping            import *
from .measure            import *
from .space              import *
from .analytical_mapping import *
from .callable_mapping   import *

This approach was meant to allow the user to import the relevant objects from the main sympde package without the need to know their exact location. The side effect is a very slow import time.

Suggested Solution

Step 1: Create sympde/api/__init__.py

Create an api subpackage which allows direct import of the relevant object, e.g.

from sympde.api import Cube, Mapping, Constant
from sympde.api import ScalarFunctionSpace, VectorFunctionSpace, elements_of
from sympde.api import BilinearForm, LinearForm, Norm
from sympde.api import ...

The user could even use from sympde.api import * safely, if they wanted to.

The folder sympde/api/ should contain one single file, __init__.py, which would import the relevant objects from their precise location using the full path:

from sympde.topology.domain import Domain, NCube, Line, Square, Cube, NormalVector
from sympde.topology.mapping import Mapping
from sympde.topology.space  import element_of, elements_of, Derham, ScalarFunctionSpace, VectorFunctionSpace
...

from sympde.core.basic import Constant
...

from sympde.expr.expr import BilinearForm, LinearForm, Norm
...

Step 2: Clean up all __init__.py files

With the exception of sympde/api/__init__.py above, every other __init__.py file should be totally empty. This will necessarily break the PSYDAC library, therefore we will have to release a new version of SymPDE on PyPI.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions