diff --git a/docs/source/conf.py b/docs/source/conf.py index 7b33a309e..a6a9fd1f6 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -7,9 +7,9 @@ # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information -project = 'fastplotlib' -copyright = '2023, Kushal Kolar, Caitlin Lewis' -author = 'Kushal Kolar, Caitlin Lewis' +project = "fastplotlib" +copyright = "2023, Kushal Kolar, Caitlin Lewis" +author = "Kushal Kolar, Caitlin Lewis" release = fastplotlib.__version__ # -- General configuration --------------------------------------------------- @@ -28,21 +28,21 @@ autosummary_generate = True -templates_path = ['_templates'] +templates_path = ["_templates"] exclude_patterns = [] -napoleon_custom_sections = ['Features'] +napoleon_custom_sections = ["Features"] # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output html_theme = "furo" -html_static_path = ['_static'] +html_static_path = ["_static"] html_logo = "_static/logo.png" html_title = f"v{release}" -autodoc_member_order = 'groupwise' +autodoc_member_order = "groupwise" autoclass_content = "both" add_module_names = False @@ -50,9 +50,9 @@ autodoc_typehints_description_target = "documented_params" intersphinx_mapping = { - 'python': ('https://docs.python.org/3', None), - 'numpy': ('https://numpy.org/doc/stable/', None), - 'pygfx': ('https://pygfx.readthedocs.io/en/latest', None) + "python": ("https://docs.python.org/3", None), + "numpy": ("https://numpy.org/doc/stable/", None), + "pygfx": ("https://pygfx.readthedocs.io/en/latest", None), } html_theme_options = { diff --git a/docs/source/generate_api.py b/docs/source/generate_api.py index 05e8b0f1c..19b739d1b 100644 --- a/docs/source/generate_api.py +++ b/docs/source/generate_api.py @@ -26,7 +26,7 @@ GRAPHICS_DIR, GRAPHIC_FEATURES_DIR, SELECTORS_DIR, - WIDGETS_DIR + WIDGETS_DIR, ] for source_dir in doc_sources: @@ -66,13 +66,9 @@ def generate_class( ): name = cls.__name__ methods, properties = get_public_members(cls) - methods = [ - f"{name}.{m}" for m in methods - ] + methods = [f"{name}.{m}" for m in methods] - properties = [ - f"{name}.{p}" for p in properties - ] + properties = [f"{name}.{p}" for p in properties] underline = "=" * len(name) @@ -149,32 +145,28 @@ def main(): page_name="Plot", classes=[fastplotlib.Plot], modules=["fastplotlib"], - source_path=LAYOUTS_DIR.joinpath("plot.rst") + source_path=LAYOUTS_DIR.joinpath("plot.rst"), ) generate_page( page_name="GridPlot", classes=[fastplotlib.GridPlot], modules=["fastplotlib"], - source_path=LAYOUTS_DIR.joinpath("gridplot.rst") + source_path=LAYOUTS_DIR.joinpath("gridplot.rst"), ) generate_page( page_name="Subplot", classes=[Subplot], modules=["fastplotlib.layouts._subplot"], - source_path=LAYOUTS_DIR.joinpath("subplot.rst") + source_path=LAYOUTS_DIR.joinpath("subplot.rst"), ) # the rest of this is a mess and can be refactored later - graphic_classes = [ - getattr(graphics, g) for g in graphics.__all__ - ] + graphic_classes = [getattr(graphics, g) for g in graphics.__all__] - graphic_class_names = [ - g.__name__ for g in graphic_classes - ] + graphic_class_names = [g.__name__ for g in graphic_classes] graphic_class_names_str = "\n ".join([""] + graphic_class_names) @@ -194,17 +186,13 @@ def main(): page_name=graphic_cls.__name__, classes=[graphic_cls], modules=["fastplotlib"], - source_path=GRAPHICS_DIR.joinpath(f"{graphic_cls.__name__}.rst") + source_path=GRAPHICS_DIR.joinpath(f"{graphic_cls.__name__}.rst"), ) ############################################################################## - feature_classes = [ - getattr(_features, f) for f in _features.__all__ - ] + feature_classes = [getattr(_features, f) for f in _features.__all__] - feature_class_names = [ - f.__name__ for f in feature_classes - ] + feature_class_names = [f.__name__ for f in feature_classes] feature_class_names_str = "\n ".join([""] + feature_class_names) @@ -223,17 +211,13 @@ def main(): page_name=feature_cls.__name__, classes=[feature_cls], modules=["fastplotlib.graphics._features"], - source_path=GRAPHIC_FEATURES_DIR.joinpath(f"{feature_cls.__name__}.rst") + source_path=GRAPHIC_FEATURES_DIR.joinpath(f"{feature_cls.__name__}.rst"), ) ############################################################################## - selector_classes = [ - getattr(selectors, s) for s in selectors.__all__ - ] + selector_classes = [getattr(selectors, s) for s in selectors.__all__] - selector_class_names = [ - s.__name__ for s in selector_classes - ] + selector_class_names = [s.__name__ for s in selector_classes] selector_class_names_str = "\n ".join([""] + selector_class_names) @@ -252,17 +236,13 @@ def main(): page_name=selector_cls.__name__, classes=[selector_cls], modules=["fastplotlib"], - source_path=SELECTORS_DIR.joinpath(f"{selector_cls.__name__}.rst") + source_path=SELECTORS_DIR.joinpath(f"{selector_cls.__name__}.rst"), ) ############################################################################## - widget_classes = [ - getattr(widgets, w) for w in widgets.__all__ - ] + widget_classes = [getattr(widgets, w) for w in widgets.__all__] - widget_class_names = [ - w.__name__ for w in widget_classes - ] + widget_class_names = [w.__name__ for w in widget_classes] widget_class_names_str = "\n ".join([""] + widget_class_names) @@ -281,7 +261,7 @@ def main(): page_name=widget_cls.__name__, classes=[widget_cls], modules=["fastplotlib"], - source_path=WIDGETS_DIR.joinpath(f"{widget_cls.__name__}.rst") + source_path=WIDGETS_DIR.joinpath(f"{widget_cls.__name__}.rst"), ) ############################################################################## diff --git a/fastplotlib/layouts/graphic_methods_mixin.py b/fastplotlib/layouts/graphic_methods_mixin.py index b00187df7..0376fd777 100644 --- a/fastplotlib/layouts/graphic_methods_mixin.py +++ b/fastplotlib/layouts/graphic_methods_mixin.py @@ -14,13 +14,13 @@ def __init__(self): pass def _create_graphic(self, graphic_class, *args, **kwargs) -> Graphic: - if 'center' in kwargs.keys(): - center = kwargs.pop('center') + if "center" in kwargs.keys(): + center = kwargs.pop("center") else: center = False - if 'name' in kwargs.keys(): - self._check_graphic_name_exists(kwargs['name']) + if "name" in kwargs.keys(): + self._check_graphic_name_exists(kwargs["name"]) graphic = graphic_class(*args, **kwargs) self.add_graphic(graphic, center=center) @@ -28,9 +28,20 @@ def _create_graphic(self, graphic_class, *args, **kwargs) -> Graphic: # only return a proxy to the real graphic return weakref.proxy(graphic) - def add_heatmap(self, data: Any, vmin: int = None, vmax: int = None, cmap: str = 'plasma', filter: str = 'nearest', chunk_size: int = 8192, isolated_buffer: bool = True, *args, **kwargs) -> HeatmapGraphic: + def add_heatmap( + self, + data: Any, + vmin: int = None, + vmax: int = None, + cmap: str = "plasma", + filter: str = "nearest", + chunk_size: int = 8192, + isolated_buffer: bool = True, + *args, + **kwargs + ) -> HeatmapGraphic: """ - + Create an Image Graphic Parameters @@ -78,13 +89,34 @@ def add_heatmap(self, data: Any, vmin: int = None, vmax: int = None, cmap: str = **present**: :class:`.PresentFeature` Control the presence of the Graphic in the scene - - """ - return self._create_graphic(HeatmapGraphic, data, vmin, vmax, cmap, filter, chunk_size, isolated_buffer, *args, **kwargs) - def add_image(self, data: Any, vmin: int = None, vmax: int = None, cmap: str = 'plasma', filter: str = 'nearest', isolated_buffer: bool = True, *args, **kwargs) -> ImageGraphic: """ - + return self._create_graphic( + HeatmapGraphic, + data, + vmin, + vmax, + cmap, + filter, + chunk_size, + isolated_buffer, + *args, + **kwargs + ) + + def add_image( + self, + data: Any, + vmin: int = None, + vmax: int = None, + cmap: str = "plasma", + filter: str = "nearest", + isolated_buffer: bool = True, + *args, + **kwargs + ) -> ImageGraphic: + """ + Create an Image Graphic Parameters @@ -129,13 +161,36 @@ def add_image(self, data: Any, vmin: int = None, vmax: int = None, cmap: str = ' **present**: :class:`.PresentFeature` Control the presence of the Graphic in the scene - - """ - return self._create_graphic(ImageGraphic, data, vmin, vmax, cmap, filter, isolated_buffer, *args, **kwargs) - def add_line_collection(self, data: List[numpy.ndarray], z_position: Union[List[float], float] = None, thickness: Union[float, List[float]] = 2.0, colors: Union[List[numpy.ndarray], numpy.ndarray] = 'w', alpha: float = 1.0, cmap: Union[List[str], str] = None, cmap_values: Union[numpy.ndarray, List] = None, name: str = None, metadata: Union[list, tuple, numpy.ndarray] = None, *args, **kwargs) -> LineCollection: """ - + return self._create_graphic( + ImageGraphic, + data, + vmin, + vmax, + cmap, + filter, + isolated_buffer, + *args, + **kwargs + ) + + def add_line_collection( + self, + data: List[numpy.ndarray], + z_position: Union[List[float], float] = None, + thickness: Union[float, List[float]] = 2.0, + colors: Union[List[numpy.ndarray], numpy.ndarray] = "w", + alpha: float = 1.0, + cmap: Union[List[str], str] = None, + cmap_values: Union[numpy.ndarray, List] = None, + name: str = None, + metadata: Union[list, tuple, numpy.ndarray] = None, + *args, + **kwargs + ) -> LineCollection: + """ + Create a collection of :class:`.LineGraphic` Parameters @@ -189,13 +244,38 @@ def add_line_collection(self, data: List[numpy.ndarray], z_position: Union[List[ See :class:`LineGraphic` details on the features. - - """ - return self._create_graphic(LineCollection, data, z_position, thickness, colors, alpha, cmap, cmap_values, name, metadata, *args, **kwargs) - def add_line(self, data: Any, thickness: float = 2.0, colors: Union[str, numpy.ndarray, Iterable] = 'w', alpha: float = 1.0, cmap: str = None, cmap_values: Union[numpy.ndarray, List] = None, z_position: float = None, collection_index: int = None, *args, **kwargs) -> LineGraphic: """ - + return self._create_graphic( + LineCollection, + data, + z_position, + thickness, + colors, + alpha, + cmap, + cmap_values, + name, + metadata, + *args, + **kwargs + ) + + def add_line( + self, + data: Any, + thickness: float = 2.0, + colors: Union[str, numpy.ndarray, Iterable] = "w", + alpha: float = 1.0, + cmap: str = None, + cmap_values: Union[numpy.ndarray, List] = None, + z_position: float = None, + collection_index: int = None, + *args, + **kwargs + ) -> LineGraphic: + """ + Create a line Graphic, 2d or 3d Parameters @@ -247,13 +327,37 @@ def add_line(self, data: Any, thickness: float = 2.0, colors: Union[str, numpy.n **present**: :class:`.PresentFeature` Control the presence of the Graphic in the scene, set to ``True`` or ``False`` - - """ - return self._create_graphic(LineGraphic, data, thickness, colors, alpha, cmap, cmap_values, z_position, collection_index, *args, **kwargs) - def add_line_stack(self, data: List[numpy.ndarray], z_position: Union[List[float], float] = None, thickness: Union[float, List[float]] = 2.0, colors: Union[List[numpy.ndarray], numpy.ndarray] = 'w', cmap: Union[List[str], str] = None, separation: float = 10, separation_axis: str = 'y', name: str = None, *args, **kwargs) -> LineStack: """ - + return self._create_graphic( + LineGraphic, + data, + thickness, + colors, + alpha, + cmap, + cmap_values, + z_position, + collection_index, + *args, + **kwargs + ) + + def add_line_stack( + self, + data: List[numpy.ndarray], + z_position: Union[List[float], float] = None, + thickness: Union[float, List[float]] = 2.0, + colors: Union[List[numpy.ndarray], numpy.ndarray] = "w", + cmap: Union[List[str], str] = None, + separation: float = 10, + separation_axis: str = "y", + name: str = None, + *args, + **kwargs + ) -> LineStack: + """ + Create a stack of :class:`.LineGraphic` that are separated along the "x" or "y" axis. Parameters @@ -309,13 +413,36 @@ def add_line_stack(self, data: List[numpy.ndarray], z_position: Union[List[float See :class:`LineGraphic` details on the features. - - """ - return self._create_graphic(LineStack, data, z_position, thickness, colors, cmap, separation, separation_axis, name, *args, **kwargs) - def add_scatter(self, data: numpy.ndarray, sizes: Union[int, float, numpy.ndarray, list] = 1, colors: numpy.ndarray = 'w', alpha: float = 1.0, cmap: str = None, cmap_values: Union[numpy.ndarray, List] = None, z_position: float = 0.0, *args, **kwargs) -> ScatterGraphic: """ - + return self._create_graphic( + LineStack, + data, + z_position, + thickness, + colors, + cmap, + separation, + separation_axis, + name, + *args, + **kwargs + ) + + def add_scatter( + self, + data: numpy.ndarray, + sizes: Union[int, float, numpy.ndarray, list] = 1, + colors: numpy.ndarray = "w", + alpha: float = 1.0, + cmap: str = None, + cmap_values: Union[numpy.ndarray, List] = None, + z_position: float = 0.0, + *args, + **kwargs + ) -> ScatterGraphic: + """ + Create a Scatter Graphic, 2d or 3d Parameters @@ -364,13 +491,36 @@ def add_scatter(self, data: numpy.ndarray, sizes: Union[int, float, numpy.ndarra **present**: :class:`.PresentFeature` Control the presence of the Graphic in the scene, set to ``True`` or ``False`` - - """ - return self._create_graphic(ScatterGraphic, data, sizes, colors, alpha, cmap, cmap_values, z_position, *args, **kwargs) - def add_text(self, text: str, position: Tuple[int] = (0, 0, 0), size: int = 14, face_color: Union[str, numpy.ndarray] = 'w', outline_color: Union[str, numpy.ndarray] = 'w', outline_thickness=0, screen_space: bool = True, anchor: str = 'middle-center', *args, **kwargs) -> TextGraphic: """ - + return self._create_graphic( + ScatterGraphic, + data, + sizes, + colors, + alpha, + cmap, + cmap_values, + z_position, + *args, + **kwargs + ) + + def add_text( + self, + text: str, + position: Tuple[int] = (0, 0, 0), + size: int = 14, + face_color: Union[str, numpy.ndarray] = "w", + outline_color: Union[str, numpy.ndarray] = "w", + outline_thickness=0, + screen_space: bool = True, + anchor: str = "middle-center", + *args, + **kwargs + ) -> TextGraphic: + """ + Create a text Graphic Parameters @@ -405,7 +555,18 @@ def add_text(self, text: str, position: Tuple[int] = (0, 0, 0), size: int = 14, * Vertical values: "top", "middle", "baseline", "bottom" * Horizontal values: "left", "center", "right" - - """ - return self._create_graphic(TextGraphic, text, position, size, face_color, outline_color, outline_thickness, screen_space, anchor, *args, **kwargs) + """ + return self._create_graphic( + TextGraphic, + text, + position, + size, + face_color, + outline_color, + outline_thickness, + screen_space, + anchor, + *args, + **kwargs + ) diff --git a/fastplotlib/utils/generate_add_methods.py b/fastplotlib/utils/generate_add_methods.py index 9cb87baab..100ad7757 100644 --- a/fastplotlib/utils/generate_add_methods.py +++ b/fastplotlib/utils/generate_add_methods.py @@ -1,11 +1,15 @@ import inspect import pathlib +import black + +root = pathlib.Path(__file__).parent.parent.resolve() +filename = root.joinpath("layouts/graphic_methods_mixin.py") + # if there is an existing mixin class, replace it with an empty class # so that fastplotlib will import # hacky but it works -current_module = pathlib.Path(__file__).parent.parent.resolve() -with open(current_module.joinpath("layouts/graphic_methods_mixin.py"), "w") as f: +with open(filename, "w") as f: f.write(f"class GraphicMethodsMixin:\n" f" pass") from fastplotlib import graphics @@ -20,8 +24,7 @@ def generate_add_graphics_methods(): # clear file and regenerate from scratch - - f = open(current_module.joinpath("layouts/graphic_methods_mixin.py"), "w") + f = open(filename, "w", encoding="utf-8") f.write("# This is an auto-generated file and should not be modified directly\n\n") @@ -72,5 +75,17 @@ def generate_add_graphics_methods(): f.close() +def blacken(): + with open(filename, "r", encoding="utf-8") as f: + text = f.read() + + mode = black.FileMode(line_length=88) + text = black.format_str(text, mode=mode) + + with open(filename, "w", encoding="utf-8") as f: + f.write(text) + + if __name__ == "__main__": generate_add_graphics_methods() + blacken() diff --git a/setup.py b/setup.py index 1d274fc0a..2622b1406 100644 --- a/setup.py +++ b/setup.py @@ -20,19 +20,15 @@ "nbsphinx", "pandoc", "jupyterlab", - "sidecar" + "sidecar", ], - - "notebook": - [ + "notebook": [ "jupyterlab", "jupyter-rfb>=0.4.1", "ipywidgets>=8.0.0,<9", - "sidecar" + "sidecar", ], - - "tests": - [ + "tests": [ "pytest<8.0.0", "nbmake", "scipy", @@ -42,17 +38,15 @@ "ipywidgets>=8.0.0,<9", "scikit-learn", "tqdm", - "sidecar" + "sidecar", ], - - "tests-desktop": - [ + "tests-desktop": [ "pytest<8.0.0", "scipy", "imageio", "scikit-learn", "tqdm", - ] + ], } @@ -72,19 +66,18 @@ setup( - name='fastplotlib', + name="fastplotlib", version=ver, long_description=readme, - long_description_content_type='text/markdown', + long_description_content_type="text/markdown", packages=find_packages(), - url='https://github.com/fastplotlib/fastplotlib', - license='Apache 2.0', - author='Kushal Kolar, Caitlin Lewis', - author_email='', - python_requires='>=3.9', + url="https://github.com/fastplotlib/fastplotlib", + license="Apache 2.0", + author="Kushal Kolar, Caitlin Lewis", + author_email="", + python_requires=">=3.9", install_requires=install_requires, extras_require=extras_require, include_package_data=True, - description='A fast plotting library built using the pygfx render engine' + description="A fast plotting library built using the pygfx render engine", ) -