From c1434c9e7442493b8cb2a764dff980015deaa239 Mon Sep 17 00:00:00 2001 From: Wolfgang Merkt <wxmerkt@users.noreply.github.com> Date: Thu, 8 Sep 2022 16:02:45 +0100 Subject: [PATCH] Fix flake8 errors (#318) * Fix flake8 errors * flake8: ignore E203 * flake8: 119 cols for now * black * fix comment style * exclude cmake.py * clang-format: sort include Co-authored-by: Guilhem Saurel <guilhem.saurel@laas.fr> --- .pre-commit-config.yaml | 2 +- README.md | 1 + benchmarks/bench-switch.py | 4 ++-- python/eigenpy/__init__.py | 4 ++-- setup.cfg | 4 ++++ unittest/eigen_ref.cpp | 1 + unittest/python/test_LLT.py | 1 - unittest/python/test_complex.py | 2 +- unittest/python/test_dimensions.py | 1 - unittest/python/test_eigen_ref.py | 11 ++++++++++- unittest/python/test_geometry.py | 11 +++++++++-- unittest/python/test_return_by_ref.py | 4 ++-- unittest/python/test_self_adjoint_eigen_solver.py | 5 ++--- unittest/python/test_user_type.py | 15 ++++++++------- 14 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 setup.cfg diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c6e61f23..ac4119bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: rev: v14.0.6 hooks: - id: clang-format - args: ['--style={BasedOnStyle: Google, SortIncludes: false}'] + args: [--style=Google] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.3.0 hooks: diff --git a/README.md b/README.md index 16116bfa..96eca478 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ EigenPy — Efficient Python bindings between Numpy/Eigen <a href="https://anaconda.org/conda-forge/eigenpy"><img src="https://img.shields.io/conda/dn/conda-forge/eigenpy.svg" alt="Conda Downloads"/></a> <a href="https://anaconda.org/conda-forge/eigenpy"><img src="https://img.shields.io/conda/vn/conda-forge/eigenpy.svg" alt="Conda Version"/></a> <a href="https://badge.fury.io/py/eigenpy"><img src="https://badge.fury.io/py/eigenpy.svg" alt="PyPI version"></a> + <a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black"></a> </p> **EigenPy** is an open source framework which allows to bind the famous [Eigen](http://eigen.tuxfamily.org) C++ library in Python. diff --git a/benchmarks/bench-switch.py b/benchmarks/bench-switch.py index 289a95c6..19e1ec75 100644 --- a/benchmarks/bench-switch.py +++ b/benchmarks/bench-switch.py @@ -3,8 +3,8 @@ from __future__ import print_function import eigenpy import numpy as np -import time -import timeit +import time # noqa +import timeit # noqa from IPython import get_ipython diff --git a/python/eigenpy/__init__.py b/python/eigenpy/__init__.py index 328c005e..f68cfdb8 100644 --- a/python/eigenpy/__init__.py +++ b/python/eigenpy/__init__.py @@ -2,5 +2,5 @@ # Copyright (c) 2017-2021 CNRS INRIA # -from .eigenpy_pywrap import * -from .eigenpy_pywrap import __version__, __raw_version__ +from .eigenpy_pywrap import * # noqa +from .eigenpy_pywrap import __version__, __raw_version__ # noqa diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..ea6e1878 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[flake8] +extend-ignore = E203 +max-line-length = 88 +exclude = cmake/.docs/cmake.py diff --git a/unittest/eigen_ref.cpp b/unittest/eigen_ref.cpp index 17bafe8b..78896b9a 100644 --- a/unittest/eigen_ref.cpp +++ b/unittest/eigen_ref.cpp @@ -6,6 +6,7 @@ #include <iostream> #include "eigenpy/eigenpy.hpp" +// include main header first #include "eigenpy/eigen-from-python.hpp" using namespace Eigen; diff --git a/unittest/python/test_LLT.py b/unittest/python/test_LLT.py index 21cf2752..63f94447 100644 --- a/unittest/python/test_LLT.py +++ b/unittest/python/test_LLT.py @@ -1,7 +1,6 @@ import eigenpy import numpy as np -import numpy.linalg as la dim = 100 A = np.random.rand(dim, dim) diff --git a/unittest/python/test_complex.py b/unittest/python/test_complex.py index 0f1eba2e..cbe8032b 100644 --- a/unittest/python/test_complex.py +++ b/unittest/python/test_complex.py @@ -1,7 +1,7 @@ from __future__ import print_function import numpy as np -from complex import * +from complex import switchToNumpyArray, real, imag, ascomplex switchToNumpyArray() diff --git a/unittest/python/test_dimensions.py b/unittest/python/test_dimensions.py index 83b40383..97312dcc 100644 --- a/unittest/python/test_dimensions.py +++ b/unittest/python/test_dimensions.py @@ -1,7 +1,6 @@ from __future__ import print_function import eigenpy -import numpy as np quat = eigenpy.Quaternion() # By default, we convert as numpy.matrix diff --git a/unittest/python/test_eigen_ref.py b/unittest/python/test_eigen_ref.py index 0ff13547..08026436 100644 --- a/unittest/python/test_eigen_ref.py +++ b/unittest/python/test_eigen_ref.py @@ -1,5 +1,14 @@ import numpy as np -from eigen_ref import * +from eigen_ref import ( + printMatrix, + asRef, + asConstRef, + fill, + getBlock, + editBlock, + modify_block, + has_ref_member, +) def test(mat): diff --git a/unittest/python/test_geometry.py b/unittest/python/test_geometry.py index 80ebf260..c2bd1b1a 100644 --- a/unittest/python/test_geometry.py +++ b/unittest/python/test_geometry.py @@ -1,8 +1,15 @@ from __future__ import print_function -from geometry import * +from geometry import ( + AngleAxis, + Quaternion, + testOutAngleAxis, + testInAngleAxis, + testOutQuaternion, + testInQuaternion, +) import numpy as np -from numpy import cos, sin +from numpy import cos verbose = True diff --git a/unittest/python/test_return_by_ref.py b/unittest/python/test_return_by_ref.py index c93bebc1..dff108ce 100644 --- a/unittest/python/test_return_by_ref.py +++ b/unittest/python/test_return_by_ref.py @@ -21,7 +21,7 @@ def test_shared(mat): try: m_const_ref.fill(2) assert False - except: + except Exception: assert True @@ -43,7 +43,7 @@ def test_not_shared(mat): try: m_const_ref.fill(2) assert True - except: + except Exception: assert False diff --git a/unittest/python/test_self_adjoint_eigen_solver.py b/unittest/python/test_self_adjoint_eigen_solver.py index ae986052..7e5ff1b8 100644 --- a/unittest/python/test_self_adjoint_eigen_solver.py +++ b/unittest/python/test_self_adjoint_eigen_solver.py @@ -1,9 +1,8 @@ import eigenpy -eigenpy.switchToNumpyArray() - import numpy as np -import numpy.linalg as la + +eigenpy.switchToNumpyArray() dim = 100 A = np.random.rand(dim, dim) diff --git a/unittest/python/test_user_type.py b/unittest/python/test_user_type.py index 76e5dfea..6815673c 100644 --- a/unittest/python/test_user_type.py +++ b/unittest/python/test_user_type.py @@ -14,11 +14,12 @@ def test(dtype): assert (mat == mat_copy).all() assert not (mat != mat_copy).all() - # if version.parse(np.__version__) >= version.parse("1.21.0"): # check if it fixes for new versio of NumPy - # mat.fill(mat.dtype.type(20.)) - # mat_copy = mat.copy() - # assert((mat == mat_copy).all()) - # assert(not (mat != mat_copy).all()) + # if version.parse(np.__version__) >= version.parse("1.21.0"): + # # check if it fixes for new version of NumPy + # mat.fill(mat.dtype.type(20.0)) + # mat_copy = mat.copy() + # assert (mat == mat_copy).all() + # assert not (mat != mat_copy).all() mat_op = mat + mat mat_op = mat.copy(order="F") + mat.copy(order="C") @@ -28,7 +29,7 @@ def test(dtype): mat_op = mat.dot(mat.T) mat_op = mat / mat - mat_op = -mat + mat_op = -mat # noqa assert (mat >= mat).all() assert (mat <= mat).all() @@ -47,7 +48,7 @@ def test_cast(from_dtype, to_dtype): np.can_cast(from_dtype, to_dtype) from_mat = np.zeros((rows, cols), dtype=from_dtype) - to_mat = from_mat.astype(dtype=to_dtype) + to_mat = from_mat.astype(dtype=to_dtype) # noqa test(user_type.CustomDouble) -- GitLab