Skip to content

Commit

Permalink
style(python): remove line length limit from flake8 config
Browse files Browse the repository at this point in the history
Closes #9931
  • Loading branch information
mcous committed Jun 9, 2022
1 parent 93249af commit d12d651
Show file tree
Hide file tree
Showing 126 changed files with 277 additions and 276 deletions.
9 changes: 4 additions & 5 deletions api/.flake8
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
[flake8]

# set line-length for future black support
# https://github.com/psf/black/blob/master/docs/compatible_configs.md
max-line-length = 88

# max cyclomatic complexity
max-complexity = 9

extend-ignore =
# ignore E203 because black might reformat it
# 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
Expand Down
2 changes: 1 addition & 1 deletion api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def read(*parts):
},
project_urls={
"opentrons.com": "https://www.opentrons.com",
"Source Code On Github": "https://github.com/Opentrons/opentrons/tree/edge/api", # noqa: E501
"Source Code On Github": "https://github.com/Opentrons/opentrons/tree/edge/api",
"Documentation": "https://docs.opentrons.com",
},
)
8 changes: 4 additions & 4 deletions api/src/opentrons/calibration_storage/modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def create_tip_length_data(
status = cal_status
else:
status = local_types.CalibrationStatus()
status_dict: "CalibrationStatusDict" = helpers.convert_to_dict( # type: ignore[assignment] # noqa: E501
status_dict: "CalibrationStatusDict" = helpers.convert_to_dict( # type: ignore[assignment]
status
)

Expand Down Expand Up @@ -223,7 +223,7 @@ def save_robot_deck_attitude(
status = cal_status
else:
status = local_types.CalibrationStatus()
status_dict: "CalibrationStatusDict" = helpers.convert_to_dict( # type: ignore[assignment] # noqa: E501
status_dict: "CalibrationStatusDict" = helpers.convert_to_dict( # type: ignore[assignment]
status
)

Expand Down Expand Up @@ -268,7 +268,7 @@ def save_pipette_calibration(
status = cal_status
else:
status = local_types.CalibrationStatus()
status_dict: "CalibrationStatusDict" = helpers.convert_to_dict( # type: ignore[assignment] # noqa: E501
status_dict: "CalibrationStatusDict" = helpers.convert_to_dict( # type: ignore[assignment]
status
)
offset_path = pip_dir / f"{pip_id}.json"
Expand Down Expand Up @@ -296,7 +296,7 @@ def save_gripper_calibration(
status = cal_status
else:
status = local_types.CalibrationStatus()
status_dict: "CalibrationStatusDict" = helpers.convert_to_dict( # type: ignore[assignment] # noqa: E501
status_dict: "CalibrationStatusDict" = helpers.convert_to_dict( # type: ignore[assignment]
status
)

Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/drivers/smoothie_drivers/driver_3_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ def build_split(here: float, dest: float, split_distance: float) -> float:
# - we have a split configuration
and split
# - it's been long enough since the last time it moved
and ((since_moved[ax] is None) or (split.after_time < since_moved[ax])) # type: ignore[operator] # noqa: E501
and ((since_moved[ax] is None) or (split.after_time < since_moved[ax])) # type: ignore[operator]
}

split_command_string = create_coords_list(split_target)
Expand Down
6 changes: 3 additions & 3 deletions api/src/opentrons/protocol_api/instrument_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def aspirate(
a location, specify it as a keyword argument:
``instr.aspirate(location=wellplate['A1'])``
""" # noqa: E501
"""
logger.debug(
"aspirate {} from {} at {}".format(
volume, location if location else "current position", rate
Expand Down Expand Up @@ -282,7 +282,7 @@ def dispense(
a location, specify it as a keyword argument:
``instr.dispense(location=wellplate['A1'])``
""" # noqa: E501
"""
logger.debug(
"dispense {} from {} at {}".format(
volume, location if location else "current position", rate
Expand Down Expand Up @@ -1210,7 +1210,7 @@ def move_to(
broker=self.broker,
command=cmds.move_to(
instrument=self,
location=location or self._ctx.location_cache, # type: ignore[arg-type] # noqa: E501
location=location or self._ctx.location_cache, # type: ignore[arg-type]
),
)

Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/protocol_api/labware.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def wells(self, *args: Union[str, int]) -> List[Well]:
if not args:
res = self._implementation.get_wells()
elif isinstance(args[0], int):
res = [self._implementation.get_wells()[idx] for idx in args] # type: ignore[index] # noqa: E501
res = [self._implementation.get_wells()[idx] for idx in args] # type: ignore[index]
elif isinstance(args[0], str):
by_name = self._implementation.get_wells_by_name()
res = [by_name[idx] for idx in args] # type: ignore[index]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async def execute(self, command_id: str) -> None:
log.debug(
f"Executing {command.id}, {command.commandType}, {command.params}"
)
result = await command_impl.execute(command.params) # type: ignore[arg-type] # noqa: E501
result = await command_impl.execute(command.params) # type: ignore[arg-type]

except Exception as error:
log.warning(f"Execution of {command.id} failed", exc_info=error)
Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/protocol_reader/file_reader_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async def _read_file(

if filename.lower().endswith(".json"):
try:
data = parse_raw_as(BufferedJsonFileData, contents) # type: ignore[arg-type] # noqa: E501
data = parse_raw_as(BufferedJsonFileData, contents) # type: ignore[arg-type]

# unlike other Pydantic functions/methods, `parse_raw_as` can
# raise both JSONDecodeError and ValidationError separately
Expand Down
14 changes: 7 additions & 7 deletions api/src/opentrons/protocol_runner/legacy_command_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class LegacyContextCommandError(ProtocolEngineError):
_LEGACY_TO_PE_MODULE: Dict[LegacyModuleModel, pe_types.ModuleModel] = {
LegacyMagneticModuleModel.MAGNETIC_V1: pe_types.ModuleModel.MAGNETIC_MODULE_V1,
LegacyMagneticModuleModel.MAGNETIC_V2: pe_types.ModuleModel.MAGNETIC_MODULE_V2,
LegacyTemperatureModuleModel.TEMPERATURE_V1: pe_types.ModuleModel.TEMPERATURE_MODULE_V1, # noqa: E501
LegacyTemperatureModuleModel.TEMPERATURE_V2: pe_types.ModuleModel.TEMPERATURE_MODULE_V2, # noqa: E501
LegacyThermocyclerModuleModel.THERMOCYCLER_V1: pe_types.ModuleModel.THERMOCYCLER_MODULE_V1, # noqa: E501
LegacyThermocyclerModuleModel.THERMOCYCLER_V2: pe_types.ModuleModel.THERMOCYCLER_MODULE_V2, # noqa: E501
LegacyTemperatureModuleModel.TEMPERATURE_V1: pe_types.ModuleModel.TEMPERATURE_MODULE_V1,
LegacyTemperatureModuleModel.TEMPERATURE_V2: pe_types.ModuleModel.TEMPERATURE_MODULE_V2,
LegacyThermocyclerModuleModel.THERMOCYCLER_V1: pe_types.ModuleModel.THERMOCYCLER_MODULE_V1,
LegacyThermocyclerModuleModel.THERMOCYCLER_V2: pe_types.ModuleModel.THERMOCYCLER_MODULE_V2,
}

_HIGHER_ORDER_COMMAND_TYPES = {
Expand Down Expand Up @@ -203,7 +203,7 @@ def _build_initial_command(
else:
raise Exception("Unknown pick_up_tip location.")
mount = MountType(pipette.mount)
slot = DeckSlotName.from_primitive(well.parent.parent) # type: ignore[arg-type] # noqa: E501
slot = DeckSlotName.from_primitive(well.parent.parent) # type: ignore[arg-type]
well_name = well.well_name
labware_id = self._labware_id_by_slot[slot]
pipette_id = self._pipette_id_by_mount[mount]
Expand All @@ -225,14 +225,14 @@ def _build_initial_command(
and "instrument" in command["payload"]
and "location" in command["payload"]
):
pipette: LegacyPipetteContext = command["payload"]["instrument"] # type: ignore # noqa: E501
pipette: LegacyPipetteContext = command["payload"]["instrument"] # type: ignore
location = command["payload"].get("location")
if isinstance(location, Location):
well = location.labware.as_well()
else:
raise Exception("Unknown drop_tip location.")
mount = MountType(pipette.mount)
slot = DeckSlotName.from_primitive(well.parent.parent) # type: ignore[arg-type] # noqa: E501
slot = DeckSlotName.from_primitive(well.parent.parent) # type: ignore[arg-type]
well_name = well.well_name
labware_id = self._labware_id_by_slot[slot]
pipette_id = self._pipette_id_by_mount[mount]
Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/protocols/api_support/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ def validate_can_dispense(location: types.Location) -> None:
# things a `types.Location` can be (i.e. module, labware, well, etc.)
def _is_tiprack(location: types.Location) -> bool:
labware = location.labware.as_labware()
return labware.parent and labware.parent.is_tiprack # type: ignore[return-value, union-attr] # noqa: E501
return labware.parent and labware.parent.is_tiprack # type: ignore[return-value, union-attr]
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def load_instrument(

attached = {
att_mount: instr.get("name", None)
for att_mount, instr in self._sync_hardware.attached_instruments.items() # noqa: E501
for att_mount, instr in self._sync_hardware.attached_instruments.items()
if instr
}
attached[mount] = instrument_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def load_instrument(

attached = {
att_mount: instr.get("name", None)
for att_mount, instr in self._sync_hardware.attached_instruments.items() # noqa: E501
for att_mount, instr in self._sync_hardware.attached_instruments.items()
if instr
}
attached[mount] = instrument_name
Expand Down
14 changes: 7 additions & 7 deletions api/src/opentrons/protocols/execution/json_dispatchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
}

temperature_module_command_map: "JsonV4TemperatureModuleDispatch" = {
JsonTemperatureModuleCommand.temperatureModuleSetTargetTemperature.value: _temperature_module_set_temp, # noqa: E501
JsonTemperatureModuleCommand.temperatureModuleDeactivate.value: _temperature_module_deactivate, # noqa: E501
JsonTemperatureModuleCommand.temperatureModuleAwaitTemperature.value: _temperature_module_await_temp, # noqa: E501
JsonTemperatureModuleCommand.temperatureModuleSetTargetTemperature.value: _temperature_module_set_temp,
JsonTemperatureModuleCommand.temperatureModuleDeactivate.value: _temperature_module_deactivate,
JsonTemperatureModuleCommand.temperatureModuleAwaitTemperature.value: _temperature_module_await_temp,
}


Expand All @@ -73,10 +73,10 @@ def tc_do_nothing(module: ThermocyclerContext, params) -> None:
thermocycler_module_command_map: "JsonV4ThermocyclerDispatch" = {
JsonThermocyclerCommand.thermocyclerCloseLid.value: _thermocycler_close_lid,
JsonThermocyclerCommand.thermocyclerOpenLid.value: _thermocycler_open_lid,
JsonThermocyclerCommand.thermocyclerDeactivateBlock.value: _thermocycler_deactivate_block, # noqa: E501
JsonThermocyclerCommand.thermocyclerDeactivateLid.value: _thermocycler_deactivate_lid, # noqa: E501
JsonThermocyclerCommand.thermocyclerSetTargetBlockTemperature.value: _thermocycler_set_block_temperature, # noqa: E501
JsonThermocyclerCommand.thermocyclerSetTargetLidTemperature.value: _thermocycler_set_lid_temperature, # noqa: E501
JsonThermocyclerCommand.thermocyclerDeactivateBlock.value: _thermocycler_deactivate_block,
JsonThermocyclerCommand.thermocyclerDeactivateLid.value: _thermocycler_deactivate_lid,
JsonThermocyclerCommand.thermocyclerSetTargetBlockTemperature.value: _thermocycler_set_block_temperature,
JsonThermocyclerCommand.thermocyclerSetTargetLidTemperature.value: _thermocycler_set_lid_temperature,
JsonThermocyclerCommand.thermocyclerRunProfile.value: _thermocycler_run_profile,
# NOTE: the thermocyclerAwaitX commands are expected to always
# follow a corresponding SetX command, which is implemented as
Expand Down
4 changes: 2 additions & 2 deletions api/src/opentrons/protocols/models/json_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
CommandThermocyclerSetTargetLid: dev_types.ThermocyclerSetTargetLidCommandId = (
"thermocycler/setTargetLidTemperature"
)
CommandThermocyclerAwaitLidTemperature: dev_types.ThermocyclerAwaitLidTemperatureCommandId = ( # noqa: E501
CommandThermocyclerAwaitLidTemperature: dev_types.ThermocyclerAwaitLidTemperatureCommandId = (
"thermocycler/awaitLidTemperature"
)
CommandThermocyclerAwaitBlockTemperature: dev_types.ThermocyclerAwaitBlockTemperatureCommandId = ( # noqa: E501
CommandThermocyclerAwaitBlockTemperature: dev_types.ThermocyclerAwaitBlockTemperatureCommandId = (
"thermocycler/awaitBlockTemperature"
)
CommandThermocyclerDeactivateBlock: dev_types.ThermocyclerDeactivateBlockCommandId = (
Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/protocols/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def run(ctx):
Please contact [email protected] to retrieve the previous software version and be guided
through the downgrade process.
""" # noqa: E501
"""


class MalformedProtocolError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def main() -> int:
args = parser.parse_args()
# Try to migrate api v1 containers if needed

duration_estimator = DurationEstimator() if args.estimate_duration else None # type: ignore[no-untyped-call] # noqa: E501
duration_estimator = DurationEstimator() if args.estimate_duration else None # type: ignore[no-untyped-call]

runlog, maybe_bundle = simulate(
args.protocol,
Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/system/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def take_picture(filename: Path) -> None:

if IS_OSX:
# Purely for development on macos
cmd = 'ffmpeg -f avfoundation -framerate 1 -s 640x480 -i "0" -ss 0:0:1 -frames 1' # noqa: E501
cmd = 'ffmpeg -f avfoundation -framerate 1 -s 640x480 -i "0" -ss 0:0:1 -frames 1'

proc = await asyncio.create_subprocess_shell(
f"{cmd} {filename}",
Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/util/linal.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def solve_attitude(expected: SolvePoints, actual: SolvePoints) -> AttitudeMatrix
mask_transform = np.array(
[[True, True, False], [True, True, False], [False, False, False]]
)
masked_array = np.ma.masked_array(t, ~mask_transform) # type: ignore[var-annotated, no-untyped-call] # noqa: E501
masked_array = np.ma.masked_array(t, ~mask_transform) # type: ignore[var-annotated, no-untyped-call]

no_z_component = np.zeros((3, 3))
np.put(no_z_component, [8, 8], 1)
Expand Down
6 changes: 3 additions & 3 deletions api/tests/opentrons/drivers/rpi_drivers/test_usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"/sys/bus/usb/devices/usb1/1-1/1-1.1/dev",
"/sys/bus/usb/devices/usb1/1-1/dev",
"/sys/bus/usb/devices/usb1/1-1/1-1.5/dev",
"/sys/bus/usb/devices/usb1/1-1/1-1.5/1-1.5:1.2/0003:046D:C52B.0017/hidraw/hidraw0/dev", # noqa: E501
"/sys/bus/usb/devices/usb1/1-1/1-1.5/1-1.5:1.2/0003:046D:C52B.0017/hidraw/hidraw0/dev",
"/sys/bus/usb/devices/usb1/1-1/1-1.5/1-1.5:1.2/usbmisc/hiddev0/dev",
]

Expand Down Expand Up @@ -57,7 +57,7 @@ def test_modify_module_list(revision: BoardRevision, usb_bus: USBBus):
# TODO(mc, 2022-03-01): partial patching the class under test creates
# a contaminated test subject that reduces the value of these tests
# https://github.com/testdouble/contributing-tests/wiki/Partial-Mock
usb_bus._read_symlink = MagicMock(return_value="ttyACM1") # type: ignore[assignment] # noqa: E501
usb_bus._read_symlink = MagicMock(return_value="ttyACM1") # type: ignore[assignment]
mod_at_port_list = [
ModuleAtPort(name="temperature module", port="dev/ot_module_temperature_module")
]
Expand All @@ -73,7 +73,7 @@ def test_modify_module_list(revision: BoardRevision, usb_bus: USBBus):
# TODO(mc, 2022-03-01): figure out why this section of the test doesn't
# work on using the OT-2R mocked port values
if revision == BoardRevision.OG:
usb_bus._read_symlink = MagicMock(return_value="ttyACM2") # type: ignore[assignment] # noqa: E501
usb_bus._read_symlink = MagicMock(return_value="ttyACM2") # type: ignore[assignment]
mod_at_port_list = [
ModuleAtPort(name="magnetic module", port="dev/ot_module_magnetic_module")
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def test_command_sender_sanitized_response(
["M3 R \r\n\r\n", "M3R:703130", "R:703130"],
[
"M369 L \r\n\r\n",
"M369 L \r\n\r\nL:5032304D56323032303230303432323036000000000000000000000000000000", # noqa: E501
"M369 L \r\n\r\nL:5032304D56323032303230303432323036000000000000000000000000000000",
"L:5032304D56323032303230303432323036000000000000000000000000000000",
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ async def test_set_temperature_fuzzy(
# Test hold_time < _hold_time_fuzzy_seconds. Here we know
# that wait_for_hold will be called with the direct hold
# time rather than increments of 0.1
set_temperature_subject._wait_for_hold = mock.AsyncMock() # type: ignore[assignment] # noqa: E501
set_temperature_subject._wait_for_hold = mock.AsyncMock() # type: ignore[assignment]
await set_temperature_subject.set_temperature(40, hold_time_seconds=2)
set_temperature_subject._wait_for_hold.assert_called_once_with(2)
set_plate_temp_spy.assert_called_once_with(temp=40, hold_time=2, volume=None)
Expand Down
6 changes: 3 additions & 3 deletions api/tests/opentrons/protocol_api/test_labware.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_well_init() -> None:
name="A1",
),
)
assert well1.geometry.diameter == test_data[well_name]["diameter"] # type: ignore[typeddict-item] # noqa: E501
assert well1.geometry.diameter == test_data[well_name]["diameter"] # type: ignore[typeddict-item]
assert well1.geometry._length is None
assert well1.geometry._width is None

Expand All @@ -101,8 +101,8 @@ def test_well_init() -> None:
),
)
assert well2.geometry.diameter is None
assert well2.geometry._length == test_data[well2_name]["xDimension"] # type: ignore[typeddict-item] # noqa: E501
assert well2.geometry._width == test_data[well2_name]["yDimension"] # type: ignore[typeddict-item] # noqa: E501
assert well2.geometry._length == test_data[well2_name]["xDimension"] # type: ignore[typeddict-item]
assert well2.geometry._width == test_data[well2_name]["yDimension"] # type: ignore[typeddict-item]


def test_top() -> None:
Expand Down
Loading

0 comments on commit d12d651

Please sign in to comment.