Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Ruff #785

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Ruff #785

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
24 changes: 0 additions & 24 deletions .github/workflows/black.yml

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: lint

on:
push:
branches:
- main
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
lint:
name: Test Linting
timeout-minutes: 5
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
- name: Ruff lint
run: |
ruff check --output-format=github .
- name: Ruff format
run: |
ruff format --check .
10 changes: 5 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"sphinx.ext.viewcode",
"sphinx_copybutton",
"sphinx_design",
"sphinx_gallery.gen_gallery"
"sphinx_gallery.gen_gallery",
]

sphinx_gallery_conf = {
Expand All @@ -70,9 +70,9 @@
"../../examples/qt",
]
),
"ignore_pattern": r'__init__\.py',
"ignore_pattern": r"__init__\.py",
"nested_sections": False,
"thumbnail_size": (250, 250)
"thumbnail_size": (250, 250),
}

extra_conf = find_examples_for_gallery(EXAMPLES_DIR)
Expand Down Expand Up @@ -100,8 +100,8 @@
"check_switcher": True,
"switcher": {
"json_url": "http://www.fastplotlib.org/_static/switcher.json",
"version_match": release
}
"version_match": release,
},
}

html_static_path = ["_static"]
Expand Down
35 changes: 12 additions & 23 deletions docs/source/generate_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@
"fastplotlib\n"
"***********\n\n"
".. currentmodule:: fastplotlib\n\n"

".. autofunction:: fastplotlib.pause_events\n\n"

".. autofunction:: fastplotlib.enumerate_adapters\n\n"

".. autofunction:: fastplotlib.select_adapter\n\n"

".. autofunction:: fastplotlib.print_wgpu_report\n\n"

"fastplotlib.loop\n"
"------------------\n"
"See the rendercanvas docs: https://rendercanvas.readthedocs.io/stable/api.html#rendercanvas.BaseLoop "
Expand All @@ -60,7 +55,6 @@
f.write(
"fastplotlib.utils\n"
"*****************\n\n"

"..currentmodule:: fastplotlib.utils\n"
"..automodule:: fastplotlib.utils.functions\n"
" : members:\n"
Expand Down Expand Up @@ -106,8 +100,8 @@

underline = "=" * len(name)

methods_str = "\n ".join([""] + methods)

Check failure on line 103 in docs/source/generate_api.py

View workflow job for this annotation

GitHub Actions / Test Linting

Ruff (RUF005)

docs/source/generate_api.py:103:33: RUF005 Consider `["", *methods]` instead of concatenation
properties_str = "\n ".join([""] + properties)

Check failure on line 104 in docs/source/generate_api.py

View workflow job for this annotation

GitHub Actions / Test Linting

Ruff (RUF005)

docs/source/generate_api.py:104:36: RUF005 Consider `["", *properties]` instead of concatenation

out = (
f"{underline}\n"
Expand Down Expand Up @@ -161,15 +155,9 @@
):
page_name_underline = "*" * len(page_name)
with open(source_path, "w") as f:
f.write(
f".. _api.{page_name}:\n"
f"\n"
f"{page_name}\n"
f"{page_name_underline}\n"
f"\n"
)
f.write(f".. _api.{page_name}:\n\n{page_name}\n{page_name_underline}\n\n")

for cls, module in zip(classes, modules):
for cls, module in zip(classes, modules, strict=False):
to_write = generate_class(cls, module)
f.write(to_write)

Expand Down Expand Up @@ -199,15 +187,15 @@
# layouts classes index file
with open(LAYOUTS_DIR.joinpath("index.rst"), "w") as f:
f.write(
f"Layouts\n"
f"********\n"
f"\n"
f".. toctree::\n"
f" :maxdepth: 1\n"
f"\n"
f" imgui_figure\n"
f" figure\n"
f" subplot\n"
"Layouts\n"
"********\n"
"\n"
".. toctree::\n"
" :maxdepth: 1\n"
"\n"
" imgui_figure\n"
" figure\n"
" subplot\n"
)

# the rest of this is a mess and can be refactored later
Expand All @@ -216,7 +204,7 @@

graphic_class_names = [g.__name__ for g in graphic_classes]

graphic_class_names_str = "\n ".join([""] + graphic_class_names)

Check failure on line 207 in docs/source/generate_api.py

View workflow job for this annotation

GitHub Actions / Test Linting

Ruff (RUF005)

docs/source/generate_api.py:207:45: RUF005 Consider `["", *graphic_class_names]` instead of concatenation

# graphic classes index file
with open(GRAPHICS_DIR.joinpath("index.rst"), "w") as f:
Expand All @@ -242,7 +230,7 @@

feature_class_names = [f.__name__ for f in feature_classes]

feature_class_names_str = "\n ".join([""] + feature_class_names)

Check failure on line 233 in docs/source/generate_api.py

View workflow job for this annotation

GitHub Actions / Test Linting

Ruff (RUF005)

docs/source/generate_api.py:233:45: RUF005 Consider `["", *feature_class_names]` instead of concatenation

with open(GRAPHIC_FEATURES_DIR.joinpath("index.rst"), "w") as f:
f.write(
Expand All @@ -267,7 +255,7 @@

selector_class_names = [s.__name__ for s in selector_classes]

selector_class_names_str = "\n ".join([""] + selector_class_names)

Check failure on line 258 in docs/source/generate_api.py

View workflow job for this annotation

GitHub Actions / Test Linting

Ruff (RUF005)

docs/source/generate_api.py:258:46: RUF005 Consider `["", *selector_class_names]` instead of concatenation

with open(SELECTORS_DIR.joinpath("index.rst"), "w") as f:
f.write(
Expand All @@ -292,7 +280,7 @@

widget_class_names = [w.__name__ for w in widget_classes]

widget_class_names_str = "\n ".join([""] + widget_class_names)

Check failure on line 283 in docs/source/generate_api.py

View workflow job for this annotation

GitHub Actions / Test Linting

Ruff (RUF005)

docs/source/generate_api.py:283:44: RUF005 Consider `["", *widget_class_names]` instead of concatenation

with open(WIDGETS_DIR.joinpath("index.rst"), "w") as f:
f.write(
Expand All @@ -317,7 +305,7 @@

ui_class_names = [cls.__name__ for cls in ui_classes]

ui_class_names_str = "\n ".join([""] + ui_class_names)

Check failure on line 308 in docs/source/generate_api.py

View workflow job for this annotation

GitHub Actions / Test Linting

Ruff (RUF005)

docs/source/generate_api.py:308:40: RUF005 Consider `["", *ui_class_names]` instead of concatenation

with open(UI_DIR.joinpath("index.rst"), "w") as f:
f.write(
Expand Down Expand Up @@ -362,5 +350,6 @@
" utils\n"
)


if __name__ == "__main__":
main()
8 changes: 2 additions & 6 deletions examples/gridplot/gridplot_viewports_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@
import numpy as np


figure = fpl.Figure(
shape=(2, 3),
size=(700, 560),
names=list(map(str, range(6)))
)
figure = fpl.Figure(shape=(2, 3), size=(700, 560), names=list(map(str, range(6))))

np.random.seed(0)
a = np.random.rand(6, 10, 10)

for data, subplot in zip(a, figure):
for data, subplot in zip(a, figure, strict=False):
subplot.add_image(data)
subplot.docks["left"].size = 20
subplot.docks["right"].size = 30
Expand Down
13 changes: 4 additions & 9 deletions examples/gridplot/multigraphic_gridplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
figure = fpl.Figure(
shape=(2, 2),
names=[["image-overlay", "circles"], ["line-stack", "scatter"]],
size=(700, 560)
size=(700, 560),
)

img = iio.imread("imageio:coffee.png")
Expand All @@ -36,6 +36,7 @@
# add overlay to image
figure["image-overlay"].add_image(data=overlay)


# generate some circles
def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray:
theta = np.linspace(0, 2 * np.pi, n_points)
Expand All @@ -54,12 +55,7 @@ def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray:
circles.append(make_circle(center, 5, n_points=75))

# things like class labels, cluster labels, etc.
cmap_transform = [
0, 1, 1, 2,
0, 0, 1, 1,
2, 2, 8, 3,
1, 9, 1, 5
]
cmap_transform = [0, 1, 1, 2, 0, 0, 1, 1, 2, 2, 8, 3, 1, 9, 1, 5]

# add an image to overlay the circles on
img2 = iio.imread("imageio:coins.png")[10::5, 5::5]
Expand All @@ -73,7 +69,7 @@ def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray:
cmap_transform=cmap_transform,
thickness=3,
alpha=0.5,
name="circles-graphic"
name="circles-graphic",
)

# move the circles graphic so that it is centered over the image
Expand Down Expand Up @@ -115,4 +111,3 @@ def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray:
if __name__ == "__main__":
print(__doc__)
fpl.loop.run()

16 changes: 12 additions & 4 deletions examples/guis/image_widget_imgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ def update(self):
something_changed = False

# slider for gaussian filter sigma value
changed, value = imgui.slider_float(label="sigma", v=self.sigma, v_min=0.0, v_max=20.0)
changed, value = imgui.slider_float(
label="sigma", v=self.sigma, v_min=0.0, v_max=20.0
)
if changed:
self.sigma = value
something_changed = True

# int entries for gaussian filter order
for axis in ["x", "y"]:
changed, value = imgui.input_int(f"order {axis}", v=getattr(self, f"order_{axis}"))
changed, value = imgui.input_int(
f"order {axis}", v=getattr(self, f"order_{axis}")
)
if changed:
if value < 0:
value = 0
Expand All @@ -63,11 +67,15 @@ def update(self):
# do not call imgui.end_frame(), this is handled by Figure

def process_image(self):
processed = gaussian_filter(a, sigma=self.sigma, order=(self.order_y, self.order_x))
processed = gaussian_filter(
a, sigma=self.sigma, order=(self.order_y, self.order_x)
)
iw.set_data(processed)


gui = ImageProcessingWindow(iw.figure, size=200, location="right", title="Gaussian Filter")
gui = ImageProcessingWindow(
iw.figure, size=200, location="right", title="Gaussian Filter"
)


iw.figure.add_gui(gui)
Expand Down
28 changes: 21 additions & 7 deletions examples/guis/imgui_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
figure = fpl.Figure(size=(700, 560))

# make some scatter points at every 10th point
figure[0, 0].add_scatter(data[::10], colors="cyan", sizes=15, name="sine-scatter", uniform_color=True)
figure[0, 0].add_scatter(
data[::10], colors="cyan", sizes=15, name="sine-scatter", uniform_color=True
)

# place a line above the scatter
figure[0, 0].add_line(data, thickness=3, colors="r", name="sine-wave", uniform_color=True)
figure[0, 0].add_line(
data, thickness=3, colors="r", name="sine-wave", uniform_color=True
)


class ImguiExample(EdgeWindow):
Expand Down Expand Up @@ -60,27 +64,35 @@ def update(self):
# get current line color alpha value
alpha = self._line.colors[-1]
# make float slider
changed_alpha, new_alpha = imgui.slider_float("alpha", v=alpha, v_min=0.0, v_max=1.0)
changed_alpha, new_alpha = imgui.slider_float(
"alpha", v=alpha, v_min=0.0, v_max=1.0
)

# if RGB or alpha changed
if changed_color | changed_alpha:
# set new color along with alpha
self._line.colors = [*rgb, new_alpha]

# example of a slider, you can also use input_float
changed, amplitude = imgui.slider_float("amplitude", v=self._amplitude, v_max=10, v_min=0.1)
changed, amplitude = imgui.slider_float(
"amplitude", v=self._amplitude, v_max=10, v_min=0.1
)
if changed:
# set y values
self._amplitude = amplitude
self._set_data()

# slider for thickness
changed, thickness = imgui.slider_float("thickness", v=self._line.thickness, v_max=50.0, v_min=2.0)
changed, thickness = imgui.slider_float(
"thickness", v=self._line.thickness, v_max=50.0, v_min=2.0
)
if changed:
self._line.thickness = thickness

# slider for gaussian noise
changed, sigma = imgui.slider_float("noise-sigma", v=self._sigma, v_max=1.0, v_min=0.0)
changed, sigma = imgui.slider_float(
"noise-sigma", v=self._sigma, v_max=1.0, v_min=0.0
)
if changed:
self._sigma = sigma
self._set_data()
Expand All @@ -99,7 +111,9 @@ def update(self):
self._set_data()

def _set_data(self):
self._line.data[:, 1] = (np.sin(xs) * self._amplitude) + np.random.normal(scale=self._sigma, size=100)
self._line.data[:, 1] = (np.sin(xs) * self._amplitude) + np.random.normal(
scale=self._sigma, size=100
)


# make GUI instance
Expand Down
5 changes: 1 addition & 4 deletions examples/image/image_small.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

figure = fpl.Figure(size=(700, 560))

data = np.array(
[[0, 1, 2],
[3, 4, 5]]
)
data = np.array([[0, 1, 2], [3, 4, 5]])
image_graphic = figure[0, 0].add_image(data)

figure.show()
Expand Down
2 changes: 1 addition & 1 deletion examples/image_widget/image_widget_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

iw = fpl.ImageWidget(
data=[img1, img2, img3, img4],
rgb=[False, True, True, True], # mix of grayscale and RGB images
rgb=[False, True, True, True], # mix of grayscale and RGB images
names=["cameraman", "astronaut", "chelsea", "Almar's cat"],
# ImageWidget will sync controllers by default
# by setting `controller_ids=None` we can have independent controllers for each subplot
Expand Down
2 changes: 1 addition & 1 deletion examples/image_widget/image_widget_videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
[random_data, cockatoo_sub],
rgb=[False, True],
figure_shape=(2, 1), # 2 rows, 1 column
figure_kwargs={"size": (700, 940)}
figure_kwargs={"size": (700, 940)},
)

iw.show()
Expand Down
10 changes: 2 additions & 8 deletions examples/line/line_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,13 @@

# cmap_transform from an array, so the colors on the sine line will be based on the sine y-values
sine_graphic = figure[0, 0].add_line(
data=sine,
thickness=10,
cmap="plasma",
cmap_transform=sine[:, 1]
data=sine, thickness=10, cmap="plasma", cmap_transform=sine[:, 1]
)

# qualitative colormaps, useful for cluster labels or other types of categorical labels
labels = [0] * 25 + [5] * 10 + [1] * 35 + [2] * 30
cosine_graphic = figure[0, 0].add_line(
data=cosine,
thickness=10,
cmap="tab10",
cmap_transform=labels
data=cosine, thickness=10, cmap="tab10", cmap_transform=labels
)

figure.show()
Expand Down
Loading