Skip to content

Commit

Permalink
ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed May 13, 2024
1 parent 4043c77 commit fd0f076
Show file tree
Hide file tree
Showing 60 changed files with 320 additions and 303 deletions.
2 changes: 1 addition & 1 deletion src/compas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def get(filename):
import compas
from compas.datastructures import Mesh
mesh = Mesh.from_obj(compas.get('faces.obj'))
mesh = Mesh.from_obj(compas.get("faces.obj"))
"""
filename = filename.strip("/")
Expand Down
1 change: 1 addition & 0 deletions src/compas/_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
These are internal functions of the framework.
Not intended to be used outside compas* packages.
"""

import os
import platform
import re
Expand Down
6 changes: 2 additions & 4 deletions src/compas/colors/colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ class ColorMap(object):
Examples
--------
>>> import random
>>> cmap = ColorMap.from_palette('bamako')
>>> cmap = ColorMap.from_palette("bamako")
>>> for i in range(100):
... color = cmap(random.random())
...
>>> cmap = ColorMap.from_mpl('viridis')
>>> cmap = ColorMap.from_mpl("viridis")
>>> n = 100
>>> for i in range(n):
... color = cmap(i, minval=0, maxval=n - 1)
...
See Also
--------
Expand Down
4 changes: 2 additions & 2 deletions src/compas/data/coercion.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def coerce_sequence_of_tuple(sequence):
Examples
--------
>>> items = coerce_sequence_of_tuple(['a', 1, (None, ), [2.0, 3.0]])
>>> items = coerce_sequence_of_tuple(["a", 1, (None,), [2.0, 3.0]])
>>> is_sequence_of_tuple(items)
True
Expand Down Expand Up @@ -55,7 +55,7 @@ def coerce_sequence_of_list(sequence):
Examples
--------
>>> items = coerce_sequence_of_list(['a', 1, (None, ), [2.0, 3.0]])
>>> items = coerce_sequence_of_list(["a", 1, (None,), [2.0, 3.0]])
>>> is_sequence_of_list(items)
True
Expand Down
4 changes: 2 additions & 2 deletions src/compas/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,10 @@ def sha256(self, as_string=False):
Examples
--------
>>> from compas.datastructures import Mesh
>>> mesh = Mesh.from_obj(compas.get('faces.obj'))
>>> mesh = Mesh.from_obj(compas.get("faces.obj"))
>>> v1 = mesh.sha256()
>>> v2 = mesh.sha256()
>>> mesh.vertex_attribute(mesh.vertex_sample(1)[0], 'z', 1)
>>> mesh.vertex_attribute(mesh.vertex_sample(1)[0], "z", 1)
>>> v3 = mesh.sha256()
>>> v1 == v2
True
Expand Down
10 changes: 4 additions & 6 deletions src/compas/data/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,15 @@ class DataEncoder(json.JSONEncoder):
>>> from compas.data import DataEncoder
>>> from compas.geometry import Point
>>> point = Point(0, 0, 0)
>>> with open('point.json', 'w') as f:
>>> with open("point.json", "w") as f:
... json.dump(point, f, cls=DataEncoder)
...
Implicit use case.
>>> from compas.data import json_dump
>>> from compas.geometry import Point
>>> point = Point(0, 0, 0)
>>> json_dump(point, 'point.json')
>>> json_dump(point, "point.json")
"""

Expand Down Expand Up @@ -182,14 +181,13 @@ class DataDecoder(json.JSONDecoder):
>>> import json
>>> from compas.data import DataDecoder
>>> with open('point.json', 'r') as f:
>>> with open("point.json", "r") as f:
... point = json.load(f, cls=DataDecoder)
...
Implicit use case.
>>> from compas.data import json_load
>>> point = json_load('point.json')
>>> point = json_load("point.json")
"""

Expand Down
8 changes: 4 additions & 4 deletions src/compas/data/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def json_dump(data, fp, pretty=False, compact=False, minimal=False):
>>> import compas
>>> from compas.geometry import Point, Vector
>>> data1 = [Point(0, 0, 0), Vector(0, 0, 0)]
>>> compas.json_dump(data1, 'data.json')
>>> data2 = compas.json_load('data.json')
>>> compas.json_dump(data1, "data.json")
>>> data2 = compas.json_load("data.json")
>>> data1 == data2
True
Expand Down Expand Up @@ -197,8 +197,8 @@ def json_load(fp): # type: (...) -> dict
>>> import compas
>>> from compas.geometry import Point, Vector
>>> data1 = [Point(0, 0, 0), Vector(0, 0, 0)]
>>> compas.json_dump(data1, 'data.json')
>>> data2 = compas.json_load('data.json')
>>> compas.json_dump(data1, "data.json")
>>> data2 = compas.json_load("data.json")
>>> data1 == data2
True
Expand Down
8 changes: 4 additions & 4 deletions src/compas/data/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def is_sequence_of_tuple(items):
Examples
--------
>>> is_sequence_of_tuple([(1, ), (1, ), (1, )])
>>> is_sequence_of_tuple([(1,), (1,), (1,)])
True
"""
Expand All @@ -184,7 +184,7 @@ def is_sequence_of_dict(items):
Examples
--------
>>> is_sequence_of_dict([{'a': 1}, {'b': 2}, {'c': 3}])
>>> is_sequence_of_dict([{"a": 1}, {"b": 2}, {"c": 3}])
True
"""
Expand All @@ -209,7 +209,7 @@ def is_item_iterable(item):
--------
>>> is_item_iterable(1.0)
False
>>> is_item_iterable('abc')
>>> is_item_iterable("abc")
True
"""
Expand All @@ -236,7 +236,7 @@ def is_sequence_of_iterable(items):
Examples
--------
>>> is_sequence_of_iterable(['abc', [1.0], (2, 'a', None)])
>>> is_sequence_of_iterable(["abc", [1.0], (2, "a", None)])
True
"""
Expand Down
4 changes: 2 additions & 2 deletions src/compas/datastructures/assembly/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class GeometricFeature(Feature):
Examples
--------
>>> def trim_brep_plane(brep, plane):
>>> # trim brep with plane, return trimmed brep
>>> # trim brep with plane, return trimmed brep
>>>
>>> def trim_mesh_plane(mesh, plane):
>>> # trim mesh with plane, return trimmed mesh
>>> # trim mesh with plane, return trimmed mesh
>>>
>>> class TrimmingFeature(GeometricFeature):
>>> OPERATIONS = {Brep: trim_brep_plane, Mesh: trim_mesh_plane}
Expand Down
2 changes: 1 addition & 1 deletion src/compas/datastructures/cell_network/cell_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CellNetwork(Datastructure):
>>> from compas.datastructures import CellNetwork
>>> cell_network = CellNetwork()
>>> vertices = [(0, 0, 0), (0, 1, 0), (1, 1, 0), (1, 0, 0), (0, 0, 1), (1, 0, 1), (1, 1, 1), (0, 1, 1)]
>>> faces = [[0, 1, 2, 3], [0, 3, 5, 4],[3, 2, 6, 5], [2, 1, 7, 6],[1, 0, 4, 7],[4, 5, 6, 7]]
>>> faces = [[0, 1, 2, 3], [0, 3, 5, 4], [3, 2, 6, 5], [2, 1, 7, 6], [1, 0, 4, 7], [4, 5, 6, 7]]
>>> cells = [[0, 1, 2, 3, 4, 5]]
>>> [network.add_vertex(x=x, y=y, z=z) for x, y, z in vertices]
>>> [cell_network.add_face(fverts) for fverts in faces]
Expand Down
4 changes: 2 additions & 2 deletions src/compas/datastructures/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ def is_connected(self):
--------
>>> import compas
>>> from compas.datastructures import Graph
>>> graph = Graph.from_obj(compas.get('lines.obj'))
>>> graph = Graph.from_obj(compas.get("lines.obj"))
>>> graph.is_connected()
True
Expand Down Expand Up @@ -2364,7 +2364,7 @@ def complement(self):
--------
>>> import compas
>>> from compas.datastructures import Graph
>>> graph = Graph.from_obj(compas.get('lines.obj'))
>>> graph = Graph.from_obj(compas.get("lines.obj"))
>>> complement = graph.complement()
>>> any(complement.has_edge(u, v, directed=False) for u, v in graph.edges())
False
Expand Down
12 changes: 6 additions & 6 deletions src/compas/datastructures/graph/operations/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def graph_polylines(graph, splits=None):
This will result in the following polylines (a, b, c), (c, d) and (c, e, f).
>>> from compas.datastructures import Graph
>>> a = [0., 0., 0.]
>>> b = [1., 0., 0.]
>>> c = [2., 0., 0.]
>>> d = [2., 1., 0.]
>>> e = [3., 0., 0.]
>>> f = [4., 0., 0.]
>>> a = [0.0, 0.0, 0.0]
>>> b = [1.0, 0.0, 0.0]
>>> c = [2.0, 0.0, 0.0]
>>> d = [2.0, 1.0, 0.0]
>>> e = [3.0, 0.0, 0.0]
>>> f = [4.0, 0.0, 0.0]
>>> lines = [(a, b), (b, c), (c, d), (c, e), (e, f)]
>>> graph = Graph.from_lines(lines)
>>> len(graph_polylines(graph)) == 3
Expand Down
4 changes: 2 additions & 2 deletions src/compas/datastructures/mesh/duality.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def mesh_dual(mesh, cls=None, include_boundary=False):
--------
>>> import compas
>>> from compas.datastructures import Mesh
>>> mesh = Mesh.from_obj(compas.get('faces.obj'))
>>> mesh = Mesh.from_obj(compas.get("faces.obj"))
>>> mesh.delete_face(11)
>>> mesh.delete_face(6)
>>> mesh.delete_face(7)
>>> mesh.quads_to_triangles()
>>> mesh = mesh.subdivide('corner')
>>> mesh = mesh.subdivide("corner")
>>> dual = mesh.dual(include_boundary=True)
"""
Expand Down
5 changes: 2 additions & 3 deletions src/compas/datastructures/mesh/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2849,12 +2849,11 @@ def remove_duplicate_vertices(self, precision=None):
--------
>>> import compas
>>> from compas.datastructures import Mesh
>>> mesh = Mesh.from_obj(compas.get('faces.obj'))
>>> mesh = Mesh.from_obj(compas.get("faces.obj"))
>>> mesh.number_of_vertices()
36
>>> for x, y, z in mesh.vertices_attributes('xyz', keys=list(mesh.vertices())[:5]):
>>> for x, y, z in mesh.vertices_attributes("xyz", keys=list(mesh.vertices())[:5]):
... mesh.add_vertex(x=x, y=y, z=z)
...
38
39
40
Expand Down
2 changes: 1 addition & 1 deletion src/compas/datastructures/mesh/operations/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def mesh_merge_faces(mesh, faces):
--------
>>> from compas.datastructures import Mesh
>>> mesh = Mesh.from_vertices_and_faces([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], [[0, 1, 2, 3]])
>>> mesh = mesh.subdivide(scheme='quad')
>>> mesh = mesh.subdivide(scheme="quad")
>>> mesh_merge_faces(mesh, [1, 2])
5
>>> mesh_merge_faces(mesh, [3, 5])
Expand Down
8 changes: 4 additions & 4 deletions src/compas/datastructures/mesh/subdivision.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def mesh_subdivide_quad(mesh, k=1):
False
>>> type(mesh) is type(subd)
True
>>> subd.number_of_faces() == mesh.number_of_faces() * 4 ** k
>>> subd.number_of_faces() == mesh.number_of_faces() * 4**k
True
"""
Expand Down Expand Up @@ -293,7 +293,7 @@ def mesh_subdivide_catmullclark(mesh, k=1, fixed=None):
False
>>> type(mesh) is type(subd)
True
>>> subd.number_of_faces() == mesh.number_of_faces() * 4 ** k
>>> subd.number_of_faces() == mesh.number_of_faces() * 4**k
True
The algorithm supports "integer creasing" as described in
Expand All @@ -309,9 +309,9 @@ def mesh_subdivide_catmullclark(mesh, k=1, fixed=None):
>>> from compas.datastructures import Mesh
>>> cage = Mesh.from_shape(Box.from_width_height_depth(1, 1, 1))
>>> cage.update_default_edge_attributes({'crease': 0})
>>> cage.update_default_edge_attributes({"crease": 0})
>>> top = sorted(cage.faces(), key=lambda face: dot_vectors(cage.face_normal(face), [0, 0, 1]))[-1]
>>> cage.edges_attribute('crease', 5, keys=list(cage.face_halfedges(top)))
>>> cage.edges_attribute("crease", 5, keys=list(cage.face_halfedges(top)))
>>> subd = cage.subdivide(k=4)
Expand Down
10 changes: 4 additions & 6 deletions src/compas/datastructures/tree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def __data__(self):

@classmethod
def __from_data__(cls, data):

name = data.get("name", None)
attributes = data.get("attributes", {})
children = data.get("children", [])
Expand Down Expand Up @@ -235,10 +234,10 @@ class Tree(Datastructure):
--------
>>> from compas.datastructures import Tree, TreeNode
>>> tree = Tree()
>>> root = TreeNode('root')
>>> branch = TreeNode('branch')
>>> leaf1 = TreeNode('leaf1')
>>> leaf2 = TreeNode('leaf2')
>>> root = TreeNode("root")
>>> branch = TreeNode("branch")
>>> leaf1 = TreeNode("leaf1")
>>> leaf2 = TreeNode("leaf2")
>>> tree.add(root)
>>> root.add(branch)
>>> branch.add(leaf1)
Expand Down Expand Up @@ -457,7 +456,6 @@ def get_hierarchy_string(self, max_depth=None):
hierarchy = []

def traverse(node, hierarchy, prefix="", last=True, depth=0):

if max_depth is not None and depth > max_depth:
return

Expand Down
12 changes: 5 additions & 7 deletions src/compas/files/obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ class OBJ(object):
Write mesh data to a file.
>>> mesh = Mesh.from_polyhedron(12)
>>> obj = OBJ('mesh.obj')
>>> obj = OBJ("mesh.obj")
>>> obj.write(mesh)
Read mesh data from a file.
>>> obj = OBJ('mesh.obj')
>>> obj = OBJ("mesh.obj")
>>> obj.read()
>>> mesh = Mesh.from_vertices_and_faces(obj.vertices, obj.faces)
Expand All @@ -74,20 +74,18 @@ class OBJ(object):
... mesh = Mesh.from_polyhedron(12)
... mesh.transform(Translation.from_vector(point))
... meshes.append(mesh)
...
>>> obj = OBJ('meshes.obj')
>>> obj = OBJ("meshes.obj")
>>> obj.write(meshes)
Read mesh data from a file.
>>> obj = OBJ('meshes.obj')
>>> obj = OBJ("meshes.obj")
>>> obj.read()
>>> meshes = []
>>> for name in obj.objects:
... mesh = Mesh.from_vertices_and_faces(* obj.objects[name])
... mesh = Mesh.from_vertices_and_faces(*obj.objects[name])
... mesh.name = name
... meshes.append(mesh)
...
"""

Expand Down
16 changes: 8 additions & 8 deletions src/compas/geometry/_core/_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -2681,10 +2681,10 @@ def quaternion_from_axis_angle(axis, angle):
Examples
--------
>>> axis = [1.0, 0.0, 0.0]
>>> angle = math.pi/2
>>> axis = [1.0, 0.0, 0.0]
>>> angle = math.pi / 2
>>> q = quaternion_from_axis_angle(axis, angle)
>>> allclose(q, [math.sqrt(2)/2, math.sqrt(2)/2, 0, 0])
>>> allclose(q, [math.sqrt(2) / 2, math.sqrt(2) / 2, 0, 0])
True
"""
Expand All @@ -2710,11 +2710,11 @@ def axis_angle_from_quaternion(q):
Examples
--------
>>> q = [1., 1., 0., 0.]
>>> q = [1.0, 1.0, 0.0, 0.0]
>>> axis, angle = axis_angle_from_quaternion(q)
>>> allclose(axis, [1., 0., 0.])
>>> allclose(axis, [1.0, 0.0, 0.0])
True
>>> allclose([angle], [math.pi/2], 1e-6)
>>> allclose([angle], [math.pi / 2], 1e-6)
True
"""
Expand Down Expand Up @@ -2769,9 +2769,9 @@ def close(value1, value2, tol=1e-05):
Examples
--------
>>> close(1., 1.001)
>>> close(1.0, 1.001)
False
>>> close(1., 1.001, tol=1e-2)
>>> close(1.0, 1.001, tol=1e-2)
True
"""
return TOL.is_close(value1, value2, rtol=0.0, atol=tol)
Expand Down
Loading

0 comments on commit fd0f076

Please sign in to comment.