Skip to content

Commit

Permalink
feat: keep same module structure for generated python code
Browse files Browse the repository at this point in the history
  • Loading branch information
mariobuikhuizen committed Nov 1, 2023
1 parent d7abb21 commit d438c4f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 32 deletions.
2 changes: 1 addition & 1 deletion generate_source/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ if ! test -d "vuetify"; then
cd ..
fi
python generate_code.py
pre-commit run --files ../ipyvuetify/vuetify_widgets.py ../js/src/Widgets.js
pre-commit run --files ../ipyvuetify/generated.py ../js/src/Widgets.js
30 changes: 25 additions & 5 deletions generate_source/generate_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,29 @@ class {name[1:]}(VuetifyWidget):
def generate_python():
code = textwrap.dedent(
"""\
from traitlets import Unicode, Union, Float, List as TList, Dict, Bool, Any
from .vuetify_widget import VuetifyWidget
from ipyvue import VueWidget
from traitlets import Any, Bool, Dict, Float, Unicode, Union
from traitlets import List as TList
from ._version import semver
class VuetifyWidget(VueWidget):
_model_name = Unicode("VuetifyWidgetModel").tag(sync=True)
_view_name = Unicode("VuetifyView").tag(sync=True)
_view_module = Unicode("jupyter-vuetify").tag(sync=True)
_model_module = Unicode("jupyter-vuetify").tag(sync=True)
_view_module_version = Unicode(semver).tag(sync=True)
_model_module_version = Unicode(semver).tag(sync=True)
_metadata = Dict(default_value=None, allow_none=True).tag(sync=True)
"""
Expand All @@ -117,7 +137,7 @@ def generate_python():

code += textwrap.dedent(
f"""\
__all__ = ["{'", "'.join([name[1:] for name, _ in components])}"]
__all__ = ["VuetifyWidget", "{'", "'.join([name[1:] for name, _ in components])}"]
"""
)

Expand Down Expand Up @@ -184,7 +204,7 @@ def generate_js():
return code


with open("../ipyvuetify/vuetify_widgets.py", "w") as f:
with open("../ipyvuetify/generated.py", "w") as f:
f.write(generate_python())

with open("../js/src/Widgets.js", "w") as f:
Expand Down
2 changes: 1 addition & 1 deletion ipyvuetify/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ._version import __version__
from .generated import * # noqa: F403
from .Html import Html
from .Themes import theme
from .vuetify_widgets import * # noqa: F403
from .VuetifyTemplate import VuetifyTemplate


Expand Down
21 changes: 20 additions & 1 deletion ipyvuetify/vuetify_widgets.py → ipyvuetify/generated.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
from ipyvue import VueWidget
from traitlets import Any, Bool, Dict, Float, Unicode, Union
from traitlets import List as TList

from .vuetify_widget import VuetifyWidget
from ._version import semver


class VuetifyWidget(VueWidget):

_model_name = Unicode("VuetifyWidgetModel").tag(sync=True)

_view_name = Unicode("VuetifyView").tag(sync=True)

_view_module = Unicode("jupyter-vuetify").tag(sync=True)

_model_module = Unicode("jupyter-vuetify").tag(sync=True)

_view_module_version = Unicode(semver).tag(sync=True)

_model_module_version = Unicode(semver).tag(sync=True)

_metadata = Dict(default_value=None, allow_none=True).tag(sync=True)


class Alert(VuetifyWidget):
Expand Down Expand Up @@ -6705,6 +6723,7 @@ class WindowItem(VuetifyWidget):


__all__ = [
"VuetifyWidget",
"Alert",
"AlertTitle",
"App",
Expand Down
24 changes: 0 additions & 24 deletions ipyvuetify/vuetify_widget.py

This file was deleted.

0 comments on commit d438c4f

Please sign in to comment.