Coder Social home page Coder Social logo

Comments (7)

Hoxbro avatar Hoxbro commented on September 26, 2024 1

What happens if you, do this?

from lazy_loader import extension, pn

extension()

pn.template.FastListTemplate(title="Hello", main=["world"]).servable()

from panel.

Hoxbro avatar Hoxbro commented on September 26, 2024 1

Lazy loading is tricky. Maybe try to take a look at how polars does it here: https://github.com/pola-rs/polars/blob/main/py-polars/polars/dependencies.py

from panel.

MarcSkovMadsen avatar MarcSkovMadsen commented on September 26, 2024

The problem is that template is not imported in __init__.py :-) I'm working on a PR. But I need to figure out how to add test first.

from panel.

MarcSkovMadsen avatar MarcSkovMadsen commented on September 26, 2024
from lazy_loader import extension, pn

extension()

pn.template.FastListTemplate(title="Hello", main=["world"]).servable()

The problem is still there.

from panel.

MarcSkovMadsen avatar MarcSkovMadsen commented on September 26, 2024

This pytest will replicate issue

import importlib.util
import sys

def lazy_import(name):
    spec = importlib.util.find_spec(name)
    loader = importlib.util.LazyLoader(spec.loader)
    spec.loader = loader
    module = importlib.util.module_from_spec(spec)
    sys.modules[name] = module
    loader.exec_module(module)
    return module

def test_pn_template():
    lazy_import("panel")
    import panel as pn
    assert hasattr(pn, "template")

from panel.

MarcSkovMadsen avatar MarcSkovMadsen commented on September 26, 2024

Additional Context: Also issue for static analysis

The cause is that template is not imported in __init__. This also means that static analysis cannot discover it and an error is highlighted like below.

image

from panel.

MarcSkovMadsen avatar MarcSkovMadsen commented on September 26, 2024

Thanks @philippjfr

Unfortunately I start seeing more of these issues. If I lazy import holoviews then it starts failing because of below.

image

Do you think these are issues that can and should be solved? Or are they not issues and I should not try to use lazy loading?

I would really like to lazy load panel and holoviews as they add 3s to import time! And that is a lot of import time in a cli tool or if users are constantly running script that imports these packages.

I think these issue would have been identified if we where running mypy on the code base.

from panel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.