Skip to content

Commit

Permalink
Merge branch 'main' into fix/test_suite_warnings
Browse files Browse the repository at this point in the history
* upstream/main:
  Python 3 style using pyupgrade (pyvista#3638)
  Move google_analytics_id to analytics in pydata-sphinx-theme (pyvista#3634)
  • Loading branch information
adeak committed Nov 25, 2022
2 parents 1b69bec + 8c3f6d9 commit 959eb01
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 38 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ repos:
"typing-extensions==4.1.1",
]

- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
hooks:
- id: pyupgrade
args: [--py37-plus, --keep-runtime-typing]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
Expand Down
8 changes: 3 additions & 5 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import datetime
import faulthandler
import locale
import os
import sys

# Otherwise VTK reader issues on some systems, causing sphinx to crash. See also #226.
locale.setlocale(locale.LC_ALL, "en_US.UTF-8")

if sys.version_info >= (3, 0):
import faulthandler

faulthandler.enable()
faulthandler.enable()

sys.path.insert(0, os.path.abspath("."))
import make_external_gallery
Expand Down Expand Up @@ -433,7 +431,7 @@ def _str_examples(self):
# documentation.
#
html_theme_options = {
"google_analytics_id": "UA-140243896-1",
"analytics": {"google_analytics_id": "UA-140243896-1"},
"show_prev_next": False,
"github_url": "https://github.com/pyvista/pyvista",
"collapse_navigation": True,
Expand Down
3 changes: 1 addition & 2 deletions pyvista/core/datasetattributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ def __contains__(self, name: str) -> bool:

def __iter__(self) -> Iterator[str]:
"""Implement for loop iteration."""
for array in self.keys():
yield array
yield from self.keys()

def __len__(self) -> int:
"""Return the number of arrays."""
Expand Down
4 changes: 3 additions & 1 deletion pyvista/core/filters/poly_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,9 @@ def multi_ray_trace(
)
if retry:
# gather intersecting rays in lists
loc_lst, ray_lst, tri_lst = [arr.tolist() for arr in [locations, index_ray, index_tri]]
loc_lst = locations.tolist()
ray_lst = index_ray.tolist()
tri_lst = index_tri.tolist()

# find indices that trimesh failed on
all_ray_indices = np.arange(len(origins))
Expand Down
18 changes: 9 additions & 9 deletions pyvista/core/pointset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Sub-classes and wrappers for vtk.vtkPointSet."""
import collections.abc as collections
import collections.abc
from functools import wraps
import numbers
import os
Expand Down Expand Up @@ -1293,9 +1293,9 @@ def __init__(self, *args, deep=False, **kwargs) -> None:
self._check_for_consistency()

elif len(args) == 3: # and VTK9:
arg0_is_seq = isinstance(args[0], (np.ndarray, collections.Sequence))
arg1_is_seq = isinstance(args[1], (np.ndarray, collections.Sequence))
arg2_is_seq = isinstance(args[2], (np.ndarray, collections.Sequence))
arg0_is_seq = isinstance(args[0], (np.ndarray, collections.abc.Sequence))
arg1_is_seq = isinstance(args[1], (np.ndarray, collections.abc.Sequence))
arg2_is_seq = isinstance(args[2], (np.ndarray, collections.abc.Sequence))

if all([arg0_is_seq, arg1_is_seq, arg2_is_seq]):
self._from_arrays(None, args[0], args[1], args[2], deep, **kwargs)
Expand All @@ -1304,10 +1304,10 @@ def __init__(self, *args, deep=False, **kwargs) -> None:
raise TypeError('All input types must be sequences.')

elif len(args) == 4: # pragma: no cover
arg0_is_arr = isinstance(args[0], (np.ndarray, collections.Sequence))
arg1_is_arr = isinstance(args[1], (np.ndarray, collections.Sequence))
arg2_is_arr = isinstance(args[2], (np.ndarray, collections.Sequence))
arg3_is_arr = isinstance(args[3], (np.ndarray, collections.Sequence))
arg0_is_arr = isinstance(args[0], (np.ndarray, collections.abc.Sequence))
arg1_is_arr = isinstance(args[1], (np.ndarray, collections.abc.Sequence))
arg2_is_arr = isinstance(args[2], (np.ndarray, collections.abc.Sequence))
arg3_is_arr = isinstance(args[3], (np.ndarray, collections.abc.Sequence))

if all([arg0_is_arr, arg1_is_arr, arg2_is_arr, arg3_is_arr]):
self._from_arrays(args[0], args[1], args[2], args[3], deep)
Expand Down Expand Up @@ -2044,7 +2044,7 @@ def __getitem__(self, key):
if len(key) != 3:
raise RuntimeError('Slices must have exactly 3 dimensions.')
for i, k in enumerate(key):
if isinstance(k, collections.Iterable):
if isinstance(k, collections.abc.Iterable):
raise RuntimeError('Fancy indexing is not supported.')
if isinstance(k, numbers.Integral):
start = stop = k
Expand Down
4 changes: 2 additions & 2 deletions pyvista/ext/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def build_py_coverage(self) -> None:
# is not defined in this module
continue

full_name = '%s.%s' % (mod_name, name)
full_name = f'{mod_name}.{name}'
if self.ignore_pyobj(full_name):
continue

Expand Down Expand Up @@ -257,7 +257,7 @@ def build_py_coverage(self) -> None:
if skip_undoc and not attr.__doc__:
# skip methods without docstring if wished
continue
full_attr_name = '%s.%s' % (full_name, attr_name)
full_attr_name = f'{full_name}.{attr_name}'
if self.ignore_pyobj(full_attr_name):
continue
if full_attr_name not in objects:
Expand Down
2 changes: 1 addition & 1 deletion pyvista/ext/plot_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def run(arguments, content, options, state_machine, state, lineno):
images = []

opts = [
':%s: %s' % (key, val)
f':{key}: {val}'
for key, val in options.items()
if key in ('alt', 'height', 'width', 'scale', 'align')
]
Expand Down
10 changes: 4 additions & 6 deletions pyvista/plotting/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __call__(cls, *args, _wrap=None, **kwargs):
return obj


class _vtkWrapper(object, metaclass=_vtkWrapperMeta):
class _vtkWrapper(metaclass=_vtkWrapperMeta):
def __getattribute__(self, item):
unwrapped_attrs = ["_wrapped", "__class__", "__init__"]
wrapped = super().__getattribute__("_wrapped")
Expand Down Expand Up @@ -978,7 +978,7 @@ def _update_ticks(self):


class _CustomContextItem(_vtk.vtkPythonItem):
class ItemWrapper(object):
class ItemWrapper:
def Initialize(self, item):
# item is the _CustomContextItem subclass instance
return True
Expand Down Expand Up @@ -3419,8 +3419,7 @@ def plots(self, plot_type=None):
"""
plot_types = self.PLOT_TYPES.keys() if plot_type is None else [plot_type]
for plot_type in plot_types:
for plot in self._plots[plot_type]:
yield plot
yield from self._plots[plot_type]

def remove_plot(self, plot):
"""Remove the given plot from this chart.
Expand Down Expand Up @@ -4475,8 +4474,7 @@ def __len__(self):

def __iter__(self):
"""Return an iterable of charts."""
for chart in self._charts:
yield chart
yield from self._charts

def __del__(self):
"""Clean up before being destroyed."""
Expand Down
4 changes: 2 additions & 2 deletions pyvista/plotting/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,9 @@ def _from_rgba(self, rgba):
try:
if len(rgba) != 4:
raise ValueError("Invalid length for RGBA sequence.")
self._red, self._green, self._blue, self._opacity = [
self._red, self._green, self._blue, self._opacity = (
self.convert_color_channel(c) for c in rgba
]
)
except ValueError:
raise ValueError(f"Invalid RGB(A) sequence: {arg}") from None

Expand Down
3 changes: 1 addition & 2 deletions pyvista/plotting/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ def __len__(self):

def __iter__(self):
"""Return a iterable of renderers."""
for renderer in self._renderers:
yield renderer
yield from self._renderers

@property
def active_index(self):
Expand Down
2 changes: 1 addition & 1 deletion pyvista/plotting/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ def _the_callback(widget, event_id):
spline_widget.PlaceWidget(bounds)
spline_widget.SetResolution(resolution)
if initial_points is not None:
spline_widget.InitializeHandles(pyvista.vtk_points((initial_points)))
spline_widget.InitializeHandles(pyvista.vtk_points(initial_points))
else:
spline_widget.SetClosed(closed)
spline_widget.Modified()
Expand Down
4 changes: 2 additions & 2 deletions pyvista/utilities/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ def read(filename, attrs=None, force_ext=None, file_format=None, progress_bar=Fa
except ValueError:
# if using force_ext, we are explicitly only using vtk readers
if force_ext is not None:
raise IOError("This file was not able to be automatically read by pvista.")
raise OSError("This file was not able to be automatically read by pvista.")
from meshio._exceptions import ReadError

try:
return read_meshio(filename)
except ReadError:
raise IOError("This file was not able to be automatically read by pyvista.")
raise OSError("This file was not able to be automatically read by pyvista.")
else:
observer = pyvista.utilities.errors.Observer()
observer.observe(reader.reader)
Expand Down
2 changes: 1 addition & 1 deletion pyvista/utilities/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,7 @@ def _parse_file(self):
)
)
self._datasets = sorted(datasets)
self._time_values = sorted(list(set([dataset.time for dataset in self.datasets])))
self._time_values = sorted({dataset.time for dataset in self.datasets})

self.set_active_time_value(self.time_values[0])

Expand Down
2 changes: 1 addition & 1 deletion requirements_docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ numpydoc==1.5.0
osmnx==1.2.2
panel==0.14.1
param==1.12.2 # due to panel bug
pydata-sphinx-theme==0.11.0
pydata-sphinx-theme==0.12.0
pypandoc==1.10
pytest-sphinx==0.5.0
pythreejs==2.4.1
Expand Down
2 changes: 1 addition & 1 deletion tests/check_doctest_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def check_doctests(modules=None, respect_skips=True, verbose=True):
of failed doctests under the specified modules.
"""
skip_pattern = re.compile('doctest: *\+SKIP') # noqa: W605
skip_pattern = re.compile(r'doctest: *\+SKIP')

if modules is None:
modules = discover_modules()
Expand Down
2 changes: 1 addition & 1 deletion tests/plotting/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _is_vtk(obj):
@pytest.fixture(autouse=True)
def check_gc(request):
"""Ensure that all VTK objects are garbage-collected by Python."""
before = set(id(o) for o in gc.get_objects() if _is_vtk(o))
before = {id(o) for o in gc.get_objects() if _is_vtk(o)}
yield

# Do not check for collection if the test session failed. Tests that fail
Expand Down
2 changes: 1 addition & 1 deletion tests/plotting/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,7 @@ def test_index_vs_loc():
with pytest.raises(TypeError):
pl.renderers.index_to_loc(1.5)
with pytest.raises(IndexError):
pl.renderers.index_to_loc((-1))
pl.renderers.index_to_loc(-1)
with pytest.raises(TypeError):
pl.renderers.index_to_loc((1, 2))
with pytest.raises(IndexError):
Expand Down
8 changes: 8 additions & 0 deletions tests/plotting/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ def test_widget_spline(uniform):
p.add_spline_widget(callback=noop_callback)
p.close()

p = pyvista.Plotter()
p.add_mesh(uniform)
pts = np.array([[1, 5, 4], [2, 4, 9], [3, 6, 2]])
with pytest.raises(ValueError, match='`initial_points` must be length `n_handles`'):
p.add_spline_widget(callback=noop_callback, n_handles=4, initial_points=pts)
p.add_spline_widget(callback=noop_callback, n_handles=3, initial_points=pts)
p.close()

p = pyvista.Plotter()
p.add_mesh(uniform)
p.add_spline_widget(callback=noop_callback, pass_widget=True, color=None, show_ribbon=True)
Expand Down

0 comments on commit 959eb01

Please sign in to comment.