Skip to content

Commit

Permalink
Prepare project for pip packaging (#45)
Browse files Browse the repository at this point in the history
 - use relative imports
 - use pkg_ressource for paths
 - move tests inside package
 - update setup.py
 - bump version
  • Loading branch information
ch-sa authored Dec 18, 2021
1 parent 08b6ecf commit 81995f9
Show file tree
Hide file tree
Showing 48 changed files with 223 additions and 199 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
- name: Test with pytest
run: |
python -m pytest tests/integration/
python -m pytest labelCloud/tests/integration/
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:

- name: Test with pytest
run: |
python -m pytest tests/unit/
python -m pytest labelCloud/tests/unit/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,4 @@ cython_debug/
!.vscode/*.code-snippets

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,python
.vscode/launch.json
9 changes: 3 additions & 6 deletions labelCloud.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
if __name__ == "__main__":

import sys
from labelCloud.__main__ import main

sys.path.insert(0, "labelCloud")
from labelCloud import app
if __name__ == "__main__":

app.run()
main()
2 changes: 1 addition & 1 deletion labelCloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.0"
__version__ = "0.6.1"
34 changes: 30 additions & 4 deletions labelCloud/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
import sys

sys.path.insert(0, "labelCloud")
from PyQt5.QtWidgets import QApplication, QDesktopWidget

if __name__ == "__main__":
import app

app.run()
from labelCloud.view.gui import GUI
from labelCloud.control.controller import Controller


def main():
app = QApplication(sys.argv)

# Setup Model-View-Control structure
control = Controller()
view = GUI(control)

# Install event filter to catch user interventions
app.installEventFilter(view)

# Start GUI
view.show()

app.setStyle("Fusion")
desktop = QDesktopWidget().availableGeometry()
width = (desktop.width() - view.width()) / 2
height = (desktop.height() - view.height()) / 2
view.move(width, height)

print("Showing GUI...")
sys.exit(app.exec_())


if __name__ == "__main__":
main()
30 changes: 0 additions & 30 deletions labelCloud/app.py

This file was deleted.

4 changes: 2 additions & 2 deletions labelCloud/control/alignmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from typing import TYPE_CHECKING, Union

import numpy as np
import utils.oglhelper as ogl

from ..utils import oglhelper as ogl
from .pcd_manager import PointCloudManger

if TYPE_CHECKING:
from view.gui import GUI
from ..view.gui import GUI


class AlignMode(object):
Expand Down
8 changes: 4 additions & 4 deletions labelCloud/control/bbox_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
Bounding Box Management: adding, selecting updating, deleting bboxes;
Possible Active Bounding Box Manipulations: rotation, translation, scaling
"""
from typing import TYPE_CHECKING, List, Optional, Union
from typing import TYPE_CHECKING, List, Optional

import numpy as np
from model.bbox import BBox
from utils import oglhelper

from ..model.bbox import BBox
from ..utils import oglhelper
from .config_manager import config

if TYPE_CHECKING:
from view.gui import GUI
from ..view.gui import GUI


# DECORATORS
Expand Down
8 changes: 6 additions & 2 deletions labelCloud/control/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os
from typing import List

import pkg_resources


class ExtendedConfigParser(configparser.ConfigParser):
"""Extends the ConfigParser with the ability to read and parse lists.
Expand All @@ -22,8 +24,10 @@ def getlist(self, section, option, raw=False, vars=None, fallback=None) -> List:


class ConfigManager(object):
PATH_TO_CONFIG = "config.ini"
PATH_TO_DEFAULT_CONFIG = "ressources/default_config.ini"
PATH_TO_CONFIG = "config.ini" # TODO: Handle!
PATH_TO_DEFAULT_CONFIG = pkg_resources.resource_filename(
"labelCloud.ressources", "default_config.ini"
)

def __init__(self) -> None:
self.config = ExtendedConfigParser(comment_prefixes="/", allow_no_value=True)
Expand Down
8 changes: 4 additions & 4 deletions labelCloud/control/controller.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Union

from PyQt5 import QtCore, QtGui
from utils import oglhelper
from model.bbox import BBox
from view.gui import GUI

from ..definitions import BBOX_SIDES
from ..utils import oglhelper
from ..view.gui import GUI
from .alignmode import AlignMode
from .bbox_controller import BoundingBoxController
from .drawing_manager import DrawingManager
Expand Down Expand Up @@ -117,7 +117,7 @@ def set_selected_side(self) -> None:
self.view.glWidget.crosshair_col = [1, 0, 0]
side_vertices = self.bbox_controller.get_active_bbox().get_vertices()
self.view.glWidget.selected_side_vertices = side_vertices[
BBox.BBOX_SIDES[self.selected_side]
BBOX_SIDES[self.selected_side]
]
else:
self.view.glWidget.selected_side_vertices = []
Expand Down
5 changes: 2 additions & 3 deletions labelCloud/control/drawing_manager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import TYPE_CHECKING, Union

from labeling_strategies import BaseLabelingStrategy

from ..labeling_strategies import BaseLabelingStrategy
from .bbox_controller import BoundingBoxController

if TYPE_CHECKING:
from view.gui import GUI
from ..view.gui import GUI


class DrawingManager(object):
Expand Down
5 changes: 2 additions & 3 deletions labelCloud/control/label_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import os
from typing import List

from label_formats import BaseLabelFormat, CentroidFormat, KittiFormat, VerticesFormat
from model.bbox import BBox

from ..label_formats import BaseLabelFormat, CentroidFormat, KittiFormat, VerticesFormat
from ..model.bbox import BBox
from .config_manager import config


Expand Down
15 changes: 10 additions & 5 deletions labelCloud/control/pcd_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

import numpy as np
import open3d as o3d
from model.bbox import BBox
from model.point_cloud import PointCloud

from ..model import BBox, PointCloud
from .config_manager import config
from .label_manager import LabelManager

if TYPE_CHECKING:
from view.gui import GUI
from ..view.gui import GUI

import pkg_resources


@dataclass
Expand All @@ -27,7 +28,9 @@ class Perspective(object):


def color_pointcloud(points, z_min, z_max) -> np.ndarray:
palette = np.loadtxt("labelCloud/ressources/rocket-palette.txt")
palette = np.loadtxt(
pkg_resources.resource_filename("labelCloud.ressources", "rocket-palette.txt")
)
palette_len = len(palette) - 1

colors = np.zeros(points.shape)
Expand Down Expand Up @@ -81,7 +84,9 @@ def read_pointcloud_folder(self) -> None:
"Please set the point cloud folder to a location that contains point cloud files."
)
self.pointcloud = self.load_pointcloud(
"labelCloud/ressources/labelCloud_icon.pcd"
pkg_resources.resource_filename(
"labelCloud.ressources", "labelCloud_icon.pcd"
)
)
self.update_pcd_infos(pointcloud_label=" – (select folder!)")

Expand Down
1 change: 1 addition & 0 deletions labelCloud/definitions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .bbox import BBOX_EDGES, BBOX_SIDES
26 changes: 26 additions & 0 deletions labelCloud/definitions/bbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# order in which the bounding box edges are drawn
BBOX_EDGES = [
(0, 1),
(0, 3),
(0, 4),
(2, 1),
(2, 3),
(2, 6),
(5, 1),
(5, 4),
(5, 6),
(7, 3),
(7, 4),
(7, 6),
]


# vertices of each side
BBOX_SIDES = {
"top": [4, 5, 6, 7],
"bottom": [0, 1, 2, 3],
"right": [2, 3, 7, 6],
"back": [0, 3, 7, 4],
"left": [0, 1, 5, 4],
"front": [1, 2, 6, 5],
}
3 changes: 2 additions & 1 deletion labelCloud/label_formats/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from typing import List, Optional, Union

import numpy as np
from model import BBox

from ..model import BBox


class BaseLabelFormat(ABC):
Expand Down
3 changes: 1 addition & 2 deletions labelCloud/label_formats/centroid_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import os
from typing import List

from model import BBox

from ..model import BBox
from . import BaseLabelFormat, abs2rel_rotation, rel2abs_rotation


Expand Down
3 changes: 1 addition & 2 deletions labelCloud/label_formats/kitti_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import os
from typing import List

from model import BBox

from ..model import BBox
from . import BaseLabelFormat, abs2rel_rotation, rel2abs_rotation


Expand Down
4 changes: 2 additions & 2 deletions labelCloud/label_formats/vertices_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from typing import List

import numpy as np
from model import BBox
from utils import math3d

from ..model import BBox
from ..utils import math3d
from . import BaseLabelFormat


Expand Down
7 changes: 3 additions & 4 deletions labelCloud/labeling_strategies/base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, List

from model.bbox import BBox

if TYPE_CHECKING:
from view.gui import GUI
from ..model import BBox
from ..view.gui import GUI


class BaseLabelingStrategy(ABC):
Expand All @@ -30,7 +29,7 @@ def register_scrolling(self, distance: float) -> None:
pass

@abstractmethod
def get_bbox(self) -> BBox:
def get_bbox(self) -> "BBox":
raise NotImplementedError

def draw_preview(self) -> None:
Expand Down
8 changes: 4 additions & 4 deletions labelCloud/labeling_strategies/picking.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from typing import TYPE_CHECKING, List

import numpy as np
import utils.oglhelper as ogl
from control.config_manager import config
from model import BBox

from ..control.config_manager import config
from ..model import BBox
from ..utils import oglhelper as ogl
from . import BaseLabelingStrategy

if TYPE_CHECKING:
from view.gui import GUI
from ..view.gui import GUI


class PickingStrategy(BaseLabelingStrategy):
Expand Down
10 changes: 5 additions & 5 deletions labelCloud/labeling_strategies/spanning.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from typing import TYPE_CHECKING, List

import numpy as np
import utils.math3d as math3d
import utils.oglhelper as ogl
from control.config_manager import config
from model import BBox

from ..control.config_manager import config
from ..model import BBox
from ..utils import math3d as math3d
from ..utils import oglhelper as ogl
from . import BaseLabelingStrategy

if TYPE_CHECKING:
from view.gui import GUI
from ..view.gui import GUI

import numpy as np

Expand Down
Loading

0 comments on commit 81995f9

Please sign in to comment.