Skip to content

Commit

Permalink
feat(usb-bridge): add usb-bridge project (#11468)
Browse files Browse the repository at this point in the history
* Addeed the shell of the usb-bridge project
* Added github workflow for testing and linting usb-bridge
* Added simple CLI module with option to set log level
* Added pytest.ini to trigger coverage generation
  • Loading branch information
fsinapi authored Sep 16, 2022
1 parent 129ffa8 commit 6871b3e
Show file tree
Hide file tree
Showing 19 changed files with 1,168 additions and 1 deletion.
78 changes: 78 additions & 0 deletions .github/workflows/usb-bridge-lint-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# This workflow runs tests and lint on non-release branches pushed that alter
# the usb-bridge subpackage

name: 'USB-Bridge test/lint'

on:
push:
paths:
- 'usb-bridge/**/*'
- 'Makefile'
- 'scripts/**/*.mk'
- 'scripts/**/*.py'
- '.github/workflows/usb-bridge-lint-test.yaml'
- '.github/actions/python/**'
branches: # ignore any release-related thing (handled elsewhere)
- 'edge'
tags-ignore:
- '*'
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
paths:
- 'usb-bridge/**/*'
- 'Makefile'
- 'scripts/**/*.mk'
- 'scripts/**/*.py'
- '.github/workflows/usb-bridge-lint-test.yaml'
- '.github/actions/python/**'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ github.ref_name != 'edge' || github.run_id}}-${{ github.ref_type != 'tag' || github.run_id }}
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
lint:
name: 'usb-bridge linting'
timeout-minutes: 10
runs-on: 'ubuntu-22.04'
steps:
- uses: 'actions/checkout@v3'
- uses: 'actions/setup-node@v3'
with:
node-version: '14'
- uses: 'actions/setup-python@v4'
with:
python-version: '3.7'

- uses: './.github/actions/python/setup'
with:
project: 'usb-bridge'
- name: Lint
run: make -C usb-bridge lint
test:
name: 'usb-bridge package tests'
timeout-minutes: 10
needs: [lint]
runs-on: 'ubuntu-22.04'
steps:
- uses: 'actions/checkout@v3'
- uses: 'actions/setup-node@v3'
with:
node-version: '14'
- uses: 'actions/setup-python@v4'
with:
python-version: '3.7'
- uses: './.github/actions/python/setup'
with:
project: 'usb-bridge'
- name: Test
run: make -C usb-bridge test
- uses: 'codecov/codecov-action@v3'
with:
files: ./usb-bridge/coverage.xml
flags: usb-bridge
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ SHARED_DATA_DIR := shared-data
UPDATE_SERVER_DIR := update-server
ROBOT_SERVER_DIR := robot-server
HARDWARE_DIR := hardware
USB_BRIDGE_DIR := usb-bridge

PYTHON_DIRS := $(API_DIR) $(UPDATE_SERVER_DIR) $(NOTIFY_SERVER_DIR) $(ROBOT_SERVER_DIR) $(SHARED_DATA_DIR)/python $(G_CODE_TESTING_DIR) $(HARDWARE_DIR)
PYTHON_DIRS := $(API_DIR) $(UPDATE_SERVER_DIR) $(NOTIFY_SERVER_DIR) $(ROBOT_SERVER_DIR) $(SHARED_DATA_DIR)/python $(G_CODE_TESTING_DIR) $(HARDWARE_DIR) $(USB_BRIDGE_DIR)

# This may be set as an environment variable (and is by CI tasks that upload
# to test pypi) to add a .dev extension to the python package versions. If
Expand Down
4 changes: 4 additions & 0 deletions usb-bridge/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[report]
exclude_lines =
@overload
if TYPE_CHECKING:
22 changes: 22 additions & 0 deletions usb-bridge/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[flake8]

# max cyclomatic complexity
max-complexity = 9

extend-ignore =
# defer formatting concerns to black
# E203: space around `:` operator
# E501: maximum line length
E203,
E501,
# do not require type annotations for self nor cls
ANN101,
ANN102
# do not require docstring for __init__, put them on the class
D107,

# configure flake8-docstrings
# https://pypi.org/project/flake8-docstrings/
docstring-convention = google

noqa-require-code = true
5 changes: 5 additions & 0 deletions usb-bridge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This is generated by setuptools
pyproject.toml

# This is generated by sdist
LICENSE
70 changes: 70 additions & 0 deletions usb-bridge/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# makefile for usb-tcp bridge for OT-3

include ../scripts/push.mk
include ../scripts/python.mk

# using bash instead of /bin/bash in SHELL prevents macOS optimizing away our PATH update
SHELL := bash

PATH := $(shell cd .. && yarn bin):$(PATH)
SHX := npx shx

# add yarn CLI dev deps to PATH (for cross platform POSIX commands via shx)
PATH := $(shell cd .. && yarn bin):$(PATH)

# These variables can be overriden when make is invoked to customize the
# behavior of pytest. For instance,
# make test tests=tests/ot3usb/abcd.py would run only the
# specified test
tests ?= tests
test_opts ?=
sdist_file = $(call python_get_sdistname,ot3usb)
# Host key location for buildroot robot
br_ssh_key ?= $(default_ssh_key)
# Other SSH args for buildroot robots
br_ssh_opts ?= $(default_ssh_opts)

.PHONY: setup
setup:
$(pipenv) sync $(pipenv_opts)
$(pipenv) run pip freeze

.PHONY: clean
clean:
$(SHX) rm -rf \
build \
dist \
.coverage \
coverage.xml \
'*.egg-info' \
'**/__pycache__' \
'**/*.pyc'

.PHONY: teardown
teardown:
$(pipenv) --rm

.PHONY: test
test:
$(python) -m pytest $(test_opts) $(tests)

.PHONY: lint
lint:
$(python) -m mypy ot3usb tests
$(python) -m black --check ./ot3usb ./tests
$(python) -m flake8 ot3usb tests

.PHONY: format
format:
$(python) -m black ot3usb tests

.PHONY: sdist
sdist: clean
$(python) setup.py sdist
$(SHX) rm -rf build
$(SHX) ls dist

.PHONY: push-ot3
push-ot3: sdist
$(call push-python-sdist,$(host),,$(br_ssh_opts),dist/$(sdist_file),/opt/ot3usb,ot3usb)
# todo (fs, 2022-09-15): add a restart when appropriate
31 changes: 31 additions & 0 deletions usb-bridge/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
typing-extensions = "==3.10.0.0"
pyserial = "==3.5"

[dev-packages]
ot3usb = {path = ".", editable = true}
flake8 = "~=3.9.0"
flake8-annotations = "~=2.6.2"
flake8-docstrings = "~=1.6.0"
flake8-noqa = "~=1.1.0"
pytest = "==6.1.0"
pytest-watch = "~=4.2.0"
pytest-cov = "==2.10.1"
pytest-aiohttp = "==0.3.0"
coverage = "==5.1"
# atomicwrites and colorama are pytest dependencies on windows,
# spec'd here to force lockfile inclusion
# https://github.com/pypa/pipenv/issues/4408#issuecomment-668324177
atomicwrites = {version="==1.4.0", sys_platform="== 'win32'"}
colorama = {version="==0.4.4", sys_platform="== 'win32'"}
mypy = "==0.940"
black = "==22.3.0"
decoy = "~=1.10"

[requires]
python_version = "3.7"
Loading

0 comments on commit 6871b3e

Please sign in to comment.