From aef03ad62fa96f43f4dd680744754d261a5cc880 Mon Sep 17 00:00:00 2001 From: Tomas Nilsson Date: Wed, 18 Sep 2024 08:27:14 +0000 Subject: [PATCH] chore(grpc-asyncio): add consistent tooling Use the same test, lint and type checking across all our python projects. For API, that means adding pylint. --- ...code-qa-ci.yaml => python-code-qa-ci.yaml} | 28 +-- .github/workflows/rust-code-qa-ci.yaml | 24 ++ python/remotivelabs-broker/.ruff.toml | 76 ------ python/remotivelabs-broker/poetry.lock | 226 ++++++++++++++---- python/remotivelabs-broker/poetry.toml | 2 + python/remotivelabs-broker/pyproject.toml | 74 ++++-- .../remotivelabs/broker/sync/client.py | 2 +- .../remotivelabs/broker/sync/helper.py | 4 +- .../remotivelabs/broker/sync/signalcreator.py | 26 +- .../tests/system/test_smoke_system.py | 4 +- .../tests/unit/test_proto_types.py | 2 +- 11 files changed, 285 insertions(+), 183 deletions(-) rename .github/workflows/{code-qa-ci.yaml => python-code-qa-ci.yaml} (60%) create mode 100644 .github/workflows/rust-code-qa-ci.yaml delete mode 100644 python/remotivelabs-broker/.ruff.toml create mode 100644 python/remotivelabs-broker/poetry.toml diff --git a/.github/workflows/code-qa-ci.yaml b/.github/workflows/python-code-qa-ci.yaml similarity index 60% rename from .github/workflows/code-qa-ci.yaml rename to .github/workflows/python-code-qa-ci.yaml index a7737ea..7535fd8 100644 --- a/.github/workflows/code-qa-ci.yaml +++ b/.github/workflows/python-code-qa-ci.yaml @@ -1,4 +1,4 @@ -name: Code QA CI +name: Python Code QA CI on: push @@ -6,7 +6,6 @@ jobs: python-ci: runs-on: ubuntu-latest strategy: - fail-fast: false matrix: python-version: ["3.8", "3.9", "3.10"] defaults: @@ -28,26 +27,15 @@ jobs: run: ./docker-build.sh - run: poetry install + - name: run pytest run: poetry poe test + - name: run ruff run: poetry poe lint - - name: run mypy - run: poetry poe mypy-check - rust-cargo: - name: Rust cargo tasks - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - name: Build and run tests - run: | - pushd rust/remotivelabs-broker - cargo test - popd - - name: Check format - run: | - pushd rust/remotivelabs-broker - cargo fmt --check - popd + - name: run pylint + run: poetry poe pylint + + - name: run mypy + run: poetry poe mypy diff --git a/.github/workflows/rust-code-qa-ci.yaml b/.github/workflows/rust-code-qa-ci.yaml new file mode 100644 index 0000000..c64d686 --- /dev/null +++ b/.github/workflows/rust-code-qa-ci.yaml @@ -0,0 +1,24 @@ +name: Rust Code QA CI + +on: push + +jobs: + rust-ci: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@stable + + - name: Build and run tests + run: | + pushd rust/remotivelabs-broker + cargo test + popd + + - name: Check format + run: | + pushd rust/remotivelabs-broker + cargo fmt --check + popd diff --git a/python/remotivelabs-broker/.ruff.toml b/python/remotivelabs-broker/.ruff.toml deleted file mode 100644 index 8b1d4fc..0000000 --- a/python/remotivelabs-broker/.ruff.toml +++ /dev/null @@ -1,76 +0,0 @@ -# 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] -select = ["C901", "E", "W", "F", "RET505", "I001", "B034", "EXE001", "N806", "UP032", "FA100"] -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" diff --git a/python/remotivelabs-broker/poetry.lock b/python/remotivelabs-broker/poetry.lock index 9b4ce84..3adfe11 100644 --- a/python/remotivelabs-broker/poetry.lock +++ b/python/remotivelabs-broker/poetry.lock @@ -1,5 +1,19 @@ # This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +[[package]] +name = "astroid" +version = "3.2.4" +description = "An abstract syntax tree for Python with inference support." +optional = false +python-versions = ">=3.8.0" +files = [ + {file = "astroid-3.2.4-py3-none-any.whl", hash = "sha256:413658a61eeca6202a59231abb473f932038fbcbf1666587f66d482083413a25"}, + {file = "astroid-3.2.4.tar.gz", hash = "sha256:0e14202810b30da1b735827f78f5157be2bbd4a7a59b7707ca0bfc2fb4c0063a"}, +] + +[package.dependencies] +typing-extensions = {version = ">=4.0.0", markers = "python_version < \"3.11\""} + [[package]] name = "astunparse" version = "1.6.3" @@ -256,6 +270,21 @@ typing-inspect = ">=0.4.0" [package.extras] dev = ["flake8", "hypothesis", "ipython", "mypy (>=0.710)", "portray", "pytest (>=7.2.0)", "setuptools", "simplejson", "twine", "types-dataclasses", "wheel"] +[[package]] +name = "dill" +version = "0.3.8" +description = "serialize all of Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "dill-0.3.8-py3-none-any.whl", hash = "sha256:c36ca9ffb54365bdd2f8eb3eff7d2a21237f8452b57ace88b1ac615b7e815bd7"}, + {file = "dill-0.3.8.tar.gz", hash = "sha256:3ebe3c479ad625c4553aca177444d89b486b1d84982eeacded644afc0cf797ca"}, +] + +[package.extras] +graph = ["objgraph (>=1.7.2)"] +profile = ["gprof2dot (>=2022.7.29)"] + [[package]] name = "exceptiongroup" version = "1.2.2" @@ -272,20 +301,20 @@ test = ["pytest (>=6)"] [[package]] name = "grpc-interceptor" -version = "0.15.0" +version = "0.15.4" description = "Simplifies gRPC interceptors" optional = false -python-versions = ">=3.6.1,<4.0.0" +python-versions = ">=3.7,<4.0" files = [ - {file = "grpc-interceptor-0.15.0.tar.gz", hash = "sha256:5c1aa9680b1d7e12259960c38057b121826860b05ebbc1001c74343b7ad1455e"}, - {file = "grpc_interceptor-0.15.0-py3-none-any.whl", hash = "sha256:63e390162e64df96c39c40508eb697def76a7cafac32a7eaf9272093eec1109e"}, + {file = "grpc-interceptor-0.15.4.tar.gz", hash = "sha256:1f45c0bcb58b6f332f37c637632247c9b02bc6af0fdceb7ba7ce8d2ebbfb0926"}, + {file = "grpc_interceptor-0.15.4-py3-none-any.whl", hash = "sha256:0035f33228693ed3767ee49d937bac424318db173fef4d2d0170b3215f254d9d"}, ] [package.dependencies] -grpcio = ">=1.32.0,<2.0.0" +grpcio = ">=1.49.1,<2.0.0" [package.extras] -testing = ["protobuf (>=3.6.0)"] +testing = ["protobuf (>=4.21.9)"] [[package]] name = "grpc-stubs" @@ -431,15 +460,18 @@ files = [ [[package]] name = "idna" -version = "3.8" +version = "3.10" description = "Internationalized Domain Names in Applications (IDNA)" optional = false python-versions = ">=3.6" files = [ - {file = "idna-3.8-py3-none-any.whl", hash = "sha256:050b4e5baadcd44d760cedbd2b8e639f2ff89bbc7a5730fcc662954303377aac"}, - {file = "idna-3.8.tar.gz", hash = "sha256:d838c2c0ed6fced7693d5e8ab8e734d5f8fda53a039c0164afb0b82e771e3603"}, + {file = "idna-3.10-py3-none-any.whl", hash = "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3"}, + {file = "idna-3.10.tar.gz", hash = "sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9"}, ] +[package.extras] +all = ["flake8 (>=7.1.1)", "mypy (>=1.11.2)", "pytest (>=8.3.2)", "ruff (>=0.6.2)"] + [[package]] name = "iniconfig" version = "2.0.0" @@ -451,6 +483,20 @@ files = [ {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, ] +[[package]] +name = "isort" +version = "5.13.2" +description = "A Python utility / library to sort Python imports." +optional = false +python-versions = ">=3.8.0" +files = [ + {file = "isort-5.13.2-py3-none-any.whl", hash = "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6"}, + {file = "isort-5.13.2.tar.gz", hash = "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109"}, +] + +[package.extras] +colors = ["colorama (>=0.4.6)"] + [[package]] name = "jinja2" version = "3.1.4" @@ -610,6 +656,17 @@ files = [ [package.dependencies] marshmallow = ">=2.0.0" +[[package]] +name = "mccabe" +version = "0.7.0" +description = "McCabe checker, plugin for flake8" +optional = false +python-versions = ">=3.6" +files = [ + {file = "mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"}, + {file = "mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"}, +] + [[package]] name = "mypy" version = "1.11.2" @@ -699,6 +756,22 @@ pygments = ">=2.12.0" [package.extras] dev = ["black", "hypothesis", "mypy", "pytest", "pytest-cov", "pytest-timeout", "ruff", "tox", "types-pygments"] +[[package]] +name = "platformdirs" +version = "4.3.6" +description = "A small Python package for determining appropriate platform-specific dirs, e.g. a `user data dir`." +optional = false +python-versions = ">=3.8" +files = [ + {file = "platformdirs-4.3.6-py3-none-any.whl", hash = "sha256:73e575e1408ab8103900836b97580d5307456908a03e92031bab39e4554cc3fb"}, + {file = "platformdirs-4.3.6.tar.gz", hash = "sha256:357fb2acbc885b0419afd3ce3ed34564c13c9b95c89360cd9563f73aa5e2b907"}, +] + +[package.extras] +docs = ["furo (>=2024.8.6)", "proselint (>=0.14)", "sphinx (>=8.0.2)", "sphinx-autodoc-typehints (>=2.4)"] +test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=8.3.2)", "pytest-cov (>=5)", "pytest-mock (>=3.14)"] +type = ["mypy (>=1.11.2)"] + [[package]] name = "pluggy" version = "1.5.0" @@ -716,22 +789,22 @@ testing = ["pytest", "pytest-benchmark"] [[package]] name = "protobuf" -version = "5.27.2" +version = "5.28.1" description = "" optional = false python-versions = ">=3.8" files = [ - {file = "protobuf-5.27.2-cp310-abi3-win32.whl", hash = "sha256:354d84fac2b0d76062e9b3221f4abbbacdfd2a4d8af36bab0474f3a0bb30ab38"}, - {file = "protobuf-5.27.2-cp310-abi3-win_amd64.whl", hash = "sha256:0e341109c609749d501986b835f667c6e1e24531096cff9d34ae411595e26505"}, - {file = "protobuf-5.27.2-cp38-abi3-macosx_10_9_universal2.whl", hash = "sha256:a109916aaac42bff84702fb5187f3edadbc7c97fc2c99c5ff81dd15dcce0d1e5"}, - {file = "protobuf-5.27.2-cp38-abi3-manylinux2014_aarch64.whl", hash = "sha256:176c12b1f1c880bf7a76d9f7c75822b6a2bc3db2d28baa4d300e8ce4cde7409b"}, - {file = "protobuf-5.27.2-cp38-abi3-manylinux2014_x86_64.whl", hash = "sha256:b848dbe1d57ed7c191dfc4ea64b8b004a3f9ece4bf4d0d80a367b76df20bf36e"}, - {file = "protobuf-5.27.2-cp38-cp38-win32.whl", hash = "sha256:4fadd8d83e1992eed0248bc50a4a6361dc31bcccc84388c54c86e530b7f58863"}, - {file = "protobuf-5.27.2-cp38-cp38-win_amd64.whl", hash = "sha256:610e700f02469c4a997e58e328cac6f305f649826853813177e6290416e846c6"}, - {file = "protobuf-5.27.2-cp39-cp39-win32.whl", hash = "sha256:9e8f199bf7f97bd7ecebffcae45ebf9527603549b2b562df0fbc6d4d688f14ca"}, - {file = "protobuf-5.27.2-cp39-cp39-win_amd64.whl", hash = "sha256:7fc3add9e6003e026da5fc9e59b131b8f22b428b991ccd53e2af8071687b4fce"}, - {file = "protobuf-5.27.2-py3-none-any.whl", hash = "sha256:54330f07e4949d09614707c48b06d1a22f8ffb5763c159efd5c0928326a91470"}, - {file = "protobuf-5.27.2.tar.gz", hash = "sha256:f3ecdef226b9af856075f28227ff2c90ce3a594d092c39bee5513573f25e2714"}, + {file = "protobuf-5.28.1-cp310-abi3-win32.whl", hash = "sha256:fc063acaf7a3d9ca13146fefb5b42ac94ab943ec6e978f543cd5637da2d57957"}, + {file = "protobuf-5.28.1-cp310-abi3-win_amd64.whl", hash = "sha256:4c7f5cb38c640919791c9f74ea80c5b82314c69a8409ea36f2599617d03989af"}, + {file = "protobuf-5.28.1-cp38-abi3-macosx_10_9_universal2.whl", hash = "sha256:4304e4fceb823d91699e924a1fdf95cde0e066f3b1c28edb665bda762ecde10f"}, + {file = "protobuf-5.28.1-cp38-abi3-manylinux2014_aarch64.whl", hash = "sha256:0dfd86d2b5edf03d91ec2a7c15b4e950258150f14f9af5f51c17fa224ee1931f"}, + {file = "protobuf-5.28.1-cp38-abi3-manylinux2014_x86_64.whl", hash = "sha256:51f09caab818707ab91cf09cc5c156026599cf05a4520779ccbf53c1b352fb25"}, + {file = "protobuf-5.28.1-cp38-cp38-win32.whl", hash = "sha256:1b04bde117a10ff9d906841a89ec326686c48ececeb65690f15b8cabe7149495"}, + {file = "protobuf-5.28.1-cp38-cp38-win_amd64.whl", hash = "sha256:cabfe43044ee319ad6832b2fda332646f9ef1636b0130186a3ae0a52fc264bb4"}, + {file = "protobuf-5.28.1-cp39-cp39-win32.whl", hash = "sha256:4b4b9a0562a35773ff47a3df823177ab71a1f5eb1ff56d8f842b7432ecfd7fd2"}, + {file = "protobuf-5.28.1-cp39-cp39-win_amd64.whl", hash = "sha256:f24e5d70e6af8ee9672ff605d5503491635f63d5db2fffb6472be78ba62efd8f"}, + {file = "protobuf-5.28.1-py3-none-any.whl", hash = "sha256:c529535e5c0effcf417682563719e5d8ac8d2b93de07a56108b4c2d436d7a29a"}, + {file = "protobuf-5.28.1.tar.gz", hash = "sha256:42597e938f83bb7f3e4b35f03aa45208d49ae8d5bcb4bc10b9fc825e0ab5e423"}, ] [[package]] @@ -748,6 +821,52 @@ files = [ [package.extras] windows-terminal = ["colorama (>=0.4.6)"] +[[package]] +name = "pylint" +version = "3.2.7" +description = "python code static checker" +optional = false +python-versions = ">=3.8.0" +files = [ + {file = "pylint-3.2.7-py3-none-any.whl", hash = "sha256:02f4aedeac91be69fb3b4bea997ce580a4ac68ce58b89eaefeaf06749df73f4b"}, + {file = "pylint-3.2.7.tar.gz", hash = "sha256:1b7a721b575eaeaa7d39db076b6e7743c993ea44f57979127c517c6c572c803e"}, +] + +[package.dependencies] +astroid = ">=3.2.4,<=3.3.0-dev0" +colorama = {version = ">=0.4.5", markers = "sys_platform == \"win32\""} +dill = [ + {version = ">=0.2", markers = "python_version < \"3.11\""}, + {version = ">=0.3.7", markers = "python_version >= \"3.12\""}, + {version = ">=0.3.6", markers = "python_version >= \"3.11\" and python_version < \"3.12\""}, +] +isort = ">=4.2.5,<5.13.0 || >5.13.0,<6" +mccabe = ">=0.6,<0.8" +platformdirs = ">=2.2.0" +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} +tomlkit = ">=0.10.1" +typing-extensions = {version = ">=3.10.0", markers = "python_version < \"3.10\""} + +[package.extras] +spelling = ["pyenchant (>=3.2,<4.0)"] +testutils = ["gitpython (>3)"] + +[[package]] +name = "pylint-protobuf" +version = "0.22.0" +description = "A plugin for making Pylint aware of the fields of protobuf-generated classes" +optional = false +python-versions = "*" +files = [ + {file = "pylint-protobuf-0.22.0.tar.gz", hash = "sha256:fd569200698cf30cb85f13cc5cfff40c49285599bc972b455e932c1805216a11"}, + {file = "pylint_protobuf-0.22.0-py2.py3-none-any.whl", hash = "sha256:d6c5823ca55fb0141b862569aff18e9abc287409a105a9061c1327d425999f09"}, +] + +[package.dependencies] +astroid = "*" +protobuf = "*" +pylint = "*" + [[package]] name = "pytest" version = "8.3.3" @@ -884,45 +1003,45 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "ruff" -version = "0.6.4" +version = "0.6.5" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.6.4-py3-none-linux_armv6l.whl", hash = "sha256:c4b153fc152af51855458e79e835fb6b933032921756cec9af7d0ba2aa01a258"}, - {file = "ruff-0.6.4-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:bedff9e4f004dad5f7f76a9d39c4ca98af526c9b1695068198b3bda8c085ef60"}, - {file = "ruff-0.6.4-py3-none-macosx_11_0_arm64.whl", hash = "sha256:d02a4127a86de23002e694d7ff19f905c51e338c72d8e09b56bfb60e1681724f"}, - {file = "ruff-0.6.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7862f42fc1a4aca1ea3ffe8a11f67819d183a5693b228f0bb3a531f5e40336fc"}, - {file = "ruff-0.6.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:eebe4ff1967c838a1a9618a5a59a3b0a00406f8d7eefee97c70411fefc353617"}, - {file = "ruff-0.6.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:932063a03bac394866683e15710c25b8690ccdca1cf192b9a98260332ca93408"}, - {file = "ruff-0.6.4-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:50e30b437cebef547bd5c3edf9ce81343e5dd7c737cb36ccb4fe83573f3d392e"}, - {file = "ruff-0.6.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c44536df7b93a587de690e124b89bd47306fddd59398a0fb12afd6133c7b3818"}, - {file = "ruff-0.6.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:0ea086601b22dc5e7693a78f3fcfc460cceabfdf3bdc36dc898792aba48fbad6"}, - {file = "ruff-0.6.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0b52387d3289ccd227b62102c24714ed75fbba0b16ecc69a923a37e3b5e0aaaa"}, - {file = "ruff-0.6.4-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:0308610470fcc82969082fc83c76c0d362f562e2f0cdab0586516f03a4e06ec6"}, - {file = "ruff-0.6.4-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:803b96dea21795a6c9d5bfa9e96127cc9c31a1987802ca68f35e5c95aed3fc0d"}, - {file = "ruff-0.6.4-py3-none-musllinux_1_2_i686.whl", hash = "sha256:66dbfea86b663baab8fcae56c59f190caba9398df1488164e2df53e216248baa"}, - {file = "ruff-0.6.4-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:34d5efad480193c046c86608dbba2bccdc1c5fd11950fb271f8086e0c763a5d1"}, - {file = "ruff-0.6.4-py3-none-win32.whl", hash = "sha256:f0f8968feea5ce3777c0d8365653d5e91c40c31a81d95824ba61d871a11b8523"}, - {file = "ruff-0.6.4-py3-none-win_amd64.whl", hash = "sha256:549daccee5227282289390b0222d0fbee0275d1db6d514550d65420053021a58"}, - {file = "ruff-0.6.4-py3-none-win_arm64.whl", hash = "sha256:ac4b75e898ed189b3708c9ab3fc70b79a433219e1e87193b4f2b77251d058d14"}, - {file = "ruff-0.6.4.tar.gz", hash = "sha256:ac3b5bfbee99973f80aa1b7cbd1c9cbce200883bdd067300c22a6cc1c7fba212"}, + {file = "ruff-0.6.5-py3-none-linux_armv6l.whl", hash = "sha256:7e4e308f16e07c95fc7753fc1aaac690a323b2bb9f4ec5e844a97bb7fbebd748"}, + {file = "ruff-0.6.5-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:932cd69eefe4daf8c7d92bd6689f7e8182571cb934ea720af218929da7bd7d69"}, + {file = "ruff-0.6.5-py3-none-macosx_11_0_arm64.whl", hash = "sha256:3a8d42d11fff8d3143ff4da41742a98f8f233bf8890e9fe23077826818f8d680"}, + {file = "ruff-0.6.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a50af6e828ee692fb10ff2dfe53f05caecf077f4210fae9677e06a808275754f"}, + {file = "ruff-0.6.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:794ada3400a0d0b89e3015f1a7e01f4c97320ac665b7bc3ade24b50b54cb2972"}, + {file = "ruff-0.6.5-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:381413ec47f71ce1d1c614f7779d88886f406f1fd53d289c77e4e533dc6ea200"}, + {file = "ruff-0.6.5-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:52e75a82bbc9b42e63c08d22ad0ac525117e72aee9729a069d7c4f235fc4d276"}, + {file = "ruff-0.6.5-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:09c72a833fd3551135ceddcba5ebdb68ff89225d30758027280968c9acdc7810"}, + {file = "ruff-0.6.5-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:800c50371bdcb99b3c1551d5691e14d16d6f07063a518770254227f7f6e8c178"}, + {file = "ruff-0.6.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8e25ddd9cd63ba1f3bd51c1f09903904a6adf8429df34f17d728a8fa11174253"}, + {file = "ruff-0.6.5-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:7291e64d7129f24d1b0c947ec3ec4c0076e958d1475c61202497c6aced35dd19"}, + {file = "ruff-0.6.5-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:9ad7dfbd138d09d9a7e6931e6a7e797651ce29becd688be8a0d4d5f8177b4b0c"}, + {file = "ruff-0.6.5-py3-none-musllinux_1_2_i686.whl", hash = "sha256:005256d977021790cc52aa23d78f06bb5090dc0bfbd42de46d49c201533982ae"}, + {file = "ruff-0.6.5-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:482c1e6bfeb615eafc5899127b805d28e387bd87db38b2c0c41d271f5e58d8cc"}, + {file = "ruff-0.6.5-py3-none-win32.whl", hash = "sha256:cf4d3fa53644137f6a4a27a2b397381d16454a1566ae5335855c187fbf67e4f5"}, + {file = "ruff-0.6.5-py3-none-win_amd64.whl", hash = "sha256:3e42a57b58e3612051a636bc1ac4e6b838679530235520e8f095f7c44f706ff9"}, + {file = "ruff-0.6.5-py3-none-win_arm64.whl", hash = "sha256:51935067740773afdf97493ba9b8231279e9beef0f2a8079188c4776c25688e0"}, + {file = "ruff-0.6.5.tar.gz", hash = "sha256:4d32d87fab433c0cf285c3683dd4dae63be05fd7a1d65b3f5bf7cdd05a6b96fb"}, ] [[package]] name = "setuptools" -version = "74.1.2" +version = "75.1.0" description = "Easily download, build, install, upgrade, and uninstall Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "setuptools-74.1.2-py3-none-any.whl", hash = "sha256:5f4c08aa4d3ebcb57a50c33b1b07e94315d7fc7230f7115e47fc99776c8ce308"}, - {file = "setuptools-74.1.2.tar.gz", hash = "sha256:95b40ed940a1c67eb70fc099094bd6e99c6ee7c23aa2306f4d2697ba7916f9c6"}, + {file = "setuptools-75.1.0-py3-none-any.whl", hash = "sha256:35ab7fd3bcd95e6b7fd704e4a1539513edad446c097797f2985e0e4b960772f2"}, + {file = "setuptools-75.1.0.tar.gz", hash = "sha256:d59a21b17a275fb872a9c3dae73963160ae079f1049ed956880cd7c09b120538"}, ] [package.extras] check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1)", "ruff (>=0.5.2)"] -core = ["importlib-metadata (>=6)", "importlib-resources (>=5.10.2)", "jaraco.text (>=3.7)", "more-itertools (>=8.8)", "packaging (>=24)", "platformdirs (>=2.6.2)", "tomli (>=2.0.1)", "wheel (>=0.43.0)"] +core = ["importlib-metadata (>=6)", "importlib-resources (>=5.10.2)", "jaraco.collections", "jaraco.functools", "jaraco.text (>=3.7)", "more-itertools", "more-itertools (>=8.8)", "packaging", "packaging (>=24)", "platformdirs (>=2.6.2)", "tomli (>=2.0.1)", "wheel (>=0.43.0)"] cover = ["pytest-cov"] doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "pyproject-hooks (!=1.1)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier", "towncrier (<24.7)"] enabler = ["pytest-enabler (>=2.2)"] @@ -951,6 +1070,17 @@ files = [ {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] +[[package]] +name = "tomlkit" +version = "0.13.2" +description = "Style preserving TOML library" +optional = false +python-versions = ">=3.8" +files = [ + {file = "tomlkit-0.13.2-py3-none-any.whl", hash = "sha256:7a974427f6e119197f670fbbbeae7bef749a6c14e793db934baefc1b5f03efde"}, + {file = "tomlkit-0.13.2.tar.gz", hash = "sha256:fff5fe59a87295b278abd31bec92c15d9bc4a06885ab12bcea52c71119392e79"}, +] + [[package]] name = "types-protobuf" version = "5.27.0.20240907" @@ -990,13 +1120,13 @@ typing-extensions = ">=3.7.4" [[package]] name = "urllib3" -version = "2.2.2" +version = "2.2.3" description = "HTTP library with thread-safe connection pooling, file post, and more." optional = false python-versions = ">=3.8" files = [ - {file = "urllib3-2.2.2-py3-none-any.whl", hash = "sha256:a448b2f64d686155468037e1ace9f2d2199776e17f0a46610480d311f73e3472"}, - {file = "urllib3-2.2.2.tar.gz", hash = "sha256:dd505485549a7a552833da5e6063639d0d177c04f23bc3864e41e5dc5f612168"}, + {file = "urllib3-2.2.3-py3-none-any.whl", hash = "sha256:ca899ca043dcb1bafa3e262d73aa25c465bfb49e0bd9dd5d59f1d0acba2f8fac"}, + {file = "urllib3-2.2.3.tar.gz", hash = "sha256:e7d814a81dad81e6caf2ec9fdedb284ecc9c73076b62654547cc64ccdcae26e9"}, ] [package.extras] @@ -1022,4 +1152,4 @@ test = ["pytest (>=6.0.0)", "setuptools (>=65)"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "329385d0c51c97a6e7b954a489154ef7e63783f6395fdd53c0acf68ad41f9530" +content-hash = "33538fcfd93fb347080cf778fc264d28bd55bf6b57d5872bb76e30608956beb1" diff --git a/python/remotivelabs-broker/poetry.toml b/python/remotivelabs-broker/poetry.toml new file mode 100644 index 0000000..24a1ce5 --- /dev/null +++ b/python/remotivelabs-broker/poetry.toml @@ -0,0 +1,2 @@ +virtualenvs.in-project = true +virtualenvs.prefer-active-python = true diff --git a/python/remotivelabs-broker/pyproject.toml b/python/remotivelabs-broker/pyproject.toml index 8013896..e85465a 100644 --- a/python/remotivelabs-broker/pyproject.toml +++ b/python/remotivelabs-broker/pyproject.toml @@ -8,7 +8,6 @@ homepage = "https://remotivelabs.com/" repository = "https://github.com/remotivelabs/remotivelabs-apis" documentation = "https://docs.remotivelabs.com/apis/python/remotivelabs/broker" authors = ["Support "] -packages = [{ include = "remotivelabs" }] keywords = ["automotive", "autotech", "networking", "CAN"] classifiers = [ "Development Status :: 4 - Beta", @@ -25,6 +24,7 @@ classifiers = [ "Topic :: Internet", "Topic :: Scientific/Engineering :: Information Analysis", ] +packages = [{ include = "remotivelabs" }] [tool.poetry.urls] Issues = "https://github.com/remotivelabs/remotivelabs-apis/issues" @@ -38,35 +38,80 @@ grpc-interceptor = "^0.15" [tool.poetry.group.dev.dependencies] grpcio-tools = "^1.66" grpc-stubs = "^1.53" -ruff = "^0.6" -mypy = "^1.11" types-protobuf = "^5.27" [tool.poetry.group.test.dependencies] pytest = "^8.3" pytest-cov = "^5.0" +[tool.poetry.group.lint.dependencies] +ruff = "^0.6" +pylint = "^3.2.7" +pylint-protobuf = "^0.22.0" +mypy = "^1.11" + [tool.poetry.group.docs.dependencies] pdoc = "^12.2" json-schema-for-humans = "^1.0" [tool.poe.tasks] -test-server = "pytest -m server --cov=remotivelabs.broker" test = "pytest --cov=remotivelabs.broker" -format = [{ cmd = "ruff check --fix ." }, { cmd = "ruff format ." }] +test-server = "pytest -m server --cov=remotivelabs.broker" +pylint = [{ cmd = "pylint ." }] lint = [{ cmd = "ruff check ." }, { cmd = "ruff format --check --diff ." }] -mypy-check = [{ cmd = "mypy -p remotivelabs.broker -p misc -p tests" }] -check = ["test", "lint", "mypy-check"] +format = [{ cmd = "ruff format ." }, { cmd = "ruff check --fix ." }] +mypy = [{ cmd = "mypy -p remotivelabs.broker -p misc -p tests" }] +check = ["test", "lint", "pylint", "mypy"] + +[tool.pytest.ini_options] +addopts = "-v -m 'not server'" +markers = [ + "server: marks tests that require a live server (deselect with '-m \"not server\"')", +] [tool.ruff] line-length = 140 -src = ["remotivelabs", "tests"] + +[tool.ruff.lint] +select = [ + "ARG", + "B034", + "C901", + "E", + "EXE", + "F", + "FA", + "I", + "N", + "UP032", + "RET", + "W", +] + +[tool.pylint] +recursive = true +load-plugins = ["pylint_protobuf"] +ignore-paths = ['^.venv/.*$', '^remotivelabs/broker/sync.*$'] + +[tool.pylint.format] +max-line-length = 140 +max-module-lines = 1000 + +[tool.pylint.messages_control] +disable = [ + 'wrong-import-order', + 'missing-module-docstring', + 'missing-class-docstring', + 'missing-function-docstring', + 'duplicate-code', + 'logging-fstring-interpolation', +] [tool.mypy] python_version = "3.8" -mypy_path = "." namespace_packages = true explicit_package_bases = true +mypy_path = "." packages = ["remotivelabs.broker", "misc", "tests"] [[tool.mypy.overrides]] @@ -74,15 +119,6 @@ packages = ["remotivelabs.broker", "misc", "tests"] module = "remotivelabs.broker.generated.sync.diagnostics_api_pb2" disable_error_code = ["valid-type"] -[tool.pyright] -include = ["remotivelabs"] - -[tool.pytest.ini_options] -addopts = "-v -m 'not server'" -markers = [ - "server: marks tests that require a live server (deselect with '-m \"not server\"')", -] - [build-system] -requires = ["poetry-core>=1.6"] +requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" diff --git a/python/remotivelabs-broker/remotivelabs/broker/sync/client.py b/python/remotivelabs-broker/remotivelabs/broker/sync/client.py index e621651..14e0252 100644 --- a/python/remotivelabs-broker/remotivelabs/broker/sync/client.py +++ b/python/remotivelabs-broker/remotivelabs/broker/sync/client.py @@ -135,7 +135,7 @@ def parse(signal_id: str) -> SignalIdentifier: return SignalIdentifier(s[1], s[0]) -class BrokerException(Exception): +class BrokerException(Exception): # noqa: N818 pass diff --git a/python/remotivelabs-broker/remotivelabs/broker/sync/helper.py b/python/remotivelabs-broker/remotivelabs/broker/sync/helper.py index b20e07a..53719c6 100644 --- a/python/remotivelabs-broker/remotivelabs/broker/sync/helper.py +++ b/python/remotivelabs-broker/remotivelabs/broker/sync/helper.py @@ -125,11 +125,9 @@ def get_sha256(path: str) -> str: :param path: Path to file :rtype int: """ - with open(path, "rb") as f: b = f.read() # read entire file as bytes - readable_hash = hashlib.sha256(b).hexdigest() - return readable_hash + return hashlib.sha256(b).hexdigest() def generate_data(file, dest_path, chunk_size, sha256) -> Generator[system_api_pb2.FileUploadRequest, None, None]: diff --git a/python/remotivelabs-broker/remotivelabs/broker/sync/signalcreator.py b/python/remotivelabs-broker/remotivelabs/broker/sync/signalcreator.py index de63f62..2dec561 100644 --- a/python/remotivelabs-broker/remotivelabs/broker/sync/signalcreator.py +++ b/python/remotivelabs-broker/remotivelabs/broker/sync/signalcreator.py @@ -16,7 +16,7 @@ class MetaGetter: def __init__(self, proto_message): self.meta = proto_message - def _getDefault(self, field: T, default: Optional[T]) -> T: + def _getDefault(self, field: T, default: Optional[T]) -> T: # noqa: N802 if field is not None: return field @@ -25,51 +25,51 @@ def _getDefault(self, field: T, default: Optional[T]) -> T: raise Exception("Failed to retrieve meta data field") - def getDescription(self, default: Optional[str] = None) -> str: + def getDescription(self, default: Optional[str] = None) -> str: # noqa: N802 """Get protobuffer MetaData field description""" return self._getDefault(self.meta.description, default) - def getUnit(self, default: Optional[str] = None) -> str: + def getUnit(self, default: Optional[str] = None) -> str: # noqa: N802 """Get protobuffer MetaData field unit""" return self._getDefault(self.meta.unit, default) - def getMax(self, default: Optional[float] = None) -> float: + def getMax(self, default: Optional[float] = None) -> float: # noqa: N802 """Get protobuffer MetaData field max""" return self._getDefault(self.meta.max, default) - def getMin(self, default: Optional[float] = None) -> float: + def getMin(self, default: Optional[float] = None) -> float: # noqa: N802 """Get protobuffer MetaData field min""" return self._getDefault(self.meta.min, default) - def getSize(self, default: Optional[int] = None) -> int: + def getSize(self, default: Optional[int] = None) -> int: # noqa: N802 """Get protobuffer MetaData field size""" return self._getDefault(self.meta.size, default) - def getIsRaw(self, default: Optional[bool] = None) -> bool: + def getIsRaw(self, default: Optional[bool] = None) -> bool: # noqa: N802 """Get protobuffer MetaData field isRaw""" return self._getDefault(self.meta.isRaw, default) - def getFactor(self, default: Optional[float] = None) -> float: + def getFactor(self, default: Optional[float] = None) -> float: # noqa: N802 """Get protobuffer MetaData field factor""" return self._getDefault(self.meta.factor, default) - def getOffset(self, default: Optional[float] = None) -> float: + def getOffset(self, default: Optional[float] = None) -> float: # noqa: N802 """Get protobuffer MetaData field offset""" return self._getDefault(self.meta.offset, default) - def getSenders(self, default: Optional[Sequence[str]] = None) -> Sequence[str]: + def getSenders(self, default: Optional[Sequence[str]] = None) -> Sequence[str]: # noqa: N802 """Get protobuffer MetaData field sender""" return self._getDefault(self.meta.sender, default) - def getReceivers(self, default: Optional[Sequence[str]] = None) -> Sequence[str]: + def getReceivers(self, default: Optional[Sequence[str]] = None) -> Sequence[str]: # noqa: N802 """Get protobuffer MetaData field receiver""" return self._getDefault(self.meta.receiver, default) - def getCycleTime(self, default: Optional[float] = None) -> float: + def getCycleTime(self, default: Optional[float] = None) -> float: # noqa: N802 """Get protobuffer MetaData field cycleTime""" return self._getDefault(self.meta.cycleTime, default) - def getStartValue(self, default: Optional[float] = None) -> float: + def getStartValue(self, default: Optional[float] = None) -> float: # noqa: N802 """Get protobuffer MetaData field startValue""" return self._getDefault(self.meta.startValue, default) diff --git a/python/remotivelabs-broker/tests/system/test_smoke_system.py b/python/remotivelabs-broker/tests/system/test_smoke_system.py index 510610c..b8e1278 100644 --- a/python/remotivelabs-broker/tests/system/test_smoke_system.py +++ b/python/remotivelabs-broker/tests/system/test_smoke_system.py @@ -8,7 +8,7 @@ import remotivelabs.broker.sync as br_sync -class Connection: +class Connection: # pylint: disable=too-few-public-methods def __init__(self, url: str, api_key: str | None = None): self.channel = br_sync.create_channel(url, api_key) self.system_stub = br.system_api_pb2_grpc.SystemServiceStub(self.channel) @@ -83,6 +83,6 @@ def test_min_max(broker_configured, caplog): @pytest.mark.server def test_list_signals(broker_configured): - namespace = br.common_pb2.NameSpace(name="ecu_A") + namespace = br.common_pb2.NameSpace(name="ecu_A") # pylint: disable=no-member signals = broker_configured.system_stub.ListSignals(namespace) assert len(signals.frame) == 5 diff --git a/python/remotivelabs-broker/tests/unit/test_proto_types.py b/python/remotivelabs-broker/tests/unit/test_proto_types.py index 6a00bc3..2d88661 100644 --- a/python/remotivelabs-broker/tests/unit/test_proto_types.py +++ b/python/remotivelabs-broker/tests/unit/test_proto_types.py @@ -3,4 +3,4 @@ def test_create_empty_message(): """Make sure we can instantiate a basic type""" - _ = br.common_pb2.Empty + _ = br.common_pb2.Empty # pylint: disable=no-member