Skip to content
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

Add codestyle check #24

Merged
merged 4 commits into from
May 16, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
name: Deploy Examples
name: CI Workflows

on:
push:
branches:
master
pull_request:

permissions:
contents: write

jobs:
deploy:

initial_checks:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
with:
coverage: false
envs: |
# Code style
- linux: codestyle

deploy-examples:
if: github.event_name != "pull_request"
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
9 changes: 4 additions & 5 deletions glue_ar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from glue_ar.export_scatter import *
from glue_ar.export_volume import *
from glue_ar.tools import *
from glue_ar.export_scatter import * # noqa
from glue_ar.export_volume import * # noqa
from glue_ar.tools import * # noqa


def setup():
from glue_qt.config import qt_client


from glue_vispy_viewers.scatter.scatter_viewer import VispyScatterViewer
VispyScatterViewer.tools += ["ar"]
VispyScatterViewer.subtools = {
Expand Down
5 changes: 3 additions & 2 deletions glue_ar/common.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pyvista as pv


def layers_info(info_creator, viewer_state, layer_states=None):
info = {}
if layer_states is None:
layer_states = list((l for l in viewer_state.layers if l.visible))
layer_states = list((layer for layer in viewer_state.layers if layer.visible))

for layer_state in layer_states:
info[layer_state.layer.uuid] = info_creator(viewer_state, layer_state)
Expand All @@ -22,7 +23,7 @@ def create_plotter(adder, info_creator, viewer_state, layer_states=None):

# The only error so far I've seen is a ValueError when using Plotter.add_mesh if
# the mesh is empty (n_arrays = 0). We can be more explicit once our code is more definite
except:
except Exception:
pass

return plotter
11 changes: 7 additions & 4 deletions glue_ar/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import pyvista as pv
from gltflib.gltf import GLTF

GLTF_PIPELINE_FILEPATH = join(dirname(abspath(__file__)), "js", "node_modules", "gltf-pipeline", "bin", "gltf-pipeline.js")
GLTF_PIPELINE_FILEPATH = join(dirname(abspath(__file__)), "js",
"node_modules", "gltf-pipeline",
"bin", "gltf-pipeline.js")


def export_meshes(meshes, output_path):
Expand Down Expand Up @@ -63,16 +65,17 @@ def export_gl(plotter, filepath, with_alpha=True, compress=True):


def export_modelviewer(output_path, gltf_path, alt_text):
mv_url = "https://ajax.googleapis.com/ajax/libs/model-viewer/3.3.0/model-viewer.min.js"
html = f"""
<html>
<body>
<script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.3.0/model-viewer.min.js"></script>
<script type="module" src="{mv_url}"></script>
<style>
model-viewer {{
width: 100%;
height: 100%;
}}

/* This keeps child nodes hidden while the element loads */
:not(:defined) > * {{
display: none;
Expand Down Expand Up @@ -163,6 +166,6 @@ def export_modelviewer(output_path, gltf_path, alt_text):
</body>
</html>
"""

with open(output_path, 'w') as f:
f.write(html)
2 changes: 0 additions & 2 deletions glue_ar/export_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from glue.core.data_combo_helper import ComboHelper
from glue.core.state_objects import State
from glue_qt.utils import load_ui
from qtpy.QtGui import QDoubleValidator, QIntValidator


from qtpy.QtWidgets import QCheckBox, QDialog, QHBoxLayout, QLabel, QLineEdit
from qtpy.QtGui import QIntValidator, QDoubleValidator
Expand Down
3 changes: 2 additions & 1 deletion glue_ar/exporting_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

__all__ = ['ExportingDialog']


class ExportingDialog(QDialog):

_max_dots = 3

def __init__(self, parent=None, filetype=None):
Expand Down
1 change: 0 additions & 1 deletion glue_ar/qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ def create_qr(url):
box = ((width - logo_img.size[0]) // 2, (height - logo_img.size[1]) // 2)
img.paste(logo_img, box)
return img

2 changes: 1 addition & 1 deletion glue_ar/qr_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class QRDialog(QDialog):

def __init__(self, parent, url=None, img=None):

super(QRDialog, self).__init__(parent=parent)
img = create_qr(url)
self.img = ImageQt(img)
Expand Down
4 changes: 2 additions & 2 deletions glue_ar/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def scatter_layer_as_multiblock(viewer_state, layer_state,
sizes = sqrt(ones(size_data.shape) * 10)
else:
sizes = sqrt((20 * (size_data - layer_state.size_vmin) /
(layer_state.size_vmax - layer_state.size_vmin)))
(layer_state.size_vmax - layer_state.size_vmin)))
sizes *= (layer_state.size_scaling / factor)
sizes[isnan(sizes)] = 0.
spheres = [pv.Sphere(center=p, radius=r,
Expand Down Expand Up @@ -193,7 +193,7 @@ def scatter_layer_as_multiblock(viewer_state, layer_state,
for axis in ['x', 'y', 'z']:
if getattr(layer_state, f"{axis}err_visible"):
axis_bars = meshes_for_error_bars(viewer_state, layer_state,
axis, data, bounds, mask=mask)
axis, data, bounds, mask=mask)
bars.extend(axis_bars)
if not fixed_color:
bars_cmap_values.extend([y for x in cmap_values for y in (x,) * 2]) # Each line has just two points
Expand Down
6 changes: 2 additions & 4 deletions glue_ar/server.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from os.path import split

from http.server import SimpleHTTPRequestHandler
from socketserver import TCPServer


def create_handler(directory):

class ARHttpRequestHandler(SimpleHTTPRequestHandler):

def __init__(self, *args, **kwargs):
super().__init__(*args, directory=directory, **kwargs)

Expand All @@ -16,5 +14,5 @@ def __init__(self, *args, **kwargs):

def run_ar_server(port, directory):
handler_cls = create_handler(directory)
server = TCPServer(("", port), handler_cls)
server = TCPServer(("", port), handler_cls)
return server
9 changes: 3 additions & 6 deletions glue_ar/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ def activate(self):
if result == QDialog.Rejected:
return

export_path, _ = compat.getsavefilename(parent=self.viewer, basedir=f"{self._default_filename}.{dialog.state.filetype.lower()}")
export_path, _ = compat.getsavefilename(parent=self.viewer,
basedir=f"{self._default_filename}.{dialog.state.filetype.lower()}")
if not export_path:
return

_, ext = splitext(export_path)
filetype = _FILETYPE_NAMES.get(ext, None)
worker = Worker(self._export_to_ar, export_path, dialog.state_dictionary, compress=dialog.state.draco)
Expand All @@ -123,8 +124,6 @@ def _export_to_ar(self, filepath, state_dict, compress=True):
plotter.export_obj(filepath)




@viewer_tool
class ARLocalQRTool(Tool):
icon = AR_ICON
Expand All @@ -141,7 +140,6 @@ def activate(self):
_, gltf_base = split(gltf_tmp.name)
export_modelviewer(html_tmp.name, gltf_base, self.viewer.state.title)


port = 4000
directory, filename = split(html_tmp.name)
server = run_ar_server(port, directory)
Expand All @@ -168,4 +166,3 @@ def activate(self):
pass
server.shutdown()
server.server_close()

6 changes: 3 additions & 3 deletions glue_ar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def bounds_3d_from_layers(viewer_state, layer_states):
data = state.layer.layer
mins = [min(min(data[att]), m) for m, att in zip(mins, atts)]
maxes = [max(max(data[att]), m) for m, att in zip(maxes, atts)]
return [(l, u) for l, u in zip(mins, maxes)]
return [(lo, hi) for lo, hi in zip(mins, maxes)]


def slope_intercept_between(a, b):
Expand Down Expand Up @@ -66,7 +66,7 @@ def bring_into_clip(data, bounds, preserve_aspect=True):
line_data = [slope_intercept_between((bds[0], -1), (bds[1], 1)) for bds in bounds]

scaled = [[m * d + b for d in data[idx]] for idx, (m, b) in enumerate(line_data)]

return scaled


Expand Down Expand Up @@ -95,5 +95,5 @@ def xyz_for_layer(viewer_state, layer_state,
if scaled:
bounds = xyz_bounds(viewer_state)
vals = bring_into_clip(vals, bounds, preserve_aspect=preserve_aspect)

return array(list(zip(*vals)))
10 changes: 5 additions & 5 deletions glue_ar/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def meshes_for_volume_layer(viewer_state, layer_state, bounds,

def bounds_3d(viewer_state):
return [(viewer_state.z_min, viewer_state.z_max, viewer_state.resolution),
(viewer_state.y_min, viewer_state.y_max, viewer_state.resolution),
(viewer_state.x_min, viewer_state.x_max, viewer_state.resolution)]
(viewer_state.y_min, viewer_state.y_max, viewer_state.resolution),
(viewer_state.x_min, viewer_state.x_max, viewer_state.resolution)]


# For the 3D volume viewer
Expand Down Expand Up @@ -163,7 +163,6 @@ def create_meshes(viewer_state, layer_states, parameters):
parent_data = invert(subcube) * parent_data
meshes[parent.label]["data"] = parent_data


for label, item in meshes.items():
data = item["data"]
isomin = item["isomin"]
Expand All @@ -177,7 +176,9 @@ def create_meshes(viewer_state, layer_states, parameters):
grid = pv.ImageData()
grid.dimensions = (viewer_state.resolution,) * 3
grid.origin = (viewer_state.x_min, viewer_state.y_min, viewer_state.z_min)
# Comment from Luca: # I think the voxel spacing will always be 1, because of how glue downsamples to a fixed resolution grid. But don't hold me to this!
# Comment from Luca: # I think the voxel spacing will always be 1,
# because of how glue downsamples to a fixed resolution grid.
# But don't hold me to this!
grid.spacing = (1, 1, 1)
grid.point_data["values"] = data.flatten(order="F")
isodata = grid.contour([isomin])
Expand All @@ -189,4 +190,3 @@ def create_meshes(viewer_state, layer_states, parameters):
item["mesh"] = isodata

return meshes

5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def data_files(root_directory):
"pyvista",
"segno"
],
extras_require={
"test": [
"flake8"
]
},
entry_points={
"glue.plugins": "glue_ar = glue_ar:setup"
}
Expand Down
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[testenv:codestyle]
deps = flake8
skipsdist = true
skip_install = true
commands =
flake8 --max-line-length=120 --exclude=external glue_ar