Skip to content

Commit

Permalink
feature: improved CLI installation flow (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich authored Jun 9, 2024
1 parent 7a3f99d commit 2ce49ce
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 67 deletions.
10 changes: 2 additions & 8 deletions Scripts/cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,5 @@
help:
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

prepare: ## Install prerequisites
pip3 install -r requirements.txt

install: prepare ## Build and install the application
python3 setup.py install --user

.PHONY: all
all: install
install: ## Install application
pip3 install . --break-system-packages
2 changes: 1 addition & 1 deletion Scripts/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ All the operations are perform with the usage of **ProtocolBuffers**.
## Setup

First of all connect your board with device installed to serial port. Your board needs to have
already installed software build, which allows communication with TSL2591X device.
already installed software build, which allows communication with **TSL2591X** device.

![](https://www.waveshare.com/w/A6Y79bcq/Kdy80nYY.php?f=TSL25911-Arduino-WS.jpg&width=900)

Expand Down
2 changes: 1 addition & 1 deletion Scripts/cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ def read_requirements() -> list[str]:
packages=find_packages(exclude=["tests", ".github"]),
install_requires=read_requirements(),
entry_points={
"console_scripts": ["light-sensor-cli = src.cli.__main__:main"]
"console_scripts": ["light-sensor-cli = src.__main__:main"]
},
)
13 changes: 10 additions & 3 deletions Scripts/cli/src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import logging
from pathlib import Path

import sys

from .cli import *
from .client import *
from .command import *
from .dto import *
from .middleware import *
from .proto import *
from .tools import *
from .visualizer import *

sys.path.insert(0, "./")

# Initializes logger general configuration.
logging.basicConfig(
filename=f"{str(Path.home())}/light-detector-cli.log", level=logging.INFO, filemode='w', format='%(name)s - %(message)s')
logging.basicConfig(level=logging.INFO, filemode='w', format='%(name)s - %(message)s')
2 changes: 1 addition & 1 deletion Scripts/cli/src/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cli import main
from .cli import main

if __name__ == "__main__":
"""Represents external entrypoint."""
Expand Down
2 changes: 1 addition & 1 deletion Scripts/cli/src/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fire

from command import BaseCommand
from .command import BaseCommand


def main() -> None:
Expand Down
24 changes: 12 additions & 12 deletions Scripts/cli/src/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
from serial import SerialException
from serial import EIGHTBITS

from proto.Content import data_pb2 as DataBus
from proto.Content import info_pb2 as InfoBus
from proto.Content import settings_pb2 as SettingsBus
from proto import request_pb2 as Request
from proto import response_pb2 as Response

from dto import DataTypeCompound
from dto import RetrievedDataDto
from dto import InfoTypeCompound
from dto import RetrievedInfoDto
from dto import SettingsTypeCompound
from dto import SetSettingsDto
from ..proto import data_pb2 as DataBus
from ..proto import info_pb2 as InfoBus
from ..proto import settings_pb2 as SettingsBus
from ..proto import request_pb2 as Request
from ..proto import response_pb2 as Response

from ..dto import DataTypeCompound
from ..dto import RetrievedDataDto
from ..dto import InfoTypeCompound
from ..dto import RetrievedInfoDto
from ..dto import SettingsTypeCompound
from ..dto import SetSettingsDto


class Client:
Expand Down
3 changes: 2 additions & 1 deletion Scripts/cli/src/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from .get_data import GetDataCommand
from .get_info import GetInfoCommand
from .set_settings import SetSettingsCommand
from visualizer import Visualizer

from ..visualizer import Visualizer


class BaseCommand:
Expand Down
10 changes: 5 additions & 5 deletions Scripts/cli/src/command/get_available_devices.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
from serial.tools import list_ports

from middleware import is_manufacturer_allowed
from middleware import is_description_valid
from dto import AvailableDevicesDto
from tools import print_output
from ..middleware import is_manufacturer_allowed
from ..middleware import is_description_valid
from ..dto import AvailableDevicesDto
from ..tools import print_output


class GetAvailableDevicesCommand:
Expand All @@ -25,4 +25,4 @@ def handle() -> None:

logging.info("Available devices have been successfully retrieved.")
else:
logging.error("No available devices found.")
logging.info("No available devices found.")
20 changes: 10 additions & 10 deletions Scripts/cli/src/command/get_data.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging

from middleware import is_device_available
from middleware import is_export_valid
from ..middleware import is_device_available
from ..middleware import is_export_valid

from visualizer import Visualizer
from ..visualizer import Visualizer

from dto import RetrievedDataDto
from dto import VisualizerMetadataDto
from client import Client
from tools import print_output
from ..dto import RetrievedDataDto
from ..dto import VisualizerMetadataDto
from ..client import Client
from ..tools import print_output


class GetDataCommand:
Expand All @@ -24,7 +24,7 @@ def handle(device: str, baud_rate: int, type: str, series: int, export: str, gen
"""Handles the execution of command wrapper."""

if not is_device_available(device):
logging.error("Selected device is not available")
logging.info("Selected device is not available")
return

data: list[RetrievedDataDto] = []
Expand All @@ -44,7 +44,7 @@ def handle(device: str, baud_rate: int, type: str, series: int, export: str, gen
data.append(GetDataCommand.process_get_visible_data(device, baud_rate))

case _:
logging.error("Given data type is not valid.")
logging.info("Given data type is not valid.")
return

print_output(data)
Expand All @@ -67,7 +67,7 @@ def handle(device: str, baud_rate: int, type: str, series: int, export: str, gen
visualizer.select_stairs()

case _:
logging.error("Given figure type is not valid.")
logging.info("Given figure type is not valid.")
return

visualizer.save()
Expand Down
12 changes: 6 additions & 6 deletions Scripts/cli/src/command/get_info.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging

from middleware import is_device_available
from dto import RetrievedInfoDto
from client import Client
from tools import print_output
from ..middleware import is_device_available
from ..dto import RetrievedInfoDto
from ..client import Client
from ..tools import print_output


class GetInfoCommand:
Expand All @@ -19,7 +19,7 @@ def handle(device: str, baud_rate: int, type: str) -> None:
"""Handles the execution of command wrapper."""

if not is_device_available(device):
logging.error("Selected device is not available")
logging.info("Selected device is not available")
return

data: RetrievedInfoDto
Expand All @@ -38,7 +38,7 @@ def handle(device: str, baud_rate: int, type: str) -> None:
data = GetInfoCommand.process_get_device_available_info(device, baud_rate)

case _:
logging.error("Given info type is not valid.")
logging.info("Given info type is not valid.")
return

print_output(data)
Expand Down
16 changes: 8 additions & 8 deletions Scripts/cli/src/command/set_settings.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
from typing import Optional

from middleware import is_device_available
from dto import SetSettingsDto
from client import Client
from tools import print_output
from ..middleware import is_device_available
from ..dto import SetSettingsDto
from ..client import Client
from ..tools import print_output


class SetSettingsCommand:
Expand Down Expand Up @@ -54,7 +54,7 @@ def handle(device: str, baud_rate: int, type: str, value: Optional[str] = None)
"""Handles the execution of command wrapper."""

if not is_device_available(device):
logging.error("Selected device is not available")
logging.info("Selected device is not available")
return

data: SetSettingsDto
Expand All @@ -78,7 +78,7 @@ def handle(device: str, baud_rate: int, type: str, value: Optional[str] = None)
data = SetSettingsCommand.process_set_gain_max_settings(device, baud_rate)

case _:
logging.error("Given settings value type is not valid.")
logging.info("Given settings value type is not valid.")
return

case SetSettingsCommand.SET_INTEGRAL_TIME_TYPE:
Expand Down Expand Up @@ -108,11 +108,11 @@ def handle(device: str, baud_rate: int, type: str, value: Optional[str] = None)
device, baud_rate)

case _:
logging.error("Given settings value type is not valid.")
logging.info("Given settings value type is not valid.")
return

case _:
logging.error("Given settings type is not valid.")
logging.info("Given settings type is not valid.")
return

print_output(data)
Expand Down
6 changes: 4 additions & 2 deletions Scripts/cli/src/proto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from .request_pb2 import RequestContainer
from .response_pb2 import ResponseContainer
from .request_pb2 import *
from .response_pb2 import *

from .Content import *
6 changes: 3 additions & 3 deletions Scripts/cli/src/proto/request_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Scripts/cli/src/proto/response_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Scripts/cli/src/visualizer/visualizer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import matplotlib.pyplot as plt

from dto import RetrievedDataDto
from dto import VisualizerMetadataDto
from ..dto import RetrievedDataDto
from ..dto import VisualizerMetadataDto


class Visualizer:
Expand Down

0 comments on commit 2ce49ce

Please sign in to comment.