From 0faf5db50809d8f8307128d57b4820abe9a43400 Mon Sep 17 00:00:00 2001 From: Mikhail Kiselyov Date: Sat, 4 Nov 2023 15:55:38 +0300 Subject: [PATCH 1/7] add linters and tests workflow --- .github/workflows/python-package.yml | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/python-package.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..b62b67d --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,45 @@ +name: Tests and Linters + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest + pip install -r requirements.txt + + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + + - name: Lint with black + uses: psf/black@stable + with: + options: "--check --verbose" + + - name: Test with pytest + run: | + pytest \ No newline at end of file From 742d1c78b19170189851554344ee88d7ffd06dbd Mon Sep 17 00:00:00 2001 From: Mikhail Kiselyov Date: Sat, 4 Nov 2023 15:57:54 +0300 Subject: [PATCH 2/7] format voxel.py --- octreelib/internal/voxel.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/octreelib/internal/voxel.py b/octreelib/internal/voxel.py index c72237a..b8666f7 100644 --- a/octreelib/internal/voxel.py +++ b/octreelib/internal/voxel.py @@ -90,9 +90,7 @@ def __init__( ): super().__init__(corner_min, edge_length) - self._points: PointCloud = ( - points if points is not None else PointCloud.empty() - ) + self._points: PointCloud = points if points is not None else PointCloud.empty() def get_points(self) -> RawPointCloud: """ From 7c6b8a28126a53987a6de2ae240079f5e577da5e Mon Sep 17 00:00:00 2001 From: Mikhail Kiselyov Date: Sun, 5 Nov 2023 14:46:07 +0300 Subject: [PATCH 3/7] install library before running pytest --- .github/workflows/python-package.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index b62b67d..690a99f 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -42,4 +42,5 @@ jobs: - name: Test with pytest run: | + pip install . pytest \ No newline at end of file From 155d2a6865b98a8258a6903d9b64fea08896df91 Mon Sep 17 00:00:00 2001 From: Mikhail Kiselyov Date: Sun, 5 Nov 2023 18:12:43 +0300 Subject: [PATCH 4/7] fix mutable field in dataclass --- octreelib/grid/grid_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octreelib/grid/grid_base.py b/octreelib/grid/grid_base.py index 9ac76f6..fbe2078 100644 --- a/octreelib/grid/grid_base.py +++ b/octreelib/grid/grid_base.py @@ -1,5 +1,5 @@ from abc import ABC, abstractmethod -from dataclasses import dataclass +from dataclasses import dataclass, field from enum import Enum from typing import Callable, Generic, List, Type @@ -63,7 +63,7 @@ class GridConfigBase(ABC): octree_config: OctreeConfigBase debug: bool = False grid_voxel_edge_length: int = 1 - corner: RawPoint = np.array(([0.0, 0.0, 0.0])) + corner: RawPoint = field(default_factory=lambda: np.array(([0.0, 0.0, 0.0]))) @property def compatible_octree_types(self): From c0f77de2f57d7bce91006eadc70bd9fb41a4b057 Mon Sep 17 00:00:00 2001 From: Mikhail Kiselyov Date: Sun, 5 Nov 2023 18:17:52 +0300 Subject: [PATCH 5/7] fix unused imports internal/voxel.py --- octreelib/internal/voxel.py | 1 - 1 file changed, 1 deletion(-) diff --git a/octreelib/internal/voxel.py b/octreelib/internal/voxel.py index b8666f7..b9e3de6 100644 --- a/octreelib/internal/voxel.py +++ b/octreelib/internal/voxel.py @@ -1,5 +1,4 @@ import itertools -from abc import ABC, abstractmethod from typing import Optional import numpy as np From 050c4a9384f0f50c0cb6be454798aa517f4763aa Mon Sep 17 00:00:00 2001 From: Mikhail Kiselyov Date: Sun, 5 Nov 2023 18:24:51 +0300 Subject: [PATCH 6/7] display diff on lint with black --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 690a99f..6fff9ff 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -38,7 +38,7 @@ jobs: - name: Lint with black uses: psf/black@stable with: - options: "--check --verbose" + options: "--check --verbose --diff" - name: Test with pytest run: | From 9bec93051beb7264860429b1e4a76d9f5537ba05 Mon Sep 17 00:00:00 2001 From: Mikhail Kiselyov Date: Sun, 5 Nov 2023 18:33:54 +0300 Subject: [PATCH 7/7] format voxel.py --- octreelib/internal/voxel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/octreelib/internal/voxel.py b/octreelib/internal/voxel.py index a7ecb02..ad94ad0 100644 --- a/octreelib/internal/voxel.py +++ b/octreelib/internal/voxel.py @@ -47,7 +47,9 @@ def is_point_geometrically_inside(self, point: RawPoint) -> bool: :param point: Point to check. :return: True if point is inside the bounding box of a voxel, False if outside. """ - return bool((point >= self.corner_min).all()) and bool((point <= self.corner_max).all()) + return bool((point >= self.corner_min).all()) and bool( + (point <= self.corner_max).all() + ) @property def corner_min(self):