Skip to content

Commit

Permalink
Fix docs (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
bollwyvl authored Aug 30, 2024
1 parent e376923 commit 48a68f7
Show file tree
Hide file tree
Showing 10 changed files with 2,198 additions and 3,013 deletions.
2 changes: 1 addition & 1 deletion examples/files/02_python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.5"
}
},
"nbformat": 4,
Expand Down
35 changes: 18 additions & 17 deletions examples/files/04_sqlalchemy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,44 @@
"source": [
"from __future__ import annotations\n",
"\n",
"import pprint\n",
"import sys\n",
"from pathlib import Path\n",
"\n",
"if __name__ == \"__main__\" and \"pyodide\" in sys.modules:\n",
" %pip install -r requirements.txt"
" %pip install -r requirements-sqlalchemy.txt"
]
},
{
"cell_type": "markdown",
"id": "33e83b0e-748f-4e6b-8865-a954400123d4",
"id": "90958bc5-a0e7-454a-9784-e354204864a4",
"metadata": {},
"source": [
"## Demoing\n",
"## Configuring\n",
"\n",
"Using the excellent [ipylab](https://github.com/jtpio/ipylab), this example will use a single `Pyinstrument` attached to the left side of the document with the 🔭 icon. "
"This `Pyinstrument` sets a higher-resolution `interval`, and an `output_path`, which will save the history."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cc09d042-4dea-4809-965f-47577f98ce85",
"id": "bf933e40-9254-4acb-a697-41d286f68853",
"metadata": {},
"outputs": [],
"source": [
"import pprint\n",
"from pathlib import Path\n",
"from ipyprofiler import Pyinstrument\n",
"\n",
"from ipylab import Icon, JupyterFrontEnd, Panel\n",
"\n",
"from ipyprofiler import Pyinstrument"
"ps = Pyinstrument(interval=0.001, output_folder=Path(\"_pyinstrument_sqlalchemy\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "15889439-e625-44c9-8189-291e2e8fa117",
"cell_type": "markdown",
"id": "00dfb991-7ea8-4d45-a9f2-a97b25f52ebb",
"metadata": {},
"outputs": [],
"source": [
"ps = Pyinstrument(interval=0.001, output_folder=Path(\"_pyinstrument_sqlalchemy\"))"
"## Demoing\n",
"\n",
"Using the excellent [ipylab](https://github.com/jtpio/ipylab), this example will attach the `Pyinstrument` to the left area of the application with the 🔭 icon. "
]
},
{
Expand All @@ -69,6 +68,8 @@
"metadata": {},
"outputs": [],
"source": [
"from ipylab import Icon, JupyterFrontEnd, Panel\n",
"\n",
"app = JupyterFrontEnd()\n",
"panel: Panel = locals().get(\"panel\")\n",
"if panel:\n",
Expand All @@ -80,7 +81,7 @@
" \"\"\"</svg>\"\"\"\n",
")\n",
"panel.title.icon = Icon(name=\"ipyprofiler\", svgstr=svgstr)\n",
"app.shell.add(panel, \"right\")\n",
"app.shell.add(panel, \"right\", {\"rank\": 0})\n",
"app.shell.expand_right()"
]
},
Expand Down Expand Up @@ -279,7 +280,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.5"
}
},
"nbformat": 4,
Expand Down
3 changes: 3 additions & 0 deletions examples/files/requirements-sqlalchemy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-r requirements.txt
ipylab
sqlalchemy
5 changes: 2 additions & 3 deletions examples/files/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ipylab
ipyprofiler[pyinstrument]
ipywidgets
sqlalchemy
ipywidgets==8.1.3
widgetsnbextension==4.0.11
5,133 changes: 2,150 additions & 2,983 deletions pixi.lock

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -514,20 +514,23 @@ pytest-html = "*"
nbconvert-core = "*"
ansi2html = "*"

[feature.deps-lite.dependencies]
ipywidgets = "8.1.3"
jupyterlab_widgets = "3.0.12"
jupyterlite-core = "0.4.*"
jupyterlite-pyodide-kernel = "0.4.*"
python-libarchive-c = "*"

[feature.deps-docs.dependencies]
ipywidgets = "*"
jupyterlite-core = "0.3.*"
jupyterlite-pyodide-kernel = "0.3.*"
myst-nb = "*"
pydata-sphinx-theme = "*"
python-libarchive-c = "*"

# envs ########################################################################

[environments]
build = ["deps-build", "deps-dist", "deps-lab", "deps-node", "deps-run", "tasks-build"]
lint = ["deps-lint", "deps-node", "deps-lab", "tasks-lint"]
docs = ["deps-docs", "deps-lab", "deps-build", "tasks-docs"]
docs = ["deps-docs", "deps-lab", "deps-build", "tasks-docs", "deps-lite"]
lab = [
"deps-build",
"deps-dist",
Expand Down
12 changes: 10 additions & 2 deletions src/ipyprofiler/widget_pyinstrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,18 @@ def ui(self, **kwargs: Any) -> W.VBox:

def history(self) -> W.Select:
"""Build and link a history navigator."""
dropdown = W.Select(description="profiles", rows=1)
dropdown = W.Select(description="profile", rows=1)

T.dlink(
(self, "_history"),
(dropdown, "options"),
lambda h: {hi.name: hi for hi in h},
)
T.dlink(
(self, "_history"),
(dropdown, "value"),
lambda h: h[-1] if h else None,
)
T.dlink(
(dropdown, "value"),
(self._profile, "value"),
Expand Down Expand Up @@ -171,7 +176,10 @@ def archive(self, new_json: str) -> None:
path = self.output_folder / filename
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(new_json, **UTF8)
self._history += (HistoryItem(path=path, name=self.name, value=new_json),)
self._history = (
*self._history,
HistoryItem(path=path, name=self.name, value=new_json),
)

@T.default("_profiler")
def _default_profiler(self) -> Profiler:
Expand Down
4 changes: 4 additions & 0 deletions style/widget.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
overflow-y: hidden;
}

.jprf-Pyinstrument .jupyter-widget-TabPanel {
margin: 0;
}

.jprf-Pyinstrument .jupyter-widgets.widget-tab .widget-tab-contents {
padding: 0;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def a_notebook(request: pytest.FixtureRequest) -> Path:
return EXAMPLES / f"{request.param}"


@pytest.fixture()
@pytest.fixture
def a_notebook_exporter() -> Generator[nbconvert.NotebookExporter, None, None]:
"""Provide an executing notebook exporter."""
env_patch = {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_callgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pytest


@pytest.fixture()
@pytest.fixture
def a_callgraph() -> Callgraph:
"""Provide a callgraph."""
from ipyprofiler import Callgraph
Expand Down

0 comments on commit 48a68f7

Please sign in to comment.