From 5b830dcc0c48362e0d55b7effa763efb69a82845 Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Mon, 4 Feb 2019 14:42:35 +0100 Subject: [PATCH 1/8] tests: Run the flake8 linter This is useful to catch simple mistakes, unused variables or imports, ... --- lint-requirements.txt | 1 + lint.sh | 4 ++++ setup.cfg | 3 +++ 3 files changed, 8 insertions(+) create mode 100644 setup.cfg diff --git a/lint-requirements.txt b/lint-requirements.txt index 7089aea6..8b233adf 100644 --- a/lint-requirements.txt +++ b/lint-requirements.txt @@ -1 +1,2 @@ +flake8 mypy>=0.670 diff --git a/lint.sh b/lint.sh index 36826702..4c2c6f38 100755 --- a/lint.sh +++ b/lint.sh @@ -6,4 +6,8 @@ if [[ "${PYTHON-x}" =~ pypy-* ]]; then exit 0 fi +run flake8 --version +run flake8 --ignore F403,F405 tests +run flake8 --exclude tests/ + run ${PY} -m mypy ppb_vector tests diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..c8de6df4 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[flake8] +ignore = E704 +max-line-length = 100 From 3db821a7ac46206a30b30f2cb247c22ec28fc381 Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Mon, 4 Feb 2019 15:05:25 +0100 Subject: [PATCH 2/8] tests/flake8: Enforce naming conventions consistent with PEP 8 --- lint-requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/lint-requirements.txt b/lint-requirements.txt index 8b233adf..a261218b 100644 --- a/lint-requirements.txt +++ b/lint-requirements.txt @@ -1,2 +1,3 @@ flake8 mypy>=0.670 +pep8-naming From 1c54d9be5c120e3251877f387f07266b060c85a7 Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Fri, 15 Mar 2019 19:03:18 +0100 Subject: [PATCH 3/8] tests/flake8: Enable the bugbear plugin --- lint-requirements.txt | 1 + setup.cfg | 1 + 2 files changed, 2 insertions(+) diff --git a/lint-requirements.txt b/lint-requirements.txt index a261218b..76d7d62d 100644 --- a/lint-requirements.txt +++ b/lint-requirements.txt @@ -1,3 +1,4 @@ flake8 +flake8-bugbear mypy>=0.670 pep8-naming diff --git a/setup.cfg b/setup.cfg index c8de6df4..39f42289 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,4 @@ [flake8] +select = E,F,W,B,B9 ignore = E704 max-line-length = 100 From e965e802c8e8053029fa339e1c81b01263836b8f Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Fri, 15 Mar 2019 19:04:59 +0100 Subject: [PATCH 4/8] tests/flake8: Enforce trailing commas --- lint-requirements.txt | 1 + setup.cfg | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lint-requirements.txt b/lint-requirements.txt index 76d7d62d..d6046ef8 100644 --- a/lint-requirements.txt +++ b/lint-requirements.txt @@ -1,4 +1,5 @@ flake8 flake8-bugbear +flake8-commas mypy>=0.670 pep8-naming diff --git a/setup.cfg b/setup.cfg index 39f42289..83659d58 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,4 @@ [flake8] -select = E,F,W,B,B9 +select = C,E,F,W,B,B9 ignore = E704 max-line-length = 100 From 08ebe04db45cc35e8293d4f507b0225a31059637 Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Fri, 15 Mar 2019 19:06:18 +0100 Subject: [PATCH 5/8] tests/flake8: Enforce uniform import order --- lint-requirements.txt | 1 + setup.cfg | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lint-requirements.txt b/lint-requirements.txt index d6046ef8..89b11ccb 100644 --- a/lint-requirements.txt +++ b/lint-requirements.txt @@ -1,5 +1,6 @@ flake8 flake8-bugbear flake8-commas +flake8-import-order mypy>=0.670 pep8-naming diff --git a/setup.cfg b/setup.cfg index 83659d58..f3083629 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,7 @@ [flake8] -select = C,E,F,W,B,B9 +select = C,E,F,I,W,B,B9 ignore = E704 max-line-length = 100 + +application-import-names = ppb_vector,utils +import-order-style = smarkets From 091115daf4d251b5c80eb52f5e053cfafc49c521 Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Mon, 18 Mar 2019 12:21:28 +0100 Subject: [PATCH 6/8] tests: Comply with PEP8 style --- tests/test_memory.py | 3 +- tests/test_vector2_rotate.py | 40 +++++++++++---------- tests/test_vector2_scalar_multiplication.py | 1 + 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/tests/test_memory.py b/tests/test_memory.py index 571ca98e..d95e9afa 100644 --- a/tests/test_memory.py +++ b/tests/test_memory.py @@ -20,8 +20,7 @@ def __init__(self, x, y): @pytest.mark.skipif(sys.implementation.name != 'cpython', - reason="PyPy optimises __slots__ automatically.", -) + reason="PyPy optimises __slots__ automatically.") @given(x=floats(), y=floats()) def test_object_size(x, y): """Check that Vector2 is 2 times smaller than a naïve version.""" diff --git a/tests/test_vector2_rotate.py b/tests/test_vector2_rotate.py index c920ef82..a1d5fb49 100644 --- a/tests/test_vector2_rotate.py +++ b/tests/test_vector2_rotate.py @@ -16,43 +16,43 @@ (Vector2(1, 1), 180, Vector2(-1, -1)), ] + @pytest.mark.parametrize("input, angle, expected", data_exact, - ids=[str(angle) for _, angle, _ in data_exact], -) + ids=[str(angle) for _, angle, _ in data_exact]) def test_exact_rotations(input, angle, expected): assert input.rotate(angle) == expected assert input.angle(expected) == angle # angle (in degrees) -> (sin, cos) -## values from 0 to 45° -## lifted from https://en.wikibooks.org/wiki/Trigonometry/Selected_Angles_Reference +# values from 0 to 45° +# lifted from https://en.wikibooks.org/wiki/Trigonometry/Selected_Angles_Reference remarkable_angles = { - 15: ((sqrt(6) - sqrt(2))/4, (sqrt(6) + sqrt(2))/4), - 22.5: (sqrt(2 - sqrt(2))/2, sqrt(2 + sqrt(2))/2), - 30: (0.5, sqrt(3)/2), - 45: (sqrt(2)/2, sqrt(2)/2), + 15: ((sqrt(6) - sqrt(2)) / 4, (sqrt(6) + sqrt(2)) / 4), + 22.5: (sqrt(2 - sqrt(2)) / 2, sqrt(2 + sqrt(2)) / 2), + 30: (0.5, sqrt(3) / 2), + 45: (sqrt(2) / 2, sqrt(2) / 2), } -## extend up to 90° +# extend up to 90° remarkable_angles.update({ 90 - angle: (cos_t, sin_t) for angle, (sin_t, cos_t) in remarkable_angles.items() }) -## extend up to 180° +# extend up to 180° remarkable_angles.update({ angle + 90: (cos_t, -sin_t) for angle, (sin_t, cos_t) in remarkable_angles.items() }) -## extend up to 360° +# extend up to 360° remarkable_angles.update({ angle + 180: (-sin_t, -cos_t) for angle, (sin_t, cos_t) in remarkable_angles.items() }) -## extend to negative angles +# extend to negative angles remarkable_angles.update({ -angle: (-sin_t, cos_t) for angle, (sin_t, cos_t) in remarkable_angles.items() @@ -60,8 +60,7 @@ def test_exact_rotations(input, angle, expected): @pytest.mark.parametrize("angle, trig", remarkable_angles.items(), - ids=[str(x) for x in remarkable_angles] -) + ids=[str(x) for x in remarkable_angles]) def test_remarkable_angles(angle, trig): _angle = math.radians(angle) sin_t, cos_t = trig @@ -79,11 +78,14 @@ def test_remarkable_angles(angle, trig): for (angle, (sin_t, cos_t)) in remarkable_angles.items() ] +data_close_ids = [ + f"(1,0).rotate({x})" for x in remarkable_angles +] + [ + f"(1,1).rotate({x})" for x in remarkable_angles +] + -@pytest.mark.parametrize("input, angle, expected", data_close, - ids=[f"(1,0).rotate({x})" for x in remarkable_angles] + - [f"(1,1).rotate({x})" for x in remarkable_angles], -) +@pytest.mark.parametrize("input, angle, expected", data_close, ids=data_close_ids) def test_close_rotations(input, angle, expected): assert input.rotate(angle).isclose(expected) assert angle_isclose(input.angle(expected), angle) @@ -111,7 +113,7 @@ def test_trig_stability(angle): def test_trig_invariance(angle: float, n: int): """Test that cos(θ), sin(θ) ≃ cos(θ + n*360°), sin(θ + n*360°)""" r_cos, r_sin = Vector2._trig(angle) - n_cos, n_sin = Vector2._trig(angle + 360*n) + n_cos, n_sin = Vector2._trig(angle + 360 * n) note(f"δcos: {r_cos - n_cos}") assert isclose(r_cos, n_cos, rel_to=[n / 1e9]) diff --git a/tests/test_vector2_scalar_multiplication.py b/tests/test_vector2_scalar_multiplication.py index 18d78bbb..e9bff73f 100644 --- a/tests/test_vector2_scalar_multiplication.py +++ b/tests/test_vector2_scalar_multiplication.py @@ -39,6 +39,7 @@ def test_scalar_division(x: Vector2, scalar: float): assume(abs(scalar) > 1e-100) assert (x / scalar).isclose((1 / scalar) * x) + @given(x=vectors(), scalar=floats()) def test_scalar_inverse(x: Vector2, scalar: float): """Test that (x / λ) = (1 / λ) * x""" From 72bdb042d405111b3015a82eabacfcee902e5638 Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Tue, 26 Mar 2019 17:17:09 +0100 Subject: [PATCH 7/8] docs/conf.py: Add missing trailing comma --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 9b5ffab2..7076abfb 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -148,7 +148,7 @@ # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'ppb-vector', 'ppb-vector Documentation', - [author], 1) + [author], 1), ] From f5947715c9f07570c550a74fbfd51795704db8ee Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Tue, 26 Mar 2019 17:17:54 +0100 Subject: [PATCH 8/8] Vector2.truncate: Eliminate invalid escape sequence in docstring --- ppb_vector/vector2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ppb_vector/vector2.py b/ppb_vector/vector2.py index 9228f543..d6ce62dd 100644 --- a/ppb_vector/vector2.py +++ b/ppb_vector/vector2.py @@ -487,7 +487,7 @@ def truncate(self: Vector, max_length: typing.SupportsFloat) -> Vector: Note that :py:meth:`vector.scale(max_length) ` is equivalent to :py:meth:`vector.truncate(max_length) ` when - :py:meth:`max_length \< vector.length `. + :py:meth:`max_length ≨ vector.length `. >>> Vector2(3, 4).scale(4) Vector2(2.4, 3.2)