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

Pages.py rewrite #69

Closed
wants to merge 1 commit into from
Closed

Pages.py rewrite #69

wants to merge 1 commit into from

Conversation

ruxi
Copy link

@ruxi ruxi commented Dec 28, 2021

I refactored Pages.py to use absolute paths. The motivation of the enable interactive work when not at the package root . Please kindly review and consider

---------------------
InstallPluginToModule
---------------------
attaches plug-in methods either
(i) directly to module (dash) - (original behaviour),
or
(ii) add namespace to module with methods - (new behaviour)

i.e.

example 1:
InstallPluginToModule(dash, namespace = 'pages')  -(creates)->
    dash.pages
        |_ .register_pages
        |_ {registry}

example 2:
InstallPluginToModule(dash, namespace = None)  -(creates)->
    dash
        |_ .register_pages
        |_ {registry}

rationale:
    easier to make namespace changes using a factory.

----------------------------------------------
PageRegistryRecord & inject_record_to_registry
----------------------------------------------
refactored `register_page`

the task of creating registry records and
injecting the data to the registry is decoupled
for portability

`PageRegistryRecord` is the dataclass schema
`inject_record_to_registry` is a decorator

----------------
AutoRegisterPage
----------------
The auto-import function from `plug` was split off to
`AutoRegisterPage`, added option to configure PAGES_PATH

-----------
other notes
-----------
_match_case_filename_image_table 
    requires py3.10 since it uses the new pattern matching syntax
    (did it for learning purposes)

The original is in archive/pages_original.py.

Motivation for the re-write is to enable interactive
    dev work not at the package root. This was addressed
    by using absolute paths instead of relative paths
    when appropriate, and adding more options for users
    to set the path configuration

    ---------------------
    InstallPluginToModule
    ---------------------
    attaches plug-in methods either
    (i) directly to module (dash) - (original behaviour),
    or
    (ii) add namespace to module with methods - (new behaviour)

    i.e.

    example 1:
    InstallPluginToModule(dash, namespace = 'pages')  -(creates)->
        dash.pages
            |_ .register_pages
            |_ {registry}

    example 2:
    InstallPluginToModule(dash, namespace = None)  -(creates)->
        dash
            |_ .register_pages
            |_ {registry}

    rationale:
        easier to make namespace changes using a factory.

    ----------------------------------------------
    PageRegistryRecord & inject_record_to_registry
    ----------------------------------------------
    refactored `register_page`

    the task of creating registry records and
    injecting the data to the registry is decoupled
    for portability

    `PageRegistryRecord` is the dataclass schema
    `inject_record_to_registry` is a decorator

    ----------------
    AutoRegisterPage
    ----------------
    The auto-import function from `plug` was split off to
    `AutoRegisterPage`, added option to configure PAGES_PATH

    -----------
    other notes
    -----------
    _match_case_filename_image_table 
        requires py3.10 since it uses the new pattern matching syntax
        (did it for learning purposes)

Modified pages_plugin.py by AnnMarieW (plotly, dash-labs):

Reference:
 - 
https://github.com/plotly/dash-labs/blob/main/dash_labs/plugins/pages.py
 - https://github.com/plotly/dash-multi-page-app-plugin
@ruxi ruxi marked this pull request as draft December 28, 2021 14:06
@AnnMarieW
Copy link
Collaborator

Hi @ruxi

Thanks for this PR. However, I'm not sure what you mean by "enable interactive work when not at the package root". Could you please elaborate and provide some examples? Can you say more about your use-case?

@AnnMarieW
Copy link
Collaborator

Hi @ruxi
There is now a pull request to move pages to dash and further development on the pages feature will continue there. I'll be closing this PR, but if you still have an issue, please feel free to comment on the pull request in Dash.

@AnnMarieW AnnMarieW closed this Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants