Skip to content

Commit 0a1851b

Browse files
authored
style(api,robot-server): start using black to format some modules (#8158)
1 parent 3185656 commit 0a1851b

File tree

23 files changed

+287
-113
lines changed

23 files changed

+287
-113
lines changed

.github/workflows/js-check.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,3 @@ jobs:
7474
run: make lint-json
7575
- name: 'lint css'
7676
run: make lint-css
77-
- name: 'stylecheck js'
78-
run: make format

Makefile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,6 @@ test-js:
179179
.PHONY: lint
180180
lint: lint-py lint-js lint-json lint-css check-js circular-dependencies-js
181181

182-
.PHONY: format
183-
format:
184-
ifeq ($(watch),true)
185-
onchange $(FORMAT_FILE_GLOB) -- prettier --ignore-path .eslintignore --write {{changed}}
186-
else
187-
prettier --ignore-path .eslintignore --write $(FORMAT_FILE_GLOB)
188-
endif
189-
190182
.PHONY: lint-py
191183
lint-py:
192184
$(MAKE) -C $(API_DIR) lint
@@ -208,6 +200,18 @@ lint-json:
208200
lint-css:
209201
stylelint "**/*.css" "**/*.js"
210202

203+
.PHONY: format
204+
format: format-js format-py
205+
206+
.PHONY: format-py
207+
format-py:
208+
$(MAKE) -C $(API_DIR) format
209+
$(MAKE) -C $(ROBOT_SERVER_DIR) format
210+
211+
.PHONY: format-js
212+
format-js:
213+
prettier --ignore-path .eslintignore --write $(FORMAT_FILE_GLOB)
214+
211215
.PHONY: check-js
212216
check-js: build-ts
213217

api/Makefile

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
include ../scripts/push.mk
44
include ../scripts/python.mk
55

6-
# using bash instead of /bin/bash in SHELL prevents macOS optimizing away our PATH update
7-
SHELL := bash
8-
9-
# add yarn CLI dev deps to PATH (for cross platform POSIX commands via shx)
10-
# and also make an explicit version for shx for use in the shell function,
11-
# where PATH won’t be propagated
12-
PATH := $(shell cd .. && yarn bin):$(PATH)
136
SHX := npx shx
147

158
# make push wheel file (= rather than := to expand at every use)
@@ -57,13 +50,27 @@ ot_shared_data_sources := $(filter %.json,$(shell $(SHX) find ../shared-data/))
5750
ot_resources := $(filter %,$(shell $(SHX) find src/opentrons/resources))
5851
ot_sources := $(ot_py_sources) $(ot_shared_data_sources) $(ot_resources)
5952

53+
# test modules to typecheck
54+
# TODO(mc, 2021-07-23): expand this to all tests
6055
ot_tests_to_typecheck := \
6156
tests/opentrons/protocol_api_experimental \
6257
tests/opentrons/protocol_engine \
6358
tests/opentrons/motion_planning \
6459
tests/opentrons/file_runner \
6560
tests/opentrons/protocols/runner
6661

62+
# files and modules to format
63+
# TODO(mc, 2021-07-23): expand this to all files until we can format `.`
64+
ot_files_to_format := \
65+
src/opentrons/file_runner \
66+
src/opentrons/motion_planning \
67+
src/opentrons/protocol_api_experimental \
68+
src/opentrons/protocol_engine \
69+
tests/opentrons/file_runner \
70+
tests/opentrons/motion_planning \
71+
tests/opentrons/protocol_api_experimental \
72+
tests/opentrons/protocol_engine
73+
6774
# Defined separately than the clean target so the wheel file doesn’t have to
6875
# depend on a PHONY target
6976
clean_cmd = $(SHX) rm -rf build dist .coverage coverage.xml '*.egg-info' '**/__pycache__' '**/*.pyc' 'src/**/.mypy_cache'
@@ -99,10 +106,15 @@ test:
99106
$(pytest) $(tests) $(test_opts)
100107

101108
.PHONY: lint
102-
lint: $(ot_py_sources)
109+
lint:
103110
$(python) -m mypy src/opentrons $(ot_tests_to_typecheck)
111+
$(python) -m black --check $(ot_files_to_format)
104112
$(python) -m flake8 setup.py src/opentrons tests
105113

114+
.PHONY: format
115+
format:
116+
$(python) -m black $(ot_files_to_format)
117+
106118
docs/build/html/v%: docs/v%
107119
$(sphinx_build) -b html -d docs/build/doctrees -n $< $@
108120
$(SHX) cp docs/img/lightbulb.jpg $@/_images/ # sphinx wont automatically do this because it's only in a template

api/Pipfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ flake8-annotations = "~=2.6.2"
3333
flake8-docstrings = "~=1.6.0"
3434
flake8-noqa = "~=1.1.0"
3535
diff-match-patch = "*"
36-
decoy = "~=1.6.2"
36+
decoy = "~=1.6.4"
37+
black = "==21.7b0"
3738

3839
[packages]
3940
aionotify = "==0.2.0"

api/Pipfile.lock

Lines changed: 89 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/src/opentrons/motion_planning/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
DEFAULT_GENERAL_ARC_Z_MARGIN,
55
DEFAULT_IN_LABWARE_ARC_Z_MARGIN,
66
MINIMUM_Z_MARGIN,
7-
get_waypoints
7+
get_waypoints,
88
)
99

1010
from .types import Waypoint, MoveType

api/src/opentrons/motion_planning/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(
1212
clearance: float,
1313
min_travel_z: float,
1414
max_travel_z: float,
15-
message: str
15+
message: str,
1616
) -> None:
1717
"""Initialize an error with properties of the planned motion."""
1818
super().__init__(message)

api/src/opentrons/motion_planning/waypoints.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def get_waypoints(
6262
clearance=MINIMUM_Z_MARGIN,
6363
min_travel_z=min_travel_z,
6464
max_travel_z=max_travel_z,
65-
message="Destination out of bounds in the Z-axis"
65+
message="Destination out of bounds in the Z-axis",
6666
)
6767

6868
# ensure that the passed in min_travel_z and max_travel_z are compatible
@@ -73,7 +73,7 @@ def get_waypoints(
7373
clearance=MINIMUM_Z_MARGIN,
7474
min_travel_z=min_travel_z,
7575
max_travel_z=max_travel_z,
76-
message="Arc out of bounds in the Z-axis"
76+
message="Arc out of bounds in the Z-axis",
7777
)
7878

7979
# set the z clearance according to the arc type
@@ -88,10 +88,7 @@ def get_waypoints(
8888
# if any of those exceed max_travel_z, just use max_travel_z
8989
# if max_travel_z does not provide enough clearance, check above would
9090
# raise an ArcOutOfBoundsError
91-
travel_z = min(
92-
max_travel_z,
93-
max(min_travel_z + travel_z_margin, origin.z, dest.z)
94-
)
91+
travel_z = min(max_travel_z, max(min_travel_z + travel_z_margin, origin.z, dest.z))
9592

9693
# if origin.z isn't the travel height: add waypoint to move to origin.z
9794
if travel_z > origin.z:

api/src/opentrons/protocol_api_experimental/labware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def quirks(self) -> List[str]: # noqa: D102
108108
# operational logic, and its presence in this interface is no longer
109109
# necessary with Protocol Engine controlling execution. Can we get rid of it?
110110
@property
111-
def magdeck_engage_height(self) -> Optional[float]: # noqa: D102
111+
def magdeck_engage_height(self) -> Optional[float]: # noqa: D102
112112
definition = self._engine_client.state.labware.get_labware_definition(
113113
labware_id=self._labware_id
114114
)

api/src/opentrons/protocol_engine/resources/deck_data_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def get_deck_definition(
4545

4646
async def get_deck_fixed_labware(
4747
self,
48-
deck_definition: DeckDefinitionV2
48+
deck_definition: DeckDefinitionV2,
4949
) -> List[DeckFixedLabware]:
5050
"""Get a list of all labware fixtures from a given deck definition."""
5151
labware = []

0 commit comments

Comments
 (0)