Repository navigation
Deduplicate the optional FigureWidget import in graph_objects codegen #5850
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
Open
DawnofGenX
wants to merge
1
commit into
plotly:main
Choose a base branch
from
DawnofGenX:dedupe-figurewidget-codegen-5849
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+85
−38
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
tests/test_core/test_figure_widget_backend/test_figurewidget_reexport.py
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please remove this test? It seems like overkill. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # ruff: noqa: F401 F403 F405 | ||
| """ | ||
| Regression test for plotly/plotly.py#5849. | ||
|
|
||
| The optional ``FigureWidget`` import block (the ``try: import ipywidgets`` / | ||
| ``missing_*`` fallback) must live only in ``plotly/graph_objs/__init__.py``. | ||
| ``plotly/graph_objects/__init__.py`` must re-export ``FigureWidget`` from | ||
| ``graph_objs`` like every other class, instead of duplicating that block. | ||
|
|
||
| These tests fail on unmodified master, where the block is emitted into both | ||
| generated files. | ||
| """ | ||
|
|
||
| import os | ||
| import os.path as opath | ||
| import subprocess | ||
| import sys | ||
|
|
||
| import plotly | ||
| import plotly.graph_objects as go | ||
| import plotly.graph_objs as go2 | ||
| from plotly.missing_anywidget import FigureWidget as FigureWidgetMissingAnywidget | ||
|
|
||
|
|
||
| def test_figurewidget_is_reexported_from_graph_objs(): | ||
| # (a) graph_objects.FigureWidget is the same object as | ||
| # graph_objs.FigureWidget: it is re-exported, not imported separately. | ||
| assert go.FigureWidget is go2.FigureWidget | ||
|
|
||
|
|
||
| def test_figurewidget_fallback_when_ipywidgets_missing(): | ||
| # (b) With the ipywidgets import forced to fail, graph_objects.FigureWidget | ||
| # still resolves to the missing_* fallback owned by graph_objs. This runs | ||
| # in a subprocess so it holds whether or not ipywidgets is installed. | ||
| script = ( | ||
| "import sys\n" | ||
| "sys.modules['ipywidgets'] = None\n" | ||
| "import plotly.graph_objects as go\n" | ||
| "from plotly.missing_anywidget import FigureWidget as Missing\n" | ||
| "assert go.FigureWidget is Missing, " | ||
| "f'expected missing_* fallback, got {go.FigureWidget!r}'\n" | ||
| "print('ok')\n" | ||
| ) | ||
| result = subprocess.run( | ||
| [sys.executable, "-c", script], | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
| assert result.returncode == 0, ( | ||
| f"forced-failure fallback check failed:\n" | ||
| f"stdout: {result.stdout}\nstderr: {result.stderr}" | ||
| ) | ||
| assert "ok" in result.stdout | ||
|
|
||
|
|
||
| def test_no_duplicate_ipywidgets_block_in_graph_objects(): | ||
| # (c) The optional ipywidgets import block must not be duplicated in | ||
| # graph_objects/__init__.py; it belongs only in graph_objs/__init__.py. | ||
| plotly_root = opath.dirname(plotly.__file__) | ||
| go_init = opath.join(plotly_root, "graph_objects", "__init__.py") | ||
| with open(go_init) as f: | ||
| go_source = f.read() | ||
| assert "import ipywidgets" not in go_source, ( | ||
| "graph_objects/__init__.py still contains a duplicated " | ||
| "optional ipywidgets import block" | ||
| ) | ||
| assert "missing_anywidget" not in go_source, ( | ||
| "graph_objects/__init__.py still references the missing_* fallback " | ||
| "directly instead of re-exporting FigureWidget from graph_objs" | ||
| ) | ||
|
|
||
| # The block must still be present in graph_objs/__init__.py. | ||
| go2_init = opath.join(plotly_root, "graph_objs", "__init__.py") | ||
| with open(go2_init) as f: | ||
| go2_source = f.read() | ||
| assert "import ipywidgets" in go2_source | ||
| assert "missing_anywidget" in go2_source |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please revert these changes? This is an internal update and doesn't need a changelog entry.