diff --git a/.gitattributes b/.gitattributes index a4bfadf61679d0c7a22e4ebd9ed9cfc7bf33f142..a007cf34c6d68be91c474b941e88cea1522fd767 100644 --- a/.gitattributes +++ b/.gitattributes @@ -969,3 +969,4 @@ parrot/lib/python3.10/html/__pycache__/entities.cpython-310.pyc filter=lfs diff= vllm/lib/python3.10/site-packages/pandas/tests/io/__pycache__/test_sql.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text vllm/lib/python3.10/site-packages/pandas/tests/indexing/__pycache__/test_loc.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text vllm/lib/python3.10/site-packages/pandas/tests/tools/__pycache__/test_to_datetime.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text +videollama2/lib/python3.10/site-packages/fontTools/feaLib/lexer.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text diff --git a/parrot/share/terminfo/r/rbcomm b/parrot/share/terminfo/r/rbcomm new file mode 100644 index 0000000000000000000000000000000000000000..2f5cd2939de25682e63c588b16a18f6ebd0ede0f Binary files /dev/null and b/parrot/share/terminfo/r/rbcomm differ diff --git a/parrot/share/terminfo/r/regent100 b/parrot/share/terminfo/r/regent100 new file mode 100644 index 0000000000000000000000000000000000000000..4893c8457fc48ab3171193fe748b14ee488a3628 Binary files /dev/null and b/parrot/share/terminfo/r/regent100 differ diff --git a/parrot/share/terminfo/t/t10 b/parrot/share/terminfo/t/t10 new file mode 100644 index 0000000000000000000000000000000000000000..ccd7c1a024bbf0c869d3a37dc34643f3d2d4e9d3 Binary files /dev/null and b/parrot/share/terminfo/t/t10 differ diff --git a/parrot/share/terminfo/t/t3800 b/parrot/share/terminfo/t/t3800 new file mode 100644 index 0000000000000000000000000000000000000000..75bff1e52f0a0f78e0cf52be311104f35aec4dc1 Binary files /dev/null and b/parrot/share/terminfo/t/t3800 differ diff --git a/parrot/share/terminfo/t/tab132 b/parrot/share/terminfo/t/tab132 new file mode 100644 index 0000000000000000000000000000000000000000..95ba77bdd3d794cfd6e2d4c80421622f6e4270b8 Binary files /dev/null and b/parrot/share/terminfo/t/tab132 differ diff --git a/parrot/share/terminfo/t/tek b/parrot/share/terminfo/t/tek new file mode 100644 index 0000000000000000000000000000000000000000..0ccfcb92efc1bc0c647e77805de465def4c19a43 Binary files /dev/null and b/parrot/share/terminfo/t/tek differ diff --git a/parrot/share/terminfo/t/tek4013 b/parrot/share/terminfo/t/tek4013 new file mode 100644 index 0000000000000000000000000000000000000000..7b2f7e0b18c980c115b510f0b4bc2d8c56247c23 Binary files /dev/null and b/parrot/share/terminfo/t/tek4013 differ diff --git a/parrot/share/terminfo/t/tek4014 b/parrot/share/terminfo/t/tek4014 new file mode 100644 index 0000000000000000000000000000000000000000..e43d86ba48a7991d17e6688fce95c75e8e0e8757 Binary files /dev/null and b/parrot/share/terminfo/t/tek4014 differ diff --git a/parrot/share/terminfo/t/tek4015 b/parrot/share/terminfo/t/tek4015 new file mode 100644 index 0000000000000000000000000000000000000000..4e4c83d68ba56aa71c730ee1bd8ccae944065ad4 Binary files /dev/null and b/parrot/share/terminfo/t/tek4015 differ diff --git a/parrot/share/terminfo/t/tek4025-17-ws b/parrot/share/terminfo/t/tek4025-17-ws new file mode 100644 index 0000000000000000000000000000000000000000..cfe82ff7118a11e42b595baf09d2bdbcc5d8c1bd Binary files /dev/null and b/parrot/share/terminfo/t/tek4025-17-ws differ diff --git a/parrot/share/terminfo/t/tek4025a b/parrot/share/terminfo/t/tek4025a new file mode 100644 index 0000000000000000000000000000000000000000..212081376deaa882c0f41b671955e7abd4dc1ec5 Binary files /dev/null and b/parrot/share/terminfo/t/tek4025a differ diff --git a/parrot/share/terminfo/t/tek4205 b/parrot/share/terminfo/t/tek4205 new file mode 100644 index 0000000000000000000000000000000000000000..71742a952be69dac2ce7f6deb2fb0ef60eebc44f Binary files /dev/null and b/parrot/share/terminfo/t/tek4205 differ diff --git a/parrot/share/terminfo/t/teken-2018 b/parrot/share/terminfo/t/teken-2018 new file mode 100644 index 0000000000000000000000000000000000000000..a9c48db03a8fd00ea8c129cd00ea8c980b9bdc26 Binary files /dev/null and b/parrot/share/terminfo/t/teken-2018 differ diff --git a/parrot/share/terminfo/t/teken-sc b/parrot/share/terminfo/t/teken-sc new file mode 100644 index 0000000000000000000000000000000000000000..1210e0e9b7e0ee0b2fc0eed68ba06fd3436f36d6 Binary files /dev/null and b/parrot/share/terminfo/t/teken-sc differ diff --git a/parrot/share/terminfo/t/terminology-0.6.1 b/parrot/share/terminfo/t/terminology-0.6.1 new file mode 100644 index 0000000000000000000000000000000000000000..99b97b488e0d8f57bb7f4a06d259d6c4be04ae6f Binary files /dev/null and b/parrot/share/terminfo/t/terminology-0.6.1 differ diff --git a/parrot/share/terminfo/t/ti707 b/parrot/share/terminfo/t/ti707 new file mode 100644 index 0000000000000000000000000000000000000000..8c37f2fac7eae6d47b16505ce9447a275aefcbd2 Binary files /dev/null and b/parrot/share/terminfo/t/ti707 differ diff --git a/parrot/share/terminfo/t/tkterm b/parrot/share/terminfo/t/tkterm new file mode 100644 index 0000000000000000000000000000000000000000..15ae411980ebead91ba6454f59526a162b2d9140 Binary files /dev/null and b/parrot/share/terminfo/t/tkterm differ diff --git a/parrot/share/terminfo/t/tn300 b/parrot/share/terminfo/t/tn300 new file mode 100644 index 0000000000000000000000000000000000000000..87c639c630fb257f00cec14b838ba0f6749171ed Binary files /dev/null and b/parrot/share/terminfo/t/tn300 differ diff --git a/parrot/share/terminfo/t/ts100-sp b/parrot/share/terminfo/t/ts100-sp new file mode 100644 index 0000000000000000000000000000000000000000..0128a889f17ece7cb7d78de2cf47dd99daa15d36 Binary files /dev/null and b/parrot/share/terminfo/t/ts100-sp differ diff --git a/parrot/share/terminfo/t/tty37 b/parrot/share/terminfo/t/tty37 new file mode 100644 index 0000000000000000000000000000000000000000..53a0f177c0e059646c0cd1f23c305f07f958d327 Binary files /dev/null and b/parrot/share/terminfo/t/tty37 differ diff --git a/parrot/share/terminfo/t/tty5410 b/parrot/share/terminfo/t/tty5410 new file mode 100644 index 0000000000000000000000000000000000000000..41072d6638c22ee6d9ecf136ac75c49919eaead2 Binary files /dev/null and b/parrot/share/terminfo/t/tty5410 differ diff --git a/parrot/share/terminfo/t/tty5410-w b/parrot/share/terminfo/t/tty5410-w new file mode 100644 index 0000000000000000000000000000000000000000..78d1777faa19ec7061c6003ddfc560cf29e7f831 Binary files /dev/null and b/parrot/share/terminfo/t/tty5410-w differ diff --git a/parrot/share/terminfo/t/tty5420-w-rv-n b/parrot/share/terminfo/t/tty5420-w-rv-n new file mode 100644 index 0000000000000000000000000000000000000000..3d13a44cf410a9c49ab6d579c0e733e4670c3091 Binary files /dev/null and b/parrot/share/terminfo/t/tty5420-w-rv-n differ diff --git a/parrot/share/terminfo/t/tty5620 b/parrot/share/terminfo/t/tty5620 new file mode 100644 index 0000000000000000000000000000000000000000..1bb40715fdaeac6142fcc6281d95d8ec60469312 Binary files /dev/null and b/parrot/share/terminfo/t/tty5620 differ diff --git a/parrot/share/terminfo/t/tvi9065 b/parrot/share/terminfo/t/tvi9065 new file mode 100644 index 0000000000000000000000000000000000000000..bd7243fb14a1978e4111a730cb286c30c708884d Binary files /dev/null and b/parrot/share/terminfo/t/tvi9065 differ diff --git a/parrot/share/terminfo/t/tvi910+ b/parrot/share/terminfo/t/tvi910+ new file mode 100644 index 0000000000000000000000000000000000000000..af5045f7a96766f53c138afa73f81124cfd8a12a Binary files /dev/null and b/parrot/share/terminfo/t/tvi910+ differ diff --git a/parrot/share/terminfo/t/tvi912b+dim b/parrot/share/terminfo/t/tvi912b+dim new file mode 100644 index 0000000000000000000000000000000000000000..19249cc0851316ddda84606dc7472a75e7eb612a Binary files /dev/null and b/parrot/share/terminfo/t/tvi912b+dim differ diff --git a/parrot/share/terminfo/t/tvi912b+mc b/parrot/share/terminfo/t/tvi912b+mc new file mode 100644 index 0000000000000000000000000000000000000000..4db7177801115bfb3b041c3d6ada860536c955a1 Binary files /dev/null and b/parrot/share/terminfo/t/tvi912b+mc differ diff --git a/parrot/share/terminfo/t/tvi912b+vb b/parrot/share/terminfo/t/tvi912b+vb new file mode 100644 index 0000000000000000000000000000000000000000..33e84caf0e1bdd7867ba57848ccde457153b1590 Binary files /dev/null and b/parrot/share/terminfo/t/tvi912b+vb differ diff --git a/parrot/share/terminfo/t/tvi912b-2p-mc b/parrot/share/terminfo/t/tvi912b-2p-mc new file mode 100644 index 0000000000000000000000000000000000000000..05427a1ed1e0682a6c7995bdda6cc18f28c20b5e Binary files /dev/null and b/parrot/share/terminfo/t/tvi912b-2p-mc differ diff --git a/parrot/share/terminfo/t/tvi912c-mc-2p b/parrot/share/terminfo/t/tvi912c-mc-2p new file mode 100644 index 0000000000000000000000000000000000000000..05427a1ed1e0682a6c7995bdda6cc18f28c20b5e Binary files /dev/null and b/parrot/share/terminfo/t/tvi912c-mc-2p differ diff --git a/parrot/share/terminfo/t/tvi920b+fn b/parrot/share/terminfo/t/tvi920b+fn new file mode 100644 index 0000000000000000000000000000000000000000..e06daf5116d89f2211479949d49b772870fd017a Binary files /dev/null and b/parrot/share/terminfo/t/tvi920b+fn differ diff --git a/parrot/share/terminfo/t/tvi920b-2p b/parrot/share/terminfo/t/tvi920b-2p new file mode 100644 index 0000000000000000000000000000000000000000..faa3c4865290179771b7d0fd757e26aacf9d7457 Binary files /dev/null and b/parrot/share/terminfo/t/tvi920b-2p differ diff --git a/parrot/share/terminfo/t/tvi920b-vb-mc b/parrot/share/terminfo/t/tvi920b-vb-mc new file mode 100644 index 0000000000000000000000000000000000000000..45c2f73b6add609dd5f3c58037c0b7e5373d7359 Binary files /dev/null and b/parrot/share/terminfo/t/tvi920b-vb-mc differ diff --git a/parrot/share/terminfo/t/tvi920b-vb-unk b/parrot/share/terminfo/t/tvi920b-vb-unk new file mode 100644 index 0000000000000000000000000000000000000000..e6b75518f6625a4ad5da3a95176d8195a076dd2a Binary files /dev/null and b/parrot/share/terminfo/t/tvi920b-vb-unk differ diff --git a/parrot/share/terminfo/t/tvi920c-2p-p b/parrot/share/terminfo/t/tvi920c-2p-p new file mode 100644 index 0000000000000000000000000000000000000000..f315894b29888e4ca3a8ed0ae78436e7a233b2bd Binary files /dev/null and b/parrot/share/terminfo/t/tvi920c-2p-p differ diff --git a/parrot/share/terminfo/t/tvi950 b/parrot/share/terminfo/t/tvi950 new file mode 100644 index 0000000000000000000000000000000000000000..54b15013022fa6efe0f2a16b11dc578251344c4f Binary files /dev/null and b/parrot/share/terminfo/t/tvi950 differ diff --git a/parrot/share/terminfo/t/tws2103 b/parrot/share/terminfo/t/tws2103 new file mode 100644 index 0000000000000000000000000000000000000000..213d40fd7cda69568ce0c0e223ef9ca9af002a57 Binary files /dev/null and b/parrot/share/terminfo/t/tws2103 differ diff --git a/videollama2/lib/python3.10/site-packages/altair/utils/_importers.py b/videollama2/lib/python3.10/site-packages/altair/utils/_importers.py new file mode 100644 index 0000000000000000000000000000000000000000..14085ebcf9e458f8889b9406567d3064e976310a --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/altair/utils/_importers.py @@ -0,0 +1,109 @@ +from __future__ import annotations + +from importlib.metadata import version as importlib_version +from typing import TYPE_CHECKING + +from packaging.version import Version + +if TYPE_CHECKING: + from types import ModuleType + + +def import_vegafusion() -> ModuleType: + min_version = "1.5.0" + try: + version = importlib_version("vegafusion") + embed_version = importlib_version("vegafusion-python-embed") + if version != embed_version or Version(version) < Version(min_version): + msg = ( + "The versions of the vegafusion and vegafusion-python-embed packages must match\n" + f"and must be version {min_version} or greater.\n" + f"Found:\n" + f" - vegafusion=={version}\n" + f" - vegafusion-python-embed=={embed_version}\n" + ) + raise RuntimeError(msg) + import vegafusion as vf # type: ignore + + return vf + except ImportError as err: + msg = ( + 'The "vegafusion" data transformer and chart.transformed_data feature requires\n' + f"version {min_version} or greater of the 'vegafusion-python-embed' and 'vegafusion' packages.\n" + "These can be installed with pip using:\n" + f' pip install "vegafusion[embed]>={min_version}"\n' + "Or with conda using:\n" + f' conda install -c conda-forge "vegafusion-python-embed>={min_version}" ' + f'"vegafusion>={min_version}"\n\n' + f"ImportError: {err.args[0]}" + ) + raise ImportError(msg) from err + + +def import_vl_convert() -> ModuleType: + min_version = "1.6.0" + try: + version = importlib_version("vl-convert-python") + if Version(version) < Version(min_version): + msg = ( + f"The vl-convert-python package must be version {min_version} or greater. " + f"Found version {version}" + ) + raise RuntimeError(msg) + import vl_convert as vlc + + return vlc + except ImportError as err: + msg = ( + f"The vl-convert Vega-Lite compiler and file export feature requires\n" + f"version {min_version} or greater of the 'vl-convert-python' package. \n" + f"This can be installed with pip using:\n" + f' pip install "vl-convert-python>={min_version}"\n' + "or conda:\n" + f' conda install -c conda-forge "vl-convert-python>={min_version}"\n\n' + f"ImportError: {err.args[0]}" + ) + raise ImportError(msg) from err + + +def vl_version_for_vl_convert() -> str: + from altair.vegalite import SCHEMA_VERSION + + # Compute VlConvert's vl_version string (of the form 'v5_2') + # from SCHEMA_VERSION (of the form 'v5.2.0') + return "_".join(SCHEMA_VERSION.split(".")[:2]) + + +def import_pyarrow_interchange() -> ModuleType: + min_version = "11.0.0" + try: + version = importlib_version("pyarrow") + + if Version(version) < Version(min_version): + msg = ( + f"The pyarrow package must be version {min_version} or greater. " + f"Found version {version}" + ) + raise RuntimeError(msg) + import pyarrow.interchange as pi + + return pi + except ImportError as err: + msg = ( + f"Usage of the DataFrame Interchange Protocol requires\n" + f"version {min_version} or greater of the pyarrow package. \n" + f"This can be installed with pip using:\n" + f' pip install "pyarrow>={min_version}"\n' + "or conda:\n" + f' conda install -c conda-forge "pyarrow>={min_version}"\n\n' + f"ImportError: {err.args[0]}" + ) + raise ImportError(msg) from err + + +def pyarrow_available() -> bool: + try: + import_pyarrow_interchange() + return True + except (ImportError, RuntimeError): + return False diff --git a/videollama2/lib/python3.10/site-packages/altair/utils/_show.py b/videollama2/lib/python3.10/site-packages/altair/utils/_show.py new file mode 100644 index 0000000000000000000000000000000000000000..39345d1cefc28ee419fec5c6c544840fe51162c8 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/altair/utils/_show.py @@ -0,0 +1,72 @@ +from __future__ import annotations + +import webbrowser +from http.server import BaseHTTPRequestHandler, HTTPServer +from typing import Iterable + + +def open_html_in_browser( + html: str | bytes, + using: str | Iterable[str] | None = None, + port: int | None = None, +) -> None: + """ + Display an html document in a web browser without creating a temp file. + + Instantiates a simple http server and uses the webbrowser module to + open the server's URL + + Parameters + ---------- + html: str + HTML string to display + using: str or iterable of str + Name of the web browser to open (e.g. "chrome", "firefox", etc.). + If an iterable, choose the first browser available on the system. + If none, choose the system default browser. + port: int + Port to use. Defaults to a random port + """ + # Encode html to bytes + html_bytes = html.encode("utf8") if isinstance(html, str) else html + + browser = None + + if using is None: + browser = webbrowser.get(None) + else: + # normalize using to an iterable + if isinstance(using, str): + using = [using] + + for browser_key in using: + try: + browser = webbrowser.get(browser_key) + if browser is not None: + break + except webbrowser.Error: + pass + + if browser is None: + raise ValueError("Failed to locate a browser with name in " + str(using)) + + class OneShotRequestHandler(BaseHTTPRequestHandler): + def do_GET(self) -> None: + self.send_response(200) + self.send_header("Content-type", "text/html") + self.end_headers() + + bufferSize = 1024 * 1024 + for i in range(0, len(html_bytes), bufferSize): + self.wfile.write(html_bytes[i : i + bufferSize]) + + def log_message(self, format, *args): + # Silence stderr logging + pass + + # Use specified port if provided, otherwise choose a random port (port value of 0) + server = HTTPServer( + ("127.0.0.1", port if port is not None else 0), OneShotRequestHandler + ) + browser.open(f"http://127.0.0.1:{server.server_port}") + server.handle_request() diff --git a/videollama2/lib/python3.10/site-packages/altair/utils/_vegafusion_data.py b/videollama2/lib/python3.10/site-packages/altair/utils/_vegafusion_data.py new file mode 100644 index 0000000000000000000000000000000000000000..970098d3314fb2a00e94229362df15a346bf830d --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/altair/utils/_vegafusion_data.py @@ -0,0 +1,281 @@ +from __future__ import annotations + +import uuid +from typing import ( + TYPE_CHECKING, + Any, + Callable, + Final, + MutableMapping, + TypedDict, + Union, + overload, +) +from weakref import WeakValueDictionary + +from altair.utils._importers import import_vegafusion +from altair.utils.core import DataFrameLike +from altair.utils.data import ( + DataType, + MaxRowsError, + SupportsGeoInterface, + ToValuesReturnType, +) +from altair.vegalite.data import default_data_transformer + +if TYPE_CHECKING: + from narwhals.typing import IntoDataFrame + + from vegafusion.runtime import ChartState # type: ignore + +# Temporary storage for dataframes that have been extracted +# from charts by the vegafusion data transformer. Use a WeakValueDictionary +# rather than a dict so that the Python interpreter is free to garbage +# collect the stored DataFrames. +extracted_inline_tables: MutableMapping[str, DataFrameLike] = WeakValueDictionary() + +# Special URL prefix that VegaFusion uses to denote that a +# dataset in a Vega spec corresponds to an entry in the `inline_datasets` +# kwarg of vf.runtime.pre_transform_spec(). +VEGAFUSION_PREFIX: Final = "vegafusion+dataset://" + + +class _ToVegaFusionReturnUrlDict(TypedDict): + url: str + + +_VegaFusionReturnType = Union[_ToVegaFusionReturnUrlDict, ToValuesReturnType] + + +@overload +def vegafusion_data_transformer( + data: None = ..., max_rows: int = ... +) -> Callable[..., Any]: ... + + +@overload +def vegafusion_data_transformer( + data: DataFrameLike, max_rows: int = ... +) -> ToValuesReturnType: ... + + +@overload +def vegafusion_data_transformer( + data: dict | IntoDataFrame | SupportsGeoInterface, max_rows: int = ... +) -> _VegaFusionReturnType: ... + + +def vegafusion_data_transformer( + data: DataType | None = None, max_rows: int = 100000 +) -> Callable[..., Any] | _VegaFusionReturnType: + """VegaFusion Data Transformer.""" + if data is None: + return vegafusion_data_transformer + elif isinstance(data, DataFrameLike) and not isinstance(data, SupportsGeoInterface): + table_name = f"table_{uuid.uuid4()}".replace("-", "_") + extracted_inline_tables[table_name] = data + return {"url": VEGAFUSION_PREFIX + table_name} + else: + # Use default transformer for geo interface objects + # # (e.g. a geopandas GeoDataFrame) + # Or if we don't recognize data type + return default_data_transformer(data) + + +def get_inline_table_names(vega_spec: dict[str, Any]) -> set[str]: + """ + Get a set of the inline datasets names in the provided Vega spec. + + Inline datasets are encoded as URLs that start with the table:// + prefix. + + Parameters + ---------- + vega_spec: dict + A Vega specification dict + + Returns + ------- + set of str + Set of the names of the inline datasets that are referenced + in the specification. + + Examples + -------- + >>> spec = { + ... "data": [ + ... {"name": "foo", "url": "https://path/to/file.csv"}, + ... {"name": "bar", "url": "vegafusion+dataset://inline_dataset_123"}, + ... ] + ... } + >>> get_inline_table_names(spec) + {'inline_dataset_123'} + """ + table_names = set() + + # Process datasets + for data in vega_spec.get("data", []): + url = data.get("url", "") + if url.startswith(VEGAFUSION_PREFIX): + name = url[len(VEGAFUSION_PREFIX) :] + table_names.add(name) + + # Recursively process child marks, which may have their own datasets + for mark in vega_spec.get("marks", []): + table_names.update(get_inline_table_names(mark)) + + return table_names + + +def get_inline_tables(vega_spec: dict[str, Any]) -> dict[str, DataFrameLike]: + """ + Get the inline tables referenced by a Vega specification. + + Note: This function should only be called on a Vega spec that corresponds + to a chart that was processed by the vegafusion_data_transformer. + Furthermore, this function may only be called once per spec because + the returned dataframes are deleted from internal storage. + + Parameters + ---------- + vega_spec: dict + A Vega specification dict + + Returns + ------- + dict from str to dataframe + dict from inline dataset name to dataframe object + """ + inline_names = get_inline_table_names(vega_spec) + # exclude named dataset that was provided by the user, + # or dataframes that have been deleted. + table_names = inline_names.intersection(extracted_inline_tables) + return {k: extracted_inline_tables.pop(k) for k in table_names} + + +def compile_to_vegafusion_chart_state( + vegalite_spec: dict[str, Any], local_tz: str +) -> ChartState: + """ + Compile a Vega-Lite spec to a VegaFusion ChartState. + + Note: This function should only be called on a Vega-Lite spec + that was generated with the "vegafusion" data transformer enabled. + In particular, this spec may contain references to extract datasets + using table:// prefixed URLs. + + Parameters + ---------- + vegalite_spec: dict + A Vega-Lite spec that was generated from an Altair chart with + the "vegafusion" data transformer enabled + local_tz: str + Local timezone name (e.g. 'America/New_York') + + Returns + ------- + ChartState + A VegaFusion ChartState object + """ + # Local import to avoid circular ImportError + from altair import data_transformers, vegalite_compilers + + vf = import_vegafusion() + + # Compile Vega-Lite spec to Vega + compiler = vegalite_compilers.get() + if compiler is None: + msg = "No active vega-lite compiler plugin found" + raise ValueError(msg) + + vega_spec = compiler(vegalite_spec) + + # Retrieve dict of inline tables referenced by the spec + inline_tables = get_inline_tables(vega_spec) + + # Pre-evaluate transforms in vega spec with vegafusion + row_limit = data_transformers.options.get("max_rows", None) + + chart_state = vf.runtime.new_chart_state( + vega_spec, + local_tz=local_tz, + inline_datasets=inline_tables, + row_limit=row_limit, + ) + + # Check from row limit warning and convert to MaxRowsError + handle_row_limit_exceeded(row_limit, chart_state.get_warnings()) + + return chart_state + + +def compile_with_vegafusion(vegalite_spec: dict[str, Any]) -> dict[str, Any]: + """ + Compile a Vega-Lite spec to Vega and pre-transform with VegaFusion. + + Note: This function should only be called on a Vega-Lite spec + that was generated with the "vegafusion" data transformer enabled. + In particular, this spec may contain references to extract datasets + using table:// prefixed URLs. + + Parameters + ---------- + vegalite_spec: dict + A Vega-Lite spec that was generated from an Altair chart with + the "vegafusion" data transformer enabled + + Returns + ------- + dict + A Vega spec that has been pre-transformed by VegaFusion + """ + # Local import to avoid circular ImportError + from altair import data_transformers, vegalite_compilers + + vf = import_vegafusion() + + # Compile Vega-Lite spec to Vega + compiler = vegalite_compilers.get() + if compiler is None: + msg = "No active vega-lite compiler plugin found" + raise ValueError(msg) + + vega_spec = compiler(vegalite_spec) + + # Retrieve dict of inline tables referenced by the spec + inline_tables = get_inline_tables(vega_spec) + + # Pre-evaluate transforms in vega spec with vegafusion + row_limit = data_transformers.options.get("max_rows", None) + transformed_vega_spec, warnings = vf.runtime.pre_transform_spec( + vega_spec, + vf.get_local_tz(), + inline_datasets=inline_tables, + row_limit=row_limit, + ) + + # Check from row limit warning and convert to MaxRowsError + handle_row_limit_exceeded(row_limit, warnings) + + return transformed_vega_spec + + +def handle_row_limit_exceeded(row_limit: int, warnings: list): + for warning in warnings: + if warning.get("type") == "RowLimitExceeded": + msg = ( + "The number of dataset rows after filtering and aggregation exceeds\n" + f"the current limit of {row_limit}. Try adding an aggregation to reduce\n" + "the size of the dataset that must be loaded into the browser. Or, disable\n" + "the limit by calling alt.data_transformers.disable_max_rows(). Note that\n" + "disabling this limit may cause the browser to freeze or crash." + ) + raise MaxRowsError(msg) + + +def using_vegafusion() -> bool: + """Check whether the vegafusion data transformer is enabled.""" + # Local import to avoid circular ImportError + from altair import data_transformers + + return data_transformers.active == "vegafusion" diff --git a/videollama2/lib/python3.10/site-packages/altair/utils/display.py b/videollama2/lib/python3.10/site-packages/altair/utils/display.py new file mode 100644 index 0000000000000000000000000000000000000000..91727318ef2b1c4e937024d10b3aa05870fc72d3 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/altair/utils/display.py @@ -0,0 +1,225 @@ +from __future__ import annotations + +import json +import pkgutil +import textwrap +import uuid +from typing import Any, Callable, Dict, Tuple, Union +from typing_extensions import TypeAlias + +from ._vegafusion_data import compile_with_vegafusion, using_vegafusion +from .mimebundle import spec_to_mimebundle +from .plugin_registry import PluginEnabler, PluginRegistry +from .schemapi import validate_jsonschema + +# ============================================================================== +# Renderer registry +# ============================================================================== +# MimeBundleType needs to be the same as what are acceptable return values +# for _repr_mimebundle_, +# see https://ipython.readthedocs.io/en/stable/config/integrating.html#MyObject._repr_mimebundle_ +MimeBundleDataType: TypeAlias = Dict[str, Any] +MimeBundleMetaDataType: TypeAlias = Dict[str, Any] +MimeBundleType: TypeAlias = Union[ + MimeBundleDataType, Tuple[MimeBundleDataType, MimeBundleMetaDataType] +] +RendererType: TypeAlias = Callable[..., MimeBundleType] +# Subtype of MimeBundleType as more specific in the values of the dictionaries + +DefaultRendererReturnType: TypeAlias = Tuple[ + Dict[str, Union[str, Dict[str, Any]]], Dict[str, Dict[str, Any]] +] + + +class RendererRegistry(PluginRegistry[RendererType, MimeBundleType]): + entrypoint_err_messages = { + "notebook": textwrap.dedent( + """ + To use the 'notebook' renderer, you must install the vega package + and the associated Jupyter extension. + See https://altair-viz.github.io/getting_started/installation.html + for more information. + """ + ), + } + + def set_embed_options( + self, + defaultStyle: bool | str | None = None, + renderer: str | None = None, + width: int | None = None, + height: int | None = None, + padding: int | None = None, + scaleFactor: float | None = None, + actions: bool | dict[str, bool] | None = None, + format_locale: str | dict | None = None, + time_format_locale: str | dict | None = None, + **kwargs, + ) -> PluginEnabler: + """ + Set options for embeddings of Vega & Vega-Lite charts. + + Options are fully documented at https://github.com/vega/vega-embed. + Similar to the `enable()` method, this can be used as either + a persistent global switch, or as a temporary local setting using + a context manager (i.e. a `with` statement). + + Parameters + ---------- + defaultStyle : bool or string + Specify a default stylesheet for embed actions. + renderer : string + The renderer to use for the view. One of "canvas" (default) or "svg" + width : integer + The view width in pixels + height : integer + The view height in pixels + padding : integer + The view padding in pixels + scaleFactor : number + The number by which to multiply the width and height (default 1) + of an exported PNG or SVG image. + actions : bool or dict + Determines if action links ("Export as PNG/SVG", "View Source", + "View Vega" (only for Vega-Lite), "Open in Vega Editor") are + included with the embedded view. If the value is true, all action + links will be shown and none if the value is false. This property + can take a key-value mapping object that maps keys (export, source, + compiled, editor) to boolean values for determining if + each action link should be shown. + format_locale : str or dict + d3-format locale name or dictionary. Defaults to "en-US" for United States English. + See https://github.com/d3/d3-format/tree/main/locale for available names and example + definitions. + time_format_locale : str or dict + d3-time-format locale name or dictionary. Defaults to "en-US" for United States English. + See https://github.com/d3/d3-time-format/tree/main/locale for available names and example + definitions. + **kwargs : + Additional options are passed directly to embed options. + """ + options: dict[str, bool | str | float | dict[str, bool] | None] = { + "defaultStyle": defaultStyle, + "renderer": renderer, + "width": width, + "height": height, + "padding": padding, + "scaleFactor": scaleFactor, + "actions": actions, + "formatLocale": format_locale, + "timeFormatLocale": time_format_locale, + } + kwargs.update({key: val for key, val in options.items() if val is not None}) + return self.enable(None, embed_options=kwargs) + + +# ============================================================================== +# VegaLite v1/v2 renderer logic +# ============================================================================== + + +class Displayable: + """ + A base display class for VegaLite v1/v2. + + This class takes a VegaLite v1/v2 spec and does the following: + + 1. Optionally validates the spec against a schema. + 2. Uses the RendererPlugin to grab a renderer and call it when the + IPython/Jupyter display method (_repr_mimebundle_) is called. + + The spec passed to this class must be fully schema compliant and already + have the data portion of the spec fully processed and ready to serialize. + In practice, this means, the data portion of the spec should have been passed + through appropriate data model transformers. + """ + + renderers: RendererRegistry | None = None + schema_path = ("altair", "") + + def __init__(self, spec: dict[str, Any], validate: bool = False) -> None: + self.spec = spec + self.validate = validate + self._validate() + + def _validate(self) -> None: + """Validate the spec against the schema.""" + data = pkgutil.get_data(*self.schema_path) + assert data is not None + schema_dict: dict[str, Any] = json.loads(data.decode("utf-8")) + validate_jsonschema( + self.spec, + schema_dict, + ) + + def _repr_mimebundle_( + self, include: Any = None, exclude: Any = None + ) -> MimeBundleType: + """Return a MIME bundle for display in Jupyter frontends.""" + if self.renderers is not None: + renderer_func = self.renderers.get() + assert renderer_func is not None + return renderer_func(self.spec) + else: + return {} + + +def default_renderer_base( + spec: dict[str, Any], mime_type: str, str_repr: str, **options +) -> DefaultRendererReturnType: + """ + A default renderer for Vega or VegaLite that works for modern frontends. + + This renderer works with modern frontends (JupyterLab, nteract) that know + how to render the custom VegaLite MIME type listed above. + """ + # Local import to avoid circular ImportError + from altair.vegalite.v5.display import VEGA_MIME_TYPE, VEGALITE_MIME_TYPE + + assert isinstance(spec, dict) + bundle: dict[str, str | dict] = {} + metadata: dict[str, dict[str, Any]] = {} + + if using_vegafusion(): + spec = compile_with_vegafusion(spec) + + # Swap mimetype from Vega-Lite to Vega. + # If mimetype was JSON, leave it alone + if mime_type == VEGALITE_MIME_TYPE: + mime_type = VEGA_MIME_TYPE + + bundle[mime_type] = spec + bundle["text/plain"] = str_repr + if options: + metadata[mime_type] = options + return bundle, metadata + + +def json_renderer_base( + spec: dict[str, Any], str_repr: str, **options +) -> DefaultRendererReturnType: + """ + A renderer that returns a MIME type of application/json. + + In JupyterLab/nteract this is rendered as a nice JSON tree. + """ + return default_renderer_base( + spec, mime_type="application/json", str_repr=str_repr, **options + ) + + +class HTMLRenderer: + """Object to render charts as HTML, with a unique output div each time.""" + + def __init__(self, output_div: str = "altair-viz-{}", **kwargs) -> None: + self._output_div = output_div + self.kwargs = kwargs + + @property + def output_div(self) -> str: + return self._output_div.format(uuid.uuid4().hex) + + def __call__(self, spec: dict[str, Any], **metadata) -> dict[str, str]: + kwargs = self.kwargs.copy() + kwargs.update(**metadata, output_div=self.output_div) + return spec_to_mimebundle(spec, format="html", **kwargs) diff --git a/videollama2/lib/python3.10/site-packages/altair/utils/html.py b/videollama2/lib/python3.10/site-packages/altair/utils/html.py new file mode 100644 index 0000000000000000000000000000000000000000..7b5f4dcf54daedd45b187a1c14d70c089c36ad9d --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/altair/utils/html.py @@ -0,0 +1,314 @@ +from __future__ import annotations + +import json +from typing import Any, Literal + +import jinja2 + +from altair.utils._importers import import_vl_convert, vl_version_for_vl_convert + +TemplateName = Literal["standard", "universal", "inline"] +RenderMode = Literal["vega", "vega-lite"] + +HTML_TEMPLATE = jinja2.Template( + """ +{%- if fullhtml -%} + + +
+{%- endif %} + +{%- if not requirejs %} + + {%- if mode == 'vega-lite' %} + + {%- endif %} + +{%- endif %} +{%- if fullhtml %} +{%- if requirejs %} + + +{%- endif %} + + +{%- endif %} + + +{%- if fullhtml %} + + +{%- endif %} +""" +) + + +HTML_TEMPLATE_UNIVERSAL = jinja2.Template( + """ + + + +""" +) + + +# This is like the HTML_TEMPLATE template, but includes vega javascript inline +# so that the resulting file is not dependent on external resources. This was +# ported over from altair_saver. +# +# implies requirejs=False and full_html=True +INLINE_HTML_TEMPLATE = jinja2.Template( + """\ + + + + + + + + + + + +""" +) + + +TEMPLATES: dict[TemplateName, jinja2.Template] = { + "standard": HTML_TEMPLATE, + "universal": HTML_TEMPLATE_UNIVERSAL, + "inline": INLINE_HTML_TEMPLATE, +} + + +def spec_to_html( + spec: dict[str, Any], + mode: RenderMode, + vega_version: str | None, + vegaembed_version: str | None, + vegalite_version: str | None = None, + base_url: str = "https://cdn.jsdelivr.net/npm", + output_div: str = "vis", + embed_options: dict[str, Any] | None = None, + json_kwds: dict[str, Any] | None = None, + fullhtml: bool = True, + requirejs: bool = False, + template: jinja2.Template | TemplateName = "standard", +) -> str: + """ + Embed a Vega/Vega-Lite spec into an HTML page. + + Parameters + ---------- + spec : dict + a dictionary representing a vega-lite plot spec. + mode : string {'vega' | 'vega-lite'} + The rendering mode. This value is overridden by embed_options['mode'], + if it is present. + vega_version : string + For html output, the version of vega.js to use. + vegalite_version : string + For html output, the version of vegalite.js to use. + vegaembed_version : string + For html output, the version of vegaembed.js to use. + base_url : string (optional) + The base url from which to load the javascript libraries. + output_div : string (optional) + The id of the div element where the plot will be shown. + embed_options : dict (optional) + Dictionary of options to pass to the vega-embed script. Default + entry is {'mode': mode}. + json_kwds : dict (optional) + Dictionary of keywords to pass to json.dumps(). + fullhtml : boolean (optional) + If True (default) then return a full html page. If False, then return + an HTML snippet that can be embedded into an HTML page. + requirejs : boolean (optional) + If False (default) then load libraries from base_url using