Skip to content

Importing in __init__.py #491

@hiker

Description

@hiker

When I created the tool directory, I've added imports in __init__py, to allow a shorter path to import tools, i.e. from fab.tools import Compiler instead of from fab.tools.compiler import Compiler. We have used this extensively in PSyclone.

But, with the more thorough typing that Fab is using (we are only now starting to add this in PSyclone), we are getting more and more cyclic import problems, which need to be avoided using:

  • imports not at top of the file
  • using if TYPE_CHECKING

We are noticing the same issues in PSyclone now that we are using more typing :)

@MatthewHambley has already done some work on importing with the longer paths in Fab. At the same time, I think it would be convenient for a user script to have shorter paths, and be independent of the actual location of files.

Question: would it be worth to investigate:

  1. Removing all imports in __init__.py directories, and change any imports in Fab to use the full path.
  2. Add a new api directory, which just contains a __init__.py script that imports all classes and functions that a user (typically) needs. We might not be able to really cover all cases (since we don't control what user might want to do), but I would hope that we can cover a majority of the typical use cases.

A user script would then use:

from fap.api import compile_fortran, find_source_files, link_exe
....

Before I try if this makes sense, I would love to get some feedback (@yaswant , @MatthewHambley , @jasonjunweilyu , @t00sa @Pierre-siddall )

Metadata

Metadata

Assignees

No one assigned

    Labels

    in progressSomeone is actively working on this issue

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions