Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Make Dash Pages & packages play nice & experimenting with clearing Pages registry #2271

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@ def _get_skip(text, divider=2):
no_update = _callback.NoUpdate() # pylint: disable=protected-access


def init_dash_globals():
"""Ensure that all Dash global state is re-initialised."""
_pages.PAGE_REGISTRY.clear()

# this line of thinking could be extended to potentially clear the following:
# _pages.CONFIG
# _get_paths.CONFIG
# _callback.GLOBAL_CALLBACK_MAP
# _callback.GLOBAL_CALLBACK_LIST
# _callback.GLOBAL_INLINE_SCRIPTS


# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments, too-many-locals
class Dash:
Expand Down Expand Up @@ -380,6 +392,8 @@ def __init__( # pylint: disable=too-many-statements
url_base_pathname, routes_pathname_prefix, requests_pathname_prefix
)

init_dash_globals()

self.config = AttributeDict(
name=name,
assets_folder=os.path.join(
Expand Down Expand Up @@ -2008,7 +2022,7 @@ def _import_layouts_from_pages(self):
self.pages_folder.replace("\\", "/").lstrip("/").replace("/", ".")
)

module_name = ".".join([pages_folder, page_filename])
module_name = ".".join([self.config.name, pages_folder, page_filename])

spec = importlib.util.spec_from_file_location(
module_name, os.path.join(root, file)
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/multi_page/test_pages_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,11 @@ def test_pala003_meta_tags_custom(dash_duo):


def test_pala004_no_layout_exception():
error_msg = 'No layout found in module pages_error.no_layout_page\nA variable or a function named "layout" is required.'
error_msg = 'No layout found in module test_pages_layout.pages_error.no_layout_page\nA variable or a function named "layout" is required.'

with pytest.raises(NoLayoutException) as err:
Dash(__name__, use_pages=True, pages_folder="pages_error")

# clean up after this test, so the broken entry doesn't affect other pages tests
del dash.page_registry["pages_error.no_layout_page"]
del dash.page_registry["test_pages_layout.pages_error.no_layout_page"]

assert error_msg in err.value.args[0]
16 changes: 8 additions & 8 deletions tests/integration/multi_page/test_pages_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def test_paor001_order(dash_duo):
"multi_layout3",
"multi_layout2",
"multi_layout1",
"pages.defaults",
"pages.metas",
"pages.not_found_404",
"pages.page1",
"pages.page2",
"pages.path_variables",
"pages.query_string",
"pages.redirect",
"test_pages_order.pages.defaults",
"test_pages_order.pages.metas",
"test_pages_order.pages.not_found_404",
"test_pages_order.pages.page1",
"test_pages_order.pages.page2",
"test_pages_order.pages.path_variables",
"test_pages_order.pages.query_string",
"test_pages_order.pages.redirect",
]

dash_duo.start_server(app)
Expand Down