diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f42a65c8c3..08909ca73e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Changed order of imports according to `isort` and changed line length to `179`. * Changed use of `compas.geometry.allclose` to `compas.tolerance.TOL.is_allclose`. * Changed use of `compas.geometry.close` to `compas.tolerance.TOL.is_close`. +* Changed imports of itertools to `compas.itertools` instead of `compas.utilities`. ### Removed diff --git a/src/compas/datastructures/mesh/duality.py b/src/compas/datastructures/mesh/duality.py index 9c133a90cd2..985aebda0bc 100644 --- a/src/compas/datastructures/mesh/duality.py +++ b/src/compas/datastructures/mesh/duality.py @@ -4,7 +4,7 @@ from math import pi -from compas.utilities import flatten +from compas.itertools import flatten PI2 = 2.0 * pi diff --git a/src/compas/datastructures/mesh/mesh.py b/src/compas/datastructures/mesh/mesh.py index bb13df6c6f3..aa2641c817c 100644 --- a/src/compas/datastructures/mesh/mesh.py +++ b/src/compas/datastructures/mesh/mesh.py @@ -53,11 +53,11 @@ from compas.geometry import vector_average from compas.itertools import linspace from compas.itertools import pairwise +from compas.itertools import window from compas.tolerance import TOL from compas.topology import breadth_first_traverse from compas.topology import connected_components from compas.topology import unify_cycles -from compas.utilities import window from .duality import mesh_dual from .operations.collapse import mesh_collapse_edge diff --git a/src/compas/datastructures/mesh/subdivision.py b/src/compas/datastructures/mesh/subdivision.py index 67dd54399b5..190545a2a00 100644 --- a/src/compas/datastructures/mesh/subdivision.py +++ b/src/compas/datastructures/mesh/subdivision.py @@ -8,8 +8,8 @@ from compas.geometry import centroid_points from compas.geometry import offset_polygon +from compas.itertools import iterable_like from compas.itertools import pairwise -from compas.utilities import iterable_like def subd_factory(cls): diff --git a/src/compas/geometry/_core/predicates_3.py b/src/compas/geometry/_core/predicates_3.py index eedb2d6ae84..374d5338bb7 100644 --- a/src/compas/geometry/_core/predicates_3.py +++ b/src/compas/geometry/_core/predicates_3.py @@ -13,8 +13,8 @@ from compas.geometry import length_vector from compas.geometry import normal_polygon from compas.geometry import subtract_vectors +from compas.itertools import window from compas.tolerance import TOL -from compas.utilities import window # ============================================================================= # ============================================================================= diff --git a/src/compas/geometry/interpolation_coons.py b/src/compas/geometry/interpolation_coons.py index 537d1665155..3e69fab28f2 100644 --- a/src/compas/geometry/interpolation_coons.py +++ b/src/compas/geometry/interpolation_coons.py @@ -6,7 +6,7 @@ from compas.geometry import scale_vector from compas.geometry import subtract_vectors from compas.geometry import sum_vectors -from compas.utilities import normalize_values +from compas.itertools import normalize_values def discrete_coons_patch(ab, bc, dc, ad): diff --git a/src/compas/geometry/offset.py b/src/compas/geometry/offset.py index bd8c5ba4fb0..2924dea68e6 100644 --- a/src/compas/geometry/offset.py +++ b/src/compas/geometry/offset.py @@ -12,8 +12,8 @@ from compas.geometry import normalize_vector from compas.geometry import scale_vector from compas.geometry import subtract_vectors +from compas.itertools import iterable_like from compas.itertools import pairwise -from compas.utilities import iterable_like def intersect_lines(l1, l2, tol): diff --git a/src/compas/geometry/projection.py b/src/compas/geometry/projection.py index 36b68a5e6c4..d6a095b6ddd 100644 --- a/src/compas/geometry/projection.py +++ b/src/compas/geometry/projection.py @@ -17,8 +17,8 @@ from compas.geometry import matrix_from_parallel_projection from compas.geometry import matrix_from_perspective_entries from compas.geometry import matrix_from_perspective_projection +from compas.itertools import flatten from compas.tolerance import TOL -from compas.utilities import flatten class Projection(Transformation): diff --git a/src/compas/geometry/quadmesh_planarize_none.py b/src/compas/geometry/quadmesh_planarize_none.py index a1e9e893e47..92487087aa3 100644 --- a/src/compas/geometry/quadmesh_planarize_none.py +++ b/src/compas/geometry/quadmesh_planarize_none.py @@ -9,7 +9,7 @@ from compas.geometry import midpoint_point_point from compas.geometry import project_points_plane from compas.itertools import pairwise -from compas.utilities import window +from compas.itertools import window def mesh_flatness(mesh, maxdev=1.0): diff --git a/src/compas/geometry/reflection.py b/src/compas/geometry/reflection.py index 3ee71118547..314ed8470bd 100644 --- a/src/compas/geometry/reflection.py +++ b/src/compas/geometry/reflection.py @@ -18,8 +18,8 @@ from compas.geometry import identity_matrix from compas.geometry import matrix_from_perspective_entries from compas.geometry import normalize_vector +from compas.itertools import flatten from compas.tolerance import TOL -from compas.utilities import flatten class Reflection(Transformation): diff --git a/src/compas/geometry/rotation.py b/src/compas/geometry/rotation.py index 55f39937a82..f9ecec4914a 100644 --- a/src/compas/geometry/rotation.py +++ b/src/compas/geometry/rotation.py @@ -23,8 +23,8 @@ from compas.geometry import matrix_from_frame from compas.geometry import matrix_from_quaternion from compas.geometry import normalize_vector +from compas.itertools import flatten from compas.tolerance import TOL -from compas.utilities import flatten class Rotation(Transformation): diff --git a/src/compas/geometry/scale.py b/src/compas/geometry/scale.py index 2e65218ea59..2ed8d7fdf8c 100644 --- a/src/compas/geometry/scale.py +++ b/src/compas/geometry/scale.py @@ -17,8 +17,8 @@ from compas.geometry import matrix_from_scale_factors from compas.geometry import matrix_inverse from compas.geometry import multiply_matrices +from compas.itertools import flatten from compas.tolerance import TOL -from compas.utilities import flatten class Scale(Transformation): diff --git a/src/compas/geometry/shear.py b/src/compas/geometry/shear.py index 29fb62e17a2..7de59bdc469 100644 --- a/src/compas/geometry/shear.py +++ b/src/compas/geometry/shear.py @@ -15,8 +15,8 @@ from compas.geometry import decompose_matrix from compas.geometry import matrix_from_shear from compas.geometry import matrix_from_shear_entries +from compas.itertools import flatten from compas.tolerance import TOL -from compas.utilities import flatten class Shear(Transformation): diff --git a/src/compas/geometry/surfaces/nurbs.py b/src/compas/geometry/surfaces/nurbs.py index 601d220c54a..23f7d9a8f86 100644 --- a/src/compas/geometry/surfaces/nurbs.py +++ b/src/compas/geometry/surfaces/nurbs.py @@ -4,9 +4,9 @@ from compas.geometry import Point from compas.itertools import linspace +from compas.itertools import meshgrid from compas.plugins import PluginNotInstalledError from compas.plugins import pluggable -from compas.utilities import meshgrid from .surface import Surface diff --git a/src/compas/geometry/translation.py b/src/compas/geometry/translation.py index 3830cbc7fbf..2b0d5a82009 100644 --- a/src/compas/geometry/translation.py +++ b/src/compas/geometry/translation.py @@ -14,8 +14,8 @@ from compas.geometry import Transformation from compas.geometry import matrix_from_translation from compas.geometry import translation_from_matrix +from compas.itertools import flatten from compas.tolerance import TOL -from compas.utilities import flatten class Translation(Transformation): diff --git a/src/compas/geometry/trimesh_curvature.py b/src/compas/geometry/trimesh_curvature.py index f5b2ed5b3cb..56a79ef3ef9 100644 --- a/src/compas/geometry/trimesh_curvature.py +++ b/src/compas/geometry/trimesh_curvature.py @@ -5,8 +5,8 @@ from math import pi from compas.geometry import angle_points +from compas.itertools import window from compas.plugins import pluggable -from compas.utilities import window @pluggable(category="trimesh") diff --git a/src/compas/itertools.py b/src/compas/itertools.py index 17464c4fb57..756764679b7 100644 --- a/src/compas/itertools.py +++ b/src/compas/itertools.py @@ -123,7 +123,7 @@ def meshgrid(x, y, indexing="xy"): Examples -------- - >>> from compas.utilities import linspace, meshgrid + >>> from compas.itertools import linspace, meshgrid >>> x = list(linspace(0, 1, 3)) >>> y = list(linspace(0, 1, 2)) @@ -181,7 +181,7 @@ def linspace(start, stop, num=50): Examples -------- - >>> from compas.utilities import linspace + >>> from compas.itertools import linspace >>> list(linspace(0, 1, 3)) [0.0, 0.5, 1.0] diff --git a/src/compas_rhino/conduits/faces.py b/src/compas_rhino/conduits/faces.py index 8937a8bfe48..238981a3971 100644 --- a/src/compas_rhino/conduits/faces.py +++ b/src/compas_rhino/conduits/faces.py @@ -5,8 +5,8 @@ from Rhino.Geometry import Point3d from System.Drawing.Color import FromArgb +from compas.itertools import iterable_like from compas.utilities import is_sequence_of_iterable -from compas.utilities import iterable_like from .base import BaseConduit diff --git a/src/compas_rhino/conduits/labels.py b/src/compas_rhino/conduits/labels.py index 2a1b8e74a88..116d2187336 100644 --- a/src/compas_rhino/conduits/labels.py +++ b/src/compas_rhino/conduits/labels.py @@ -5,8 +5,8 @@ from Rhino.Geometry import Point3d from System.Drawing.Color import FromArgb +from compas.itertools import iterable_like from compas.utilities import is_sequence_of_iterable -from compas.utilities import iterable_like from .base import BaseConduit diff --git a/src/compas_rhino/conduits/lines.py b/src/compas_rhino/conduits/lines.py index 7a9917324b0..57aca6f366b 100644 --- a/src/compas_rhino/conduits/lines.py +++ b/src/compas_rhino/conduits/lines.py @@ -5,8 +5,8 @@ from Rhino.Geometry import Point3d from System.Drawing.Color import FromArgb +from compas.itertools import iterable_like from compas.utilities import is_sequence_of_iterable -from compas.utilities import iterable_like from .base import BaseConduit diff --git a/src/compas_rhino/conduits/points.py b/src/compas_rhino/conduits/points.py index 3aa2da97121..383a19266a1 100644 --- a/src/compas_rhino/conduits/points.py +++ b/src/compas_rhino/conduits/points.py @@ -6,8 +6,8 @@ from Rhino.Geometry import Point3d from System.Drawing.Color import FromArgb +from compas.itertools import iterable_like from compas.utilities import color_to_rgb -from compas.utilities import iterable_like from compas.utilities.coercing import is_sequence_of_iterable from .base import BaseConduit diff --git a/src/compas_rhino/geometry/surfaces/nurbs.py b/src/compas_rhino/geometry/surfaces/nurbs.py index 8a144f0cdaa..037263cff99 100644 --- a/src/compas_rhino/geometry/surfaces/nurbs.py +++ b/src/compas_rhino/geometry/surfaces/nurbs.py @@ -9,7 +9,7 @@ from compas.geometry import NurbsSurface from compas.geometry import Point from compas.geometry import knots_and_mults_to_knotvector -from compas.utilities import flatten +from compas.itertools import flatten from compas_rhino.conversions import point_to_compas from compas_rhino.conversions import point_to_rhino diff --git a/tests/compas/utilities/test_itertools.py b/tests/compas/test_itertools.py similarity index 94% rename from tests/compas/utilities/test_itertools.py rename to tests/compas/test_itertools.py index 30f7e422da3..844dac3a2ec 100644 --- a/tests/compas/utilities/test_itertools.py +++ b/tests/compas/test_itertools.py @@ -2,9 +2,9 @@ import pytest from compas.datastructures import Mesh -from compas.utilities import iterable_like -from compas.utilities import reshape -from compas.utilities import flatten +from compas.itertools import iterable_like +from compas.itertools import reshape +from compas.itertools import flatten from compas.tolerance import TOL diff --git a/tests/compas/utilities/test_async_.py b/tests/compas/utilities/test_async_.py deleted file mode 100644 index d4abfebcba4..00000000000 --- a/tests/compas/utilities/test_async_.py +++ /dev/null @@ -1,112 +0,0 @@ -from threading import Thread - -from compas.utilities import await_callback - -import pytest - - -def test_void_return_callback(): - def async_fn(callback): - def runner(cb): - cb() - - Thread(target=runner, args=(callback,)).start() - - result = await_callback(async_fn) - assert result is None - - -def test_single_positional_arg_callback(): - def async_fn(callback): - def runner(cb): - cb("only_return_value") - - Thread(target=runner, args=(callback,)).start() - - result = await_callback(async_fn) - assert result == "only_return_value" - - -def test_many_positional_args_callback(): - def async_fn(callback): - def runner(cb): - cb(1, 2) - - Thread(target=runner, args=(callback,)).start() - - result = await_callback(async_fn) - assert result == ( - 1, - 2, - ) - - -def test_kwargs_callback(): - def async_fn(callback): - def runner(cb): - cb(name="Austin", last_name="Powers") - - Thread(target=runner, args=(callback,)).start() - - result = await_callback(async_fn) - assert result["name"] == "Austin" - assert result["last_name"] == "Powers" - - -def test_one_positional_arg_and_kwargs_callback(): - def async_fn(callback): - def runner(cb): - cb(1, retries=5) - - Thread(target=runner, args=(callback,)).start() - - result, kwargs = await_callback(async_fn) - assert result == 1 - assert kwargs["retries"] == 5 - - -def test_many_positional_args_and_kwargs_callback(): - def async_fn(callback): - def runner(cb): - cb(4, 2, 3, retries=5) - - Thread(target=runner, args=(callback,)).start() - - a, b, c, kw = await_callback(async_fn) - assert a == 4 - assert b == 2 - assert c == 3 - assert kw["retries"] == 5 - - -def test_async_fn_with_more_params(): - def async_fn(values, other_stuff, callback): - def runner(cb): - cb(200) - - Thread(target=runner, args=(callback,)).start() - - result = await_callback(async_fn, values=[1, 2, 3], other_stuff=None) - assert result == 200 - - -def test_captured_exception_in_thread(): - def async_fn(callback): - def runner(cb): - raise ValueError("exception") - - Thread(target=runner, args=(callback,)).start() - - with pytest.raises(ValueError): - await_callback(async_fn) - - -def test_errback(): - def async_fn(callback, errback): - def runner(cb, eb): - eb(ValueError("exception via errback")) - - Thread(target=runner, args=(callback, errback)).start() - - with pytest.raises(ValueError): - await_callback(async_fn, errback_name="errback") diff --git a/tests/compas/utilities/test_itertools_.py b/tests/compas/utilities/test_itertools_.py deleted file mode 100644 index b5026a0d8ac..00000000000 --- a/tests/compas/utilities/test_itertools_.py +++ /dev/null @@ -1,39 +0,0 @@ -import compas -import pytest - -from compas.datastructures import Mesh -from compas.utilities import iterable_like - - -# ============================================================================== -# iterable_like -# ============================================================================== - - -@pytest.mark.parametrize(("target", "base", "fillvalue"), [("hello", [0.5], 0.5)]) -def test_iterable_like_string_and_float(target, base, fillvalue): - a = list(iterable_like(target, base, fillvalue)) - assert a == [0.5, 0.5, 0.5, 0.5, 0.5] - - -@pytest.mark.parametrize( - ("target", "base", "fillvalue"), - [(["foo", "bar", "baz"], {"key_1": "a", "key_2": "b"}, "key_3")], -) -def test_iterable_like_list_and_dict(target, base, fillvalue): - a = list(iterable_like(target, base, fillvalue)) - assert sorted(a) == ["key_1", "key_2", "key_3"] - - -@pytest.mark.parametrize(("target", "base", "fillvalue"), [(range(2), ["a", "b"], 0)]) -def test_iterable_like_generator_and_list(target, base, fillvalue): - a = list(iterable_like(target, base, fillvalue)) - assert a == ["a", "b"] - - -@pytest.mark.parametrize(("mesh_a", "mesh_b"), [("faces.obj", "hypar.obj"), ("hypar.obj", "faces.obj")]) -def test_iterable_cap_generator(mesh_a, mesh_b): - ma = Mesh.from_obj(compas.get(mesh_a)) - mb = Mesh.from_obj(compas.get(mesh_b)) - a = list(iterable_like(ma.faces(), mb.faces())) - assert len(a) == len(list(ma.faces()))