Skip to content

Commit

Permalink
apa
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanKarlbergg committed Jan 22, 2024
1 parent c275cb7 commit 2979ee8
Show file tree
Hide file tree
Showing 23 changed files with 268 additions and 214 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Doc builder

on: push

jobs:
build-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build docs
run: |
cd python/remotivelabs-broker
./docker-build.sh
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.8
architecture: x64
- name: Checkout
uses: actions/checkout@v4
- name: Install mypy
run: |
pip install mypy
pip install python/remotivelabs-broker
- name: Run mypy
run: mypy .
19 changes: 19 additions & 0 deletions .github/workflows/code-qa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Code-QA

on: push

jobs:
ruff-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1

ruff-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
with:
src: "."
args: format --check --diff
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.cache
.venv
.local
.config
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8
79 changes: 79 additions & 0 deletions python/remotivelabs-broker/.ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
'deps',
'binaries',
'__pycache__'
]

line-length = 140
indent-width = 4

# Assume Python 3.8
target-version = "py38"

[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false

# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"
9 changes: 8 additions & 1 deletion python/remotivelabs-broker/docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ set -e

docker build -t remotivelabs/python-api-build-image -f docker/Dockerfile .

ARGS="-it"

if [ "${NO_TTY}" == "true" ]; then
ARGS="-i"
fi


docker run \
-u $(id -u):$(id -g) \
-v $(pwd)/../../:/app \
-e "protofile=*.proto" \
-w /app \
-it remotivelabs/python-api-build-image
${ARGS} remotivelabs/python-api-build-image
2 changes: 1 addition & 1 deletion python/remotivelabs-broker/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN pip install hatch json-schema-for-humans
RUN pip3 install grpcio-tools==1.44.0
RUN pip3 install hatch
RUN pip3 install pdoc
RUN pip3 install mypy-protobuf==3.3.0
COPY docker/download_protoc.sh .
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN sh download_protoc.sh
Expand All @@ -25,4 +26,3 @@ ENV protofile=*.proto
VOLUME /ouput

CMD ["./python/remotivelabs-broker/docker/build-all-in-docker.sh"]

7 changes: 6 additions & 1 deletion python/remotivelabs-broker/docker/build-all-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ set -e

HOME=/app/python/remotivelabs-broker
STUBS_OUTPUT=$HOME/remotivelabs/broker/generated/sync
mkdir -p "${STUBS_OUTPUT}"

#1.1 Generate stubs
python3 -m grpc_tools.protoc \
-I /app/protos \
--python_out=$STUBS_OUTPUT \
--grpc_python_out=$STUBS_OUTPUT \
--mypy_out=$STUBS_OUTPUT \
--mypy_grpc_out=$STUBS_OUTPUT \
/app/protos/*.proto

touch "${STUBS_OUTPUT}"/../py.typed

cd $HOME
#1.2 Fix those imports
Expand Down Expand Up @@ -63,4 +68,4 @@ function generate_json() {

generate_python_docs
(cd /app/protos && generate_proto_docs)
(cd /app/schemas/ && generate_json)
(cd /app/schemas/ && generate_json)
1 change: 1 addition & 0 deletions python/remotivelabs-broker/misc/fix_import_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import glob

files = glob.glob("remotivelabs/broker/generated/sync/*.py")
files = files + glob.glob("remotivelabs/broker/generated/sync/*.pyi")

regex_string = r"^import \w+_pb2"
substitute_string = "from . \\g<0>"
Expand Down
9 changes: 6 additions & 3 deletions python/remotivelabs-broker/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ classifiers = [
dependencies = [
"grpc-interceptor~=0.14",
"grpcio~=1.44",
"grpc-stubs~=1.53.0.5",
"requests~=2.21",
"protobuf>=3.19.0,<=3.20.1"
"protobuf>=3.19.0,<=3.20.1",
"mypy-protobuf~=3.3.0",
"types-protobuf~=4.24.0.20240106",
"grpc-interceptor"
]
dynamic = ["version"]

Expand Down Expand Up @@ -92,5 +96,4 @@ exclude_lines = [
]

[tool.hatch.build.targets.wheel]
packages = ["remotivelabs"]

packages = ["remotivelabs", "remotivelabs/broker/py.typed"]
Empty file.
1 change: 1 addition & 0 deletions python/remotivelabs-broker/remotivelabs/broker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
generated/
11 changes: 0 additions & 11 deletions python/remotivelabs-broker/remotivelabs/broker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,3 @@
# SPDX-FileCopyrightText: 2022-present remotiveLabs <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

from .__about__ import __version__
import logging

log: logging.Logger = logging.getLogger("com.remotivelabs.broker")
"""Package logging interface"""

log.addHandler(logging.NullHandler())

version: str = __version__
"""Library version"""

This file was deleted.

Empty file.
25 changes: 12 additions & 13 deletions python/remotivelabs-broker/remotivelabs/broker/sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,25 @@
Link: <https://github.com/remotivelabs/remotivelabs-samples/tree/main/python>.
"""

from ..generated.sync import common_pb2
from ..generated.sync import common_pb2_grpc
from ..generated.sync import diagnostics_api_pb2
from ..generated.sync import diagnostics_api_pb2_grpc
from ..generated.sync import functional_api_pb2
from ..generated.sync import functional_api_pb2_grpc
from ..generated.sync import network_api_pb2
from ..generated.sync import network_api_pb2_grpc
from ..generated.sync import system_api_pb2
from ..generated.sync import system_api_pb2_grpc
from ..generated.sync import traffic_api_pb2
from ..generated.sync import traffic_api_pb2_grpc
from ..generated.sync import common_pb2 # noqa: F401
from ..generated.sync import common_pb2_grpc # noqa: F401
from ..generated.sync import diagnostics_api_pb2 # noqa: F401
from ..generated.sync import diagnostics_api_pb2_grpc # noqa: F401
from ..generated.sync import functional_api_pb2 # noqa: F401
from ..generated.sync import functional_api_pb2_grpc # noqa: F401
from ..generated.sync import network_api_pb2 # noqa: F401
from ..generated.sync import network_api_pb2_grpc # noqa: F401
from ..generated.sync import system_api_pb2 # noqa: F401
from ..generated.sync import system_api_pb2_grpc # noqa: F401
from ..generated.sync import traffic_api_pb2 # noqa: F401
from ..generated.sync import traffic_api_pb2_grpc # noqa: F401

from .signalcreator import SignalCreator
from .client import Client
from .client import SignalValue
from .client import SignalsInFrame
from .client import SignalIdentifier
from .client import BrokerException
from .client import SignalsInFrame
from .helper import create_channel
from .helper import publish_signals
from .helper import printer
Expand Down
Loading

0 comments on commit 2979ee8

Please sign in to comment.