Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/twenty-moles-slide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'modelscope_studio': patch
---

fix: bugfix in dev mode
6 changes: 1 addition & 5 deletions backend/modelscope_studio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from .components.antd.components import *
from .components.antdx.components import *
from .components.base import *
from .components.legacy.components import *
from .components.pro.components import *
from .components import *
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a wildcard import (from .components import *) is generally discouraged as it can make it unclear which names are present in the namespace, potentially causing confusion and making the code harder to maintain.1

Style Guide References

Footnotes

  1. PEP 8 advises against wildcard imports (from <module> import *) because they make it unclear which names are present in the namespace. This can confuse both human readers and automated tools.

from .external import load
from .version import __version__
5 changes: 5 additions & 0 deletions backend/modelscope_studio/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .antd.components import *
from .antdx.components import *
from .base import *
from .legacy.components import *
from .pro.components import *
Comment on lines +1 to +5
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This new __init__.py file centralizes component imports, but it uses multiple wildcard imports (from ... import *). This practice is discouraged by PEP 8 because it pollutes the namespace and hides which names are being exported.1 It can make debugging and code navigation difficult. Consider defining __all__ in each submodule and then explicitly importing and re-exporting them here to create a clear public API for the components package.

Style Guide References

Footnotes

  1. PEP 8 advises against wildcard imports (from <module> import *) because they make it unclear which names are present in the namespace. This can confuse both human readers and automated tools. Using __all__ is the recommended way to define a module's public API.

4 changes: 3 additions & 1 deletion docs/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from helper.Site import Site
from legacy_app import legacy_demo

is_dev = os.environ.get("GRADIO_WATCH_MODULE_NAME") == 'docs.app'


def get_text(text: str, cn_text: str):
if is_modelscope_studio:
Expand Down Expand Up @@ -572,7 +574,7 @@ def more_components():
"label": get_text("Version 0.x", "0.x 版本"),
"key": "legacy",
"content": legacy_demo
},
} if not is_dev else None,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This conditional logic to add None to the list works, but it makes the code less direct. The Site class now has to be aware of and filter out these None values. A cleaner approach would be to conditionally append the entire dictionary to the tabs list after its initial definition. This would keep the logic for constructing the tabs list self-contained and avoid passing None values around.

For example:

# After defining the main `tabs` list...
if not is_dev:
    tabs.append({
        "label": get_text("Version 0.x", "0.x 版本"),
        "key": "legacy",
        "content": legacy_demo
    })

This would remove the need for this inline conditional and the corresponding filtering logic in the Site constructor.

]

site = Site(
Expand Down
2 changes: 1 addition & 1 deletion docs/helper/Site.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self,
docs: dict,
default_active_tab: str | None = None,
logo: Component | Callable | None = None):
self.tabs = tabs
self.tabs = [tab for tab in tabs if tab]
self.docs = docs
self.default_active_tab = default_active_tab
self.default_active_tab_item = next(
Expand Down