8000 Imports in top-level __init__.py cause eager loading of most enterprise_gateway code · Issue #960 · jupyter-server/enterprise_gateway · GitHub
[go: up one dir, main page]

Skip to content
Imports in top-level __init__.py cause eager loading of most enterprise_gateway code #960
@telamonian

Description

@telamonian

The top level enterprise_gateway.__init__.py contains a couple of imports that get fired whenever someone imports enterprise_gateway or anything below:

https://github.com/jupyter/enterprise_gateway/blob/443708ffb4cac466fb43e6daccddcdf24aed1945/enterprise_gateway/__init__.py#L4-L5

The from ._version... line is harmless, but the from .enterprisegatewayapp import launch_instance is problematic. Basically, the import from enterprisegatewayapp in turn imports most the rest of the code in the enterprise_gateway pkg, which causes some issues:

  • Can help cause large slowdowns when fetching install-wide pkg metadata, eg a particular group of entry points
    • discussed extensively in this ongoing PR about extending entry points to expose jupyter plugins and other resources
  • it breaks monkey-patching
    • while not best practice, is currently required for eg overriding builtin TokenAuthorizationMixin

and last (maybe least?)

  • it goes against the zen of python

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0