Skip to content

Commit a6ad0ae

Browse files
authored
Enable ruff linting (#464)
* ruff --fix . * add previous commit to git-blame-ignore-revs * manual ruff fixes * pre-commit sort * pre-commit: add ruff * black . * ignore pre-commit in blame * README: add black & ruff badges * fix noqa * gitlab-ci: fix url
1 parent df34a33 commit a6ad0ae

18 files changed

+117
-93
lines changed

.git-blame-ignore-revs

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
0067c8aa66aac548601e2a3fd029aa264cc59f2a
22
76b68f785df31b00e153290b45ec290a9c5f7963
3+
# ruff --fix . (Guilhem Saurel, 2023-10-24)
4+
58dee5ae90eded5125825a2da0fe76a5031f3334
5+
# black . (Guilhem Saurel, 2023-10-24)
6+
889ff8d1ca00b9e317e1da4136e233bb49a049df

.gitlab-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: http://rainboard.laas.fr/project/hpp-fcl/.gitlab-ci.yml
1+
include: https://rainboard.laas.fr/project/hpp-fcl/.gitlab-ci.yml

.pre-commit-config.yaml

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
ci:
2-
autoupdate_branch: 'devel'
2+
autoupdate_branch: devel
33
repos:
4-
- repo: https://github.com/pre-commit/mirrors-clang-format
5-
rev: v17.0.3
6-
hooks:
7-
- id: clang-format
8-
args: ['--style={BasedOnStyle: Google, SortIncludes: false}']
9-
- repo: https://github.com/pre-commit/pre-commit-hooks
10-
rev: v4.5.0
11-
hooks:
12-
- id: trailing-whitespace
13-
- repo: https://github.com/psf/black
14-
rev: 23.10.0
15-
hooks:
16-
- id: black
4+
- repo: https://github.com/charliermarsh/ruff-pre-commit
5+
rev: v0.0.267
6+
hooks:
7+
- id: ruff
8+
args:
9+
- --fix
10+
- --exit-non-zero-on-fix
11+
- repo: https://github.com/pre-commit/mirrors-clang-format
12+
rev: v17.0.3
13+
hooks:
14+
- id: clang-format
15+
args:
16+
- '--style={BasedOnStyle: Google, SortIncludes: false}'
17+
- repo: https://github.com/pre-commit/pre-commit-hooks
18+
rev: v4.5.0
19+
hooks:
20+
- id: trailing-whitespace
21+
- repo: https://github.com/psf/black
22+
rev: 23.10.0
23+
hooks:
24+
- id: black

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
HPP-FCL — An extension of the Flexible Collision Library
2-
=======
1+
# HPP-FCL — An extension of the Flexible Collision Library
32

43
<p align="center">
54
<a href="https://gepgitlab.laas.fr/humanoid-path-planner/hpp-fcl/commits/master/"><img src="https://gepgitlab.laas.fr/humanoid-path-planner/hpp-fcl/badges/master/pipeline.svg" alt="Pipeline status"/></a>
@@ -8,6 +7,8 @@ HPP-FCL — An extension of the Flexible Collision Library
87
<a href="https://anaconda.org/conda-forge/hpp-fcl"><img src="https://img.shields.io/conda/dn/conda-forge/hpp-fcl.svg" alt="Conda Downloads"/></a>
98
<a href="https://anaconda.org/conda-forge/hpp-fcl"><img src="https://img.shields.io/conda/vn/conda-forge/hpp-fcl.svg" alt="Conda Version"/></a>
109
<a href="https://badge.fury.io/py/hpp-fcl"><img src="https://badge.fury.io/py/hpp-fcl.svg" alt="PyPI version"></a>
10+
<a href="https://github.com/psf/black"><img alt="black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
11+
<a href="https://github.com/astral-sh/ruff"><img alt="ruff" src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json"></a>
1112
</p>
1213

1314
[FCL](https://github.com/flexible-collision-library/fcl) was forked in 2015. Since then, a large part of the code has been rewritten or removed (for the unused and untested part).
@@ -37,4 +38,3 @@ Unlike the original FCL library, HPP-FCL implements the well-established GJK alg
3738
## Acknowledgments
3839

3940
The development of **HPP-FCL** is actively supported by the [Gepetto team](http://projects.laas.fr/gepetto/) [@LAAS-CNRS](http://www.laas.fr), the [Willow team](https://www.di.ens.fr/willow/) [@INRIA](http://www.inria.fr) and, to some extend, [Eureka Robotics](https://eurekarobotics.com/).
40-

doc/generate_distance_plot.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
3-
from math import sqrt
43

54
interactive = False
65

doc/gjk.py

+29-29
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
edge_fmt = "{j}a * {b}a_{c}a + {j}{b} * {c}a_aa - {j}{c} * {b}a_aa"
1111

1212
# These checks must be negative and not positive, as in the cheat sheet.
13-
# They are the same as in the cheat sheet, except that we consider (...).dot(A) instead of (...).dot(-A)
13+
# They are the same as in the cheat sheet, except that we consider (...).dot(A)
14+
# instead of (...).dot(-A)
1415
plane_tests = ["C.dot (a_cross_b)", "D.dot(a_cross_c)", "-D.dot(a_cross_b)"]
1516
checks = (
1617
plane_tests
@@ -247,9 +248,9 @@
247248
def set_test_values(current_tests, test_values, itest, value):
248249
def satisfies(values, indices):
249250
for k in indices:
250-
if k > 0 and values[k - 1] != True:
251+
if k > 0 and values[k - 1] is not True:
251252
return False
252-
if k < 0 and values[-k - 1] != False:
253+
if k < 0 and values[-k - 1] is not False:
253254
return False
254255
return True
255256

@@ -286,17 +287,17 @@ def set_tests_values(current_tests, test_values, itests, values):
286287
def apply_test_values(cases, test_values):
287288
def canSatisfy(values, indices):
288289
for k in indices:
289-
if k > 0 and values[k - 1] == False:
290+
if k > 0 and values[k - 1] is False:
290291
return False
291-
if k < 0 and values[-k - 1] == True:
292+
if k < 0 and values[-k - 1] is True:
292293
return False
293294
return True
294295

295296
def satisfies(values, indices):
296297
for k in indices:
297-
if k > 0 and values[k - 1] != True:
298+
if k > 0 and values[k - 1] is not True:
298299
return False
299-
if k < 0 and values[-k - 1] != False:
300+
if k < 0 and values[-k - 1] is not False:
300301
return False
301302
return True
302303

@@ -337,7 +338,7 @@ def max_number_of_tests(
337338
prevScore=0,
338339
):
339340
for test in current_tests:
340-
assert test_values[test] == None, "Test " + str(test) + " already performed"
341+
assert test_values[test] is None, "Test " + str(test) + " already performed"
341342

342343
left_cases = apply_test_values(cases, test_values)
343344

@@ -375,7 +376,8 @@ def max_number_of_tests(
375376
remaining_tests = None
376377

377378
if remaining_tests is not None:
378-
# Do not put this in try catch as I do not want other ValueError to be understood as an infeasible branch.
379+
# Do not put this in try catch as I do not want other ValueError to be
380+
# understood as an infeasible branch.
379381
score_if_t, order_if_t = max_number_of_tests(
380382
remaining_tests,
381383
left_cases,
@@ -396,7 +398,8 @@ def max_number_of_tests(
396398
remaining_tests = None
397399

398400
if remaining_tests is not None:
399-
# Do not put this in try catch as I do not want other ValueError to be understood as an infeasible branch.
401+
# Do not put this in try catch as I do not want other ValueError to be
402+
# understood as an infeasible branch.
400403
score_if_f, order_if_f = max_number_of_tests(
401404
remaining_tests,
402405
left_cases,
@@ -438,37 +441,37 @@ def printOrder(order, indent="", start=True, file=sys.stdout, curTests=[]):
438441
file=file,
439442
)
440443
print(indent + "const vertex_id_t a = 3, b = 2, c = 1, d = 0;", file=file)
441-
for l in "abcd":
444+
for v in "abcd":
442445
print(
443446
indent
444-
+ "const Vec3f& {} (current.vertex[{}]->w);".format(l.upper(), l),
447+
+ "const Vec3f& {} (current.vertex[{}]->w);".format(v.upper(), v),
445448
file=file,
446449
)
447-
print(indent + "const FCL_REAL aa = A.squaredNorm();".format(l), file=file)
448-
for l in "dcb":
450+
print(indent + "const FCL_REAL aa = A.squaredNorm();".format(), file=file)
451+
for v in "dcb":
449452
for m in "abcd":
450-
if m <= l:
453+
if m <= v:
451454
print(
452455
indent
453456
+ "const FCL_REAL {0}{1} = {2}.dot({3});".format(
454-
l, m, l.upper(), m.upper()
457+
v, m, v.upper(), m.upper()
455458
),
456459
file=file,
457460
)
458461
else:
459462
print(
460-
indent + "const FCL_REAL& {0}{1} = {1}{0};".format(l, m),
463+
indent + "const FCL_REAL& {0}{1} = {1}{0};".format(v, m),
461464
file=file,
462465
)
463-
print(indent + "const FCL_REAL {0}a_aa = {0}a - aa;".format(l), file=file)
466+
print(indent + "const FCL_REAL {0}a_aa = {0}a - aa;".format(v), file=file)
464467
for l0, l1 in zip("bcd", "cdb"):
465468
print(
466469
indent + "const FCL_REAL {0}a_{1}a = {0}a - {1}a;".format(l0, l1),
467470
file=file,
468471
)
469-
for l in "bc":
472+
for v in "bc":
470473
print(
471-
indent + "const Vec3f a_cross_{0} = A.cross({1});".format(l, l.upper()),
474+
indent + "const Vec3f a_cross_{0} = A.cross({1});".format(v, v.upper()),
472475
file=file,
473476
)
474477
print("", file=file)
@@ -502,15 +505,12 @@ def printOrder(order, indent="", start=True, file=sys.stdout, curTests=[]):
502505
elif region == "A":
503506
print(indent + "originToPoint (current, a, A, next, ray);", file=file)
504507
elif len(region) == 2:
505-
a = region[0]
508+
region[0]
506509
B = region[1]
507510
print(
508-
indent
509-
+ "originToSegment (current, a, {b}, A, {B}, {B}-A, -{b}a_aa, next, ray);".format(
510-
**{
511-
"b": B.lower(),
512-
"B": B,
513-
}
511+
indent + "originToSegment "
512+
"(current, a, {b}, A, {B}, {B}-A, -{b}a_aa, next, ray);".format(
513+
**{"b": B.lower(), "B": B}
514514
),
515515
file=file,
516516
)
@@ -524,8 +524,8 @@ def printOrder(order, indent="", start=True, file=sys.stdout, curTests=[]):
524524
else:
525525
test = "-" + test
526526
print(
527-
indent
528-
+ "originToTriangle (current, a, {b}, {c}, ({B}-A).cross({C}-A), {t}, next, ray);".format(
527+
indent + "originToTriangle "
528+
"(current, a, {b}, {c}, ({B}-A).cross({C}-A), {t}, next, ray);".format(
529529
**{"b": B.lower(), "c": C.lower(), "B": B, "C": C, "t": test}
530530
),
531531
file=file,

doc/python/doxygen_xml_parser.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/python3
2+
# ruff: noqa: E501
23

34
from __future__ import print_function
45
from lxml import etree
@@ -120,8 +121,6 @@ def _templateParamToDict(param):
120121

121122

122123
def makeHeaderGuard(filename):
123-
import os
124-
125124
return filename.upper().replace(".", "_").replace("/", "_").replace("-", "_")
126125

127126

@@ -326,8 +325,6 @@ def getdeclname(i, declname):
326325
return ", ".join([arg.format(n) for n in argnames])
327326

328327
def include(self):
329-
import os.path
330-
331328
loc = self.xml.find("location")
332329
# The location is based on $CMAKE_SOURCE_DIR. Remove first directory.
333330
return loc.attrib["file"].split("/", 1)[1]
@@ -705,8 +702,6 @@ def parseCompound(self):
705702

706703
def write(self):
707704
# Header
708-
from os.path import abspath, dirname
709-
from time import asctime
710705

711706
self.output.open("doxygen_xml_parser_for_cmake.hh")
712707
# self.output.out ("// Generated on {}".format (asctime()))
@@ -821,7 +816,7 @@ def __init__(self, output_dir, warn, error, errorPrefix=""):
821816
self._created_files = dict()
822817

823818
def open(self, name):
824-
assert self._out == None, "You did not close the previous file"
819+
assert self._out is None, "You did not close the previous file"
825820
import os
826821

827822
fullname = os.path.join(self.output_dir, name)
@@ -895,4 +890,4 @@ def err(self, *args):
895890
index.parseCompound()
896891
index.write()
897892
index.output.writeFooterAndCloseFiles()
898-
assert index.output._out == None
893+
assert index.output._out is None

doc/python/xml_docstring.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ def _newline(self, n=1):
5959

6060
def _clean(self):
6161
s = 0
62-
for l in self.lines:
63-
if len(l.strip()) == 0:
62+
for line in self.lines:
63+
if len(line.strip()) == 0:
6464
s += 1
6565
else:
6666
break
6767
e = len(self.lines)
68-
for l in reversed(self.lines):
69-
if len(l.strip()) == 0:
68+
for line in reversed(self.lines):
69+
if len(line.strip()) == 0:
7070
e -= 1
7171
else:
7272
break
@@ -80,7 +80,7 @@ def getDocString(self, brief, detailled, output):
8080
if brief is not None:
8181
self._newline()
8282
self.visit(detailled)
83-
from sys import stdout, stderr, version_info
83+
from sys import version_info
8484

8585
self.writeErrors(output)
8686
self._clean()

python/hppfcl/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3232
# POSSIBILITY OF SUCH DAMAGE.
3333

34+
# ruff: noqa: F401, F403
3435
from .hppfcl import *
35-
from .hppfcl import __version__, __raw_version__
36+
from .hppfcl import __raw_version__, __version__

python/hppfcl/viewer.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
# Copyright (c) 2019 CNRS
44
# Author: Joseph Mirabel
55

6-
import hppfcl, numpy as np
6+
import warnings
7+
8+
import numpy as np
79
from gepetto import Color
810

11+
import hppfcl
12+
913

1014
def applyConfiguration(gui, name, tf):
1115
gui.applyConfiguration(
@@ -43,10 +47,7 @@ def displayShape(gui, name, geom, color=(0.9, 0.9, 0.9, 1.0)):
4347
gui.setLightingMode(name, "OFF")
4448
return True
4549
else:
46-
msg = "Unsupported geometry type for %s (%s)" % (
47-
geometry_object.name,
48-
type(geom),
49-
)
50+
msg = "Unsupported geometry type for %s (%s)" % (name, type(geom))
5051
warnings.warn(msg, category=UserWarning, stacklevel=2)
5152
return False
5253

test/python_unit/geometric_shapes.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ def test_convex(self):
167167
]
168168
)
169169
faces.append(hppfcl.Triangle(0, 1, 2))
170-
convex = hppfcl.Convex(verts, faces)
170+
hppfcl.Convex(verts, faces)
171171

172172
verts.append(np.array([0, 0, 1]))
173173
try:
174-
convexHull = hppfcl.Convex.convexHull(verts, False, None)
174+
hppfcl.Convex.convexHull(verts, False, None)
175175
qhullAvailable = True
176176
except Exception as e:
177177
self.assertEqual(
@@ -180,11 +180,11 @@ def test_convex(self):
180180
qhullAvailable = False
181181

182182
if qhullAvailable:
183-
convexHull = hppfcl.Convex.convexHull(verts, False, "")
184-
convexHull = hppfcl.Convex.convexHull(verts, True, "")
183+
hppfcl.Convex.convexHull(verts, False, "")
184+
hppfcl.Convex.convexHull(verts, True, "")
185185

186186
try:
187-
convexHull = hppfcl.Convex.convexHull(verts[:3], False, None)
187+
hppfcl.Convex.convexHull(verts[:3], False, None)
188188
except Exception as e:
189189
self.assertIn(
190190
str(e), "You shouldn't use this function with less than 4 points."

test/scripts/collision-bench.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import csv
2+
import sys
3+
14
import matplotlib.pyplot as plt
2-
import csv, sys, numpy as np
3-
from math import sqrt
45

56
filename = sys.argv[1]
67

@@ -43,8 +44,8 @@
4344
idx_reorder = sorted(list(range(len(xvals))), key=lambda i: xvals[i])
4445

4546

46-
def reorder(l):
47-
return [l[i] for i in idx_reorder]
47+
def reorder(v):
48+
return [v[i] for i in idx_reorder]
4849

4950

5051
xvals_s = reorder(xvals)

test/scripts/collision.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Load "env.obj" and "rob.obj" in gepetto-gui
22

3-
import numpy as np
43
import os
54
from gepetto.corbaserver import Client
65

0 commit comments

Comments
 (0)