Skip to content

Commit

Permalink
ci: use pyproject and ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Jan 7, 2025
1 parent 414545f commit 290cd3e
Show file tree
Hide file tree
Showing 26 changed files with 213 additions and 139 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/test_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,17 @@ jobs:
needs: [pre-commit, pytest]
runs-on: ubuntu-latest
if: github.event_name == 'push'
environment:
name: pypi
url: https://pypi.org/p/trame
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
contents: write # IMPORTANT: mandatory for making GitHub Releases


steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -105,8 +112,11 @@ jobs:
bash .fetch_externals.sh
- name: Python Semantic Release
uses: relekang/[email protected]
id: release
uses: relekang/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
repository_username: __token__
repository_password: ${{ secrets.PYPI_API_TOKEN }}

- name: Publish package distributions to PyPI
if: steps.release.outputs.released == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
14 changes: 4 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
entry: black --check

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
args: ['--ignore-words=.ignore-words.txt']

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
hooks:
- id: flake8
- id: ruff
- id: ruff-format
2 changes: 1 addition & 1 deletion examples/pyvista/ambient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import html, vuetify
from trame.widgets import vuetify
from trame.widgets.vtk import VtkLocalView, VtkRemoteView

import pyvista as pv
Expand Down
1 change: 1 addition & 0 deletions examples/pyvista/export_scene.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Export scene for offline rendering.
https://kitware.github.io/vtk-js/examples/OfflineLocalView.html
"""

from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import vuetify
Expand Down
2 changes: 1 addition & 1 deletion examples/pyvista/grid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import grid, vuetify
from trame.widgets import grid

server = get_server()
state = server.state
Expand Down
2 changes: 1 addition & 1 deletion examples/pyvista/lighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import html, vuetify
from trame.widgets import vuetify
from trame.widgets.vtk import VtkLocalView, VtkRemoteView

import pyvista as pv
Expand Down
4 changes: 1 addition & 3 deletions examples/pyvista/picking.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import numpy as np
from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import vuetify
Expand Down Expand Up @@ -43,8 +42,7 @@ def toggle_edges():


@ctrl.set("on_selection_change")
def on_box_selection(event):
...
def on_box_selection(event): ...


@state.change("selection_mode")
Expand Down
1 change: 0 additions & 1 deletion examples/pyvista/scalar_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from trame.widgets import vuetify

import pyvista as pv
from pyvista import examples
from pyvista.trame.ui import plotter_ui

# -----------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion examples/pyvista/toggle_edge_lighting.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Validate Int64 usage with VTK.js."""

import numpy as np
from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import vuetify
Expand Down
2 changes: 1 addition & 1 deletion examples/pyvista/toggle_edges_many_actors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# for remote view
from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import html, vtk as vtk_widgets, vuetify
from trame.widgets import vtk as vtk_widgets, vuetify
from vtkmodules.vtkFiltersSources import vtkConeSource
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleSwitch # noqa
from vtkmodules.vtkRenderingCore import (
Expand Down
1 change: 0 additions & 1 deletion examples/validation/BigIntCoords.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from trame.ui.html import DivLayout
from trame.widgets import vtk

from vtkmodules.vtkFiltersSources import vtkConeSource
from vtkmodules.vtkIOXML import vtkXMLRectilinearGridReader
from vtkmodules.vtkRenderingCore import (
vtkActor,
Expand Down
6 changes: 4 additions & 2 deletions examples/validation/CaptureImageLocal.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ def save_image_on_server(screenshot_file):
):
view = vtk_widgets.VtkLocalView(
renderWindow,
on_image_capture="utils.download('local.png', $event)", # For client side handling
# on_image_capture=(save_image_on_server, "[new File([$event], 'screenshot.png')]"), # For server side handling
# For client side handling
on_image_capture="utils.download('local.png', $event)",
# For server side handling
# on_image_capture=(save_image_on_server, "[new File([$event], 'screenshot.png')]"),
)
ctrl.view_update = view.update
ctrl.view_reset_camera = view.reset_camera
Expand Down
1 change: 0 additions & 1 deletion examples/validation/PickingLocalView.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from vtkmodules.vtkRenderingCore import (
vtkRenderer,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkPolyDataMapper,
vtkActor,
)
Expand Down
1 change: 1 addition & 0 deletions examples/validation/PyVistaVolumeRendering.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Validate volume rendering with VTK.js."""

import os
import sys
import pyvista as pv
Expand Down
87 changes: 87 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[project]
name = "trame-vtk"
version = "3.8.13"
description = "VTK widgets for trame"
authors = [
{name = "Kitware Inc."},
]
dependencies = [
"trame-client>=3.4,<4",
]
requires-python = ">=3.9"
readme = "README.rst"
license = {text = "BSD License"}
keywords = ["Python", "Interactive", "Web", "Application", "Framework"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Software Development :: Libraries :: Application Frameworks",
"Topic :: Software Development :: Libraries :: Python Modules",
]

[project.optional-dependencies]
dev = [
"pre-commit",
"ruff",
"pytest",
]

[build-system]
requires = ['setuptools', 'wheel']
build-backend = 'setuptools.build_meta'

[tool.setuptools.packages.find]
where = ["."]

[tool.setuptools.package-data]
trame_vtk = [
"**/modules/common/serve/*.js",
]

[tool.semantic_release]
version_toml = [
"pyproject.toml:project.version",
]
build_command = """
python -m venv .venv
source .venv/bin/activate
pip install -U pip build
python -m build .
"""

[semantic_release.publish]
dist_glob_patterns = ["dist/*"]
upload_to_vcs_release = true

[tool.ruff]
line-length = 88
indent-width = 4
target-version = "py39"

[tool.ruff.lint]
select = ["E", "W", "F"]
ignore = []
fixable = ["ALL"]
unfixable = []


[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
docstring-code-format = true

# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"

[tool.ruff.lint.pycodestyle]
max-line-length = 120

[lint.pydocstyle]
convention = "google"
33 changes: 0 additions & 33 deletions setup.cfg

This file was deleted.

3 changes: 0 additions & 3 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion trame/modules/paraview.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from trame_vtk.modules.common import *
from trame_vtk.modules.common import * # noqa: F403
2 changes: 1 addition & 1 deletion trame/modules/vtk.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from trame_vtk.modules.common import *
from trame_vtk.modules.common import * # noqa: F403
2 changes: 1 addition & 1 deletion trame/widgets/paraview.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from trame_vtk.widgets.vtk import *
from trame_vtk.widgets.vtk import * # noqa: F403


def initialize(server):
Expand Down
2 changes: 1 addition & 1 deletion trame/widgets/vtk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from trame_vtk.widgets.vtk import *
from trame_vtk.widgets.vtk import * # noqa: F403


def initialize(server):
Expand Down
12 changes: 8 additions & 4 deletions trame_vtk/modules/paraview/protocols/local_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ def push_geometry(new_subscription=False):
return state_to_return

if real_view_id not in self.tracking_views:
observer_callback = lambda *args, **kwargs: self.publish(
"viewport.geometry.view.subscription", push_geometry()
)

def observer_callback(*_, **__):
return self.publish(
"viewport.geometry.view.subscription",
push_geometry(),
)

tag = self.app.AddObserver("UpdateEvent", observer_callback)
self.tracking_views[real_view_id] = {"tags": [tag], "observerCount": 1}
else:
Expand Down Expand Up @@ -92,7 +96,7 @@ def get_view_state(
new_subscription=False,
widgets=None,
orientation_axis=0,
**kwargs
**kwargs,
):
s_view = self.get_view(view_id)
if not s_view:
Expand Down
17 changes: 10 additions & 7 deletions trame_vtk/modules/paraview/protocols/publish_image_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,16 @@ def add_render_observer(self, view_id):
real_view_id = s_view.GetGlobalIDAsString()

if real_view_id not in self.tracking_views:
observer_callback = lambda *args, **kwargs: self.push_render(real_view_id)
start_callback = lambda *args, **kwargs: self.start_view_animation(
real_view_id
)
stop_callback = lambda *args, **kwargs: self.stop_view_animation(
real_view_id
)

def observer_callback(*_, **__):
return self.push_render(real_view_id)

def start_callback(*_, **__):
return self.start_view_animation(real_view_id)

def stop_callback(*_, **__):
return self.stop_view_animation(real_view_id)

tag = self.app.AddObserver("UpdateEvent", observer_callback)
tag_start = self.app.AddObserver("StartInteractionEvent", start_callback)
tag_stop = self.app.AddObserver("EndInteractionEvent", stop_callback)
Expand Down
12 changes: 8 additions & 4 deletions trame_vtk/modules/vtk/protocols/local_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ def push_geometry(new_subscription=False):
return state_to_return

if real_view_id not in self.tracking_views:
observer_callback = lambda *args, **kwargs: self.publish(
"viewport.geometry.view.subscription", push_geometry()
)

def observer_callback(*_, **__):
return self.publish(
"viewport.geometry.view.subscription",
push_geometry(),
)

tag = self.app.AddObserver("UpdateEvent", observer_callback)
self.tracking_views[real_view_id] = {"tags": [tag], "observerCount": 1}
else:
Expand Down Expand Up @@ -95,7 +99,7 @@ def get_view_state(
new_subscription=False,
widgets=None,
orientation_axis=0,
**kwargs
**kwargs,
):
s_view = self.get_view(view_id)
if not s_view:
Expand Down
Loading

0 comments on commit 290cd3e

Please sign in to comment.