Skip to content

Commit

Permalink
format with latest ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
ptpt committed Jan 13, 2025
1 parent 1b2b70a commit 9c0c59c
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 77 deletions.
18 changes: 9 additions & 9 deletions mapillary_tools/camm/camm_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def _create_edit_list(
]
break

assert (
0 <= points[0].time
), f"expect non-negative point time but got {points[0]}"
assert (
points[0].time <= points[-1].time
), f"expect points to be sorted but got first point {points[0]} and last point {points[-1]}"
assert 0 <= points[0].time, (
f"expect non-negative point time but got {points[0]}"
)
assert points[0].time <= points[-1].time, (
f"expect points to be sorted but got first point {points[0]} and last point {points[-1]}"
)

if idx == 0:
if 0 < points[0].time:
Expand Down Expand Up @@ -92,9 +92,9 @@ def convert_points_to_raw_samples(
timedelta = int((points[idx + 1].time - point.time) * timescale)
else:
timedelta = 0
assert (
0 <= timedelta <= builder.UINT32_MAX
), f"expected timedelta {timedelta} between {points[idx]} and {points[idx + 1]} with timescale {timescale} to be <= UINT32_MAX"
assert 0 <= timedelta <= builder.UINT32_MAX, (
f"expected timedelta {timedelta} between {points[idx]} and {points[idx + 1]} with timescale {timescale} to be <= UINT32_MAX"
)

yield sample_parser.RawSample(
# will update later
Expand Down
4 changes: 2 additions & 2 deletions mapillary_tools/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ def generate_binary_search(self, sorted_frame_indices: T.Sequence[int]) -> str:
return "0"

if length == 1:
return f"eq(n\\,{ sorted_frame_indices[0] })"
return f"eq(n\\,{sorted_frame_indices[0]})"

middle = length // 2
return f"if(lt(n\\,{ sorted_frame_indices[middle] })\\,{ self.generate_binary_search(sorted_frame_indices[:middle]) }\\,{ self.generate_binary_search(sorted_frame_indices[middle:]) })"
return f"if(lt(n\\,{sorted_frame_indices[middle]})\\,{self.generate_binary_search(sorted_frame_indices[:middle])}\\,{self.generate_binary_search(sorted_frame_indices[middle:])})"

def extract_specified_frames(
self,
Expand Down
6 changes: 3 additions & 3 deletions mapillary_tools/geotag/gpmf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ def _apply_matrix(
matrix: T.Sequence[float], values: T.Sequence[float]
) -> T.Generator[float, None, None]:
size = len(values)
assert (
len(matrix) == size * size
), f"expecting a square matrix of size {size} x {size} but got {len(matrix)}"
assert len(matrix) == size * size, (
f"expecting a square matrix of size {size} x {size} but got {len(matrix)}"
)

for y in range(size):
row_start = y * size
Expand Down
6 changes: 3 additions & 3 deletions mapillary_tools/mp4/construct_mp4_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ def find_box_at_path(
return box
box_data = T.cast(T.Sequence[BoxDict], box["data"])
# ListContainer from construct is not sequence
assert isinstance(
box_data, T.Sequence
), f"expect a list of boxes but got {type(box_data)} at path {path}"
assert isinstance(box_data, T.Sequence), (
f"expect a list of boxes but got {type(box_data)} at path {path}"
)
found = find_box_at_path(box_data, path[1:])
if found is not None:
return found
Expand Down
6 changes: 3 additions & 3 deletions mapillary_tools/mp4/mp4_sample_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def _extract_raw_samples(
if not chunk_entries:
return

assert (
len(sizes) <= len(timedeltas)
), f"got less ({len(timedeltas)}) sample time deltas (stts) than expected ({len(sizes)})"
assert len(sizes) <= len(timedeltas), (
f"got less ({len(timedeltas)}) sample time deltas (stts) than expected ({len(sizes)})"
)

sample_idx = 0
chunk_idx = 0
Expand Down
6 changes: 3 additions & 3 deletions mapillary_tools/mp4/simple_mp4_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ def _rewrite_and_build_moov_typed_data(
for box in _filter_trak_boxes(moov_children):
sample_offset = _update_sbtl_sample_offsets(box, sample_offset)
moov_typed_data = _build_moov_typed_data(moov_children)
assert (
len(moov_typed_data) == moov_typed_data_size
), f"{len(moov_typed_data)} != {moov_typed_data_size}"
assert len(moov_typed_data) == moov_typed_data_size, (
f"{len(moov_typed_data)} != {moov_typed_data_size}"
)

return moov_typed_data
6 changes: 3 additions & 3 deletions mapillary_tools/process_geotag_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ def process_geotag_properties(
metadatas.extend(video_metadata)

# filenames should be deduplicated in utils.find_images/utils.find_videos
assert len(metadatas) == len(
set(metadata.filename for metadata in metadatas)
), "duplicate filenames found"
assert len(metadatas) == len(set(metadata.filename for metadata in metadatas)), (
"duplicate filenames found"
)

return metadatas

Expand Down
12 changes: 6 additions & 6 deletions mapillary_tools/process_sequence_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ def _interpolate_subsecs_for_sorting(sequence: PointSequence) -> None:
gidx = gidx + len(group)

for cur, nxt in geo.pairwise(sequence):
assert (
cur.time <= nxt.time
), f"sequence must be sorted but got {cur.time} > {nxt.time}"
assert cur.time <= nxt.time, (
f"sequence must be sorted but got {cur.time} > {nxt.time}"
)


def _parse_filesize_in_bytes(filesize_str: str) -> int:
Expand Down Expand Up @@ -335,9 +335,9 @@ def process_sequence_properties(

results = error_metadatas + image_metadatas + video_metadatas

assert len(metadatas) == len(
results
), f"expected {len(metadatas)} results but got {len(results)}"
assert len(metadatas) == len(results), (
f"expected {len(metadatas)} results but got {len(results)}"
)
assert sequence_idx == len(
set(metadata.MAPSequenceUUID for metadata in image_metadatas)
)
Expand Down
18 changes: 9 additions & 9 deletions mapillary_tools/sample_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def sample_video(
start_time=video_start_time_dt,
)
else:
assert (
0 < video_sample_interval
), "expect positive video_sample_interval but got {video_sample_interval}"
assert 0 < video_sample_interval, (
"expect positive video_sample_interval but got {video_sample_interval}"
)
_sample_single_video_by_interval(
video_path,
sample_dir,
Expand Down Expand Up @@ -339,9 +339,9 @@ def _sample_single_video_by_distance(
f"Expect {len(sorted_sample_indices)} samples but extracted {len(frame_samples)} samples"
)
for idx, (frame_idx_1based, sample_paths) in enumerate(frame_samples):
assert (
len(sample_paths) == 1
), "Expect 1 sample path at {frame_idx_1based} but got {sample_paths}"
assert len(sample_paths) == 1, (
"Expect 1 sample path at {frame_idx_1based} but got {sample_paths}"
)
if idx + 1 != frame_idx_1based:
raise exceptions.MapillaryVideoError(
f"Expect {sample_paths[0]} to be {idx + 1}th sample but got {frame_idx_1based}"
Expand All @@ -352,9 +352,9 @@ def _sample_single_video_by_distance(
continue

video_sample, interp = sample_points_by_frame_idx[sample_idx]
assert (
interp.time == video_sample.exact_composition_time
), f"interpolated time {interp.time} should match the video sample time {video_sample.exact_composition_time}"
assert interp.time == video_sample.exact_composition_time, (
f"interpolated time {interp.time} should match the video sample time {video_sample.exact_composition_time}"
)

timestamp = start_time + datetime.timedelta(seconds=interp.time)
exif_edit = ExifEdit(sample_paths[0])
Expand Down
6 changes: 3 additions & 3 deletions mapillary_tools/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,9 @@ def upload(
)
for idx, video_metadata in enumerate(specified_video_metadatas):
video_metadata.update_md5sum()
assert isinstance(
video_metadata.md5sum, str
), "md5sum should be updated"
assert isinstance(video_metadata.md5sum, str), (
"md5sum should be updated"
)
generator = camm_builder.camm_sample_generator2(video_metadata)
with video_metadata.filename.open("rb") as src_fp:
camm_fp = simple_mp4_builder.transform_mp4(src_fp, generator)
Expand Down
6 changes: 3 additions & 3 deletions mapillary_tools/upload_api_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ def upload(
if not chunk:
break

assert (
offset == self.entity_size
), f"Offset ends at {offset} but the entity size is {self.entity_size}"
assert offset == self.entity_size, (
f"Offset ends at {offset} but the entity size is {self.entity_size}"
)

payload = resp.json()
try:
Expand Down
30 changes: 18 additions & 12 deletions tests/integration/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,33 +238,39 @@ def verify_descs(expected: T.List[T.Dict], actual: T.Union[Path, T.List[T.Dict]]
e = expected_desc["MAPCompassHeading"]
assert "MAPCompassHeading" in actual_desc, actual_desc
a = actual_desc["MAPCompassHeading"]
assert (
abs(e["TrueHeading"] - a["TrueHeading"]) < 0.001
), f'got {a["TrueHeading"]} but expect {e["TrueHeading"]} in {filename}'
assert (
abs(e["MagneticHeading"] - a["MagneticHeading"]) < 0.001
), f'got {a["MagneticHeading"]} but expect {e["MagneticHeading"]} in {filename}'
assert abs(e["TrueHeading"] - a["TrueHeading"]) < 0.001, (
f"got {a['TrueHeading']} but expect {e['TrueHeading']} in {filename}"
)
assert abs(e["MagneticHeading"] - a["MagneticHeading"]) < 0.001, (
f"got {a['MagneticHeading']} but expect {e['MagneticHeading']} in {filename}"
)

if "MAPCaptureTime" in expected_desc:
assert (
expected_desc["MAPCaptureTime"] == actual_desc["MAPCaptureTime"]
), f'expect {expected_desc["MAPCaptureTime"]} but got {actual_desc["MAPCaptureTime"]} in {filename}'
assert expected_desc["MAPCaptureTime"] == actual_desc["MAPCaptureTime"], (
f"expect {expected_desc['MAPCaptureTime']} but got {actual_desc['MAPCaptureTime']} in {filename}"
)

if "MAPLongitude" in expected_desc:
assert (
abs(expected_desc["MAPLongitude"] - actual_desc["MAPLongitude"])
< 0.00001
), f'expect {expected_desc["MAPLongitude"]} but got {actual_desc["MAPLongitude"]} in {filename}'
), (
f"expect {expected_desc['MAPLongitude']} but got {actual_desc['MAPLongitude']} in {filename}"
)

if "MAPLatitude" in expected_desc:
assert (
abs(expected_desc["MAPLatitude"] - actual_desc["MAPLatitude"]) < 0.00001
), f'expect {expected_desc["MAPLatitude"]} but got {actual_desc["MAPLatitude"]} in {filename}'
), (
f"expect {expected_desc['MAPLatitude']} but got {actual_desc['MAPLatitude']} in {filename}"
)

if "MAPAltitude" in expected_desc:
assert (
abs(expected_desc["MAPAltitude"] - actual_desc["MAPAltitude"]) < 0.001
), f'expect {expected_desc["MAPAltitude"]} but got {actual_desc["MAPAltitude"]} in {filename}'
), (
f"expect {expected_desc['MAPAltitude']} but got {actual_desc['MAPAltitude']} in {filename}"
)

if "MAPDeviceMake" in expected_desc:
assert expected_desc["MAPDeviceMake"] == actual_desc["MAPDeviceMake"]
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def test_upload_images(
shell=True,
)
assert x.returncode == 0, x.stderr
assert (
len(setup_upload.listdir()) == 0
), "should NOT upload because it is uploaded already"
assert len(setup_upload.listdir()) == 0, (
"should NOT upload because it is uploaded already"
)


@pytest.mark.usefixtures("setup_config")
Expand All @@ -97,6 +97,6 @@ def test_upload_blackvue(
shell=True,
)
assert x.returncode == 0, x.stderr
assert (
len(setup_upload.listdir()) == 0
), "should NOT upload because it is uploaded already"
assert len(setup_upload.listdir()) == 0, (
"should NOT upload because it is uploaded already"
)
12 changes: 6 additions & 6 deletions tests/integration/test_process_and_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"MAPCaptureTime": "2019_11_18_15_44_47_862",
"MAPCompassHeading": {"MagneticHeading": 313.689, "TrueHeading": 313.689},
"MAPDeviceMake": "GoPro",
"MAPDeviceModel": "GoPro " "Max",
"MAPDeviceModel": "GoPro Max",
"MAPLatitude": 33.1266719,
"MAPLongitude": -117.3273063,
"MAPOrientation": 1,
Expand All @@ -75,7 +75,7 @@
"MAPCaptureTime": "2019_11_18_15_44_49_862",
"MAPCompassHeading": {"MagneticHeading": 326.179, "TrueHeading": 326.179},
"MAPDeviceMake": "GoPro",
"MAPDeviceModel": "GoPro " "Max",
"MAPDeviceModel": "GoPro Max",
"MAPLatitude": 33.1266891,
"MAPLongitude": -117.3273151,
"MAPOrientation": 1,
Expand All @@ -86,7 +86,7 @@
"MAPCaptureTime": "2019_11_18_15_44_51_862",
"MAPCompassHeading": {"MagneticHeading": 353.178, "TrueHeading": 353.178},
"MAPDeviceMake": "GoPro",
"MAPDeviceModel": "GoPro " "Max",
"MAPDeviceModel": "GoPro Max",
"MAPLatitude": 33.1267078,
"MAPLongitude": -117.3273264,
"MAPOrientation": 1,
Expand All @@ -97,7 +97,7 @@
"MAPCaptureTime": "2019_11_18_15_44_53_862",
"MAPCompassHeading": {"MagneticHeading": 334.427, "TrueHeading": 334.427},
"MAPDeviceMake": "GoPro",
"MAPDeviceModel": "GoPro " "Max",
"MAPDeviceModel": "GoPro Max",
"MAPLatitude": 33.1267282,
"MAPLongitude": -117.3273391,
"MAPOrientation": 1,
Expand All @@ -108,7 +108,7 @@
"MAPCaptureTime": "2019_11_18_15_44_55_862",
"MAPCompassHeading": {"MagneticHeading": 325.089, "TrueHeading": 325.089},
"MAPDeviceMake": "GoPro",
"MAPDeviceModel": "GoPro " "Max",
"MAPDeviceModel": "GoPro Max",
"MAPLatitude": 33.12675,
"MAPLongitude": -117.3273483,
"MAPOrientation": 1,
Expand All @@ -119,7 +119,7 @@
"MAPCaptureTime": "2019_11_18_15_44_57_862",
"MAPCompassHeading": {"MagneticHeading": 327.867, "TrueHeading": 327.867},
"MAPDeviceMake": "GoPro",
"MAPDeviceModel": "GoPro " "Max",
"MAPDeviceModel": "GoPro Max",
"MAPLatitude": 33.1267663,
"MAPLongitude": -117.3273595,
"MAPOrientation": 1,
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def test_chained():
thrown_x is None and thrown_y is None
), (thrown_x, thrown_y, whence, offset)
if not thrown_x:
assert (
x == y
), f"whence={whence} offset={offset} x={x} y={y} {s.tell()} {c.tell()}"
assert x == y, (
f"whence={whence} offset={offset} x={x} y={y} {s.tell()} {c.tell()}"
)

n = random.randint(-1, 20)
assert s.read(n) == c.read(n), f"n={n}"
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def _validate_zip_dir(zip_dir: py.path.local):
for zip_path in zip_dir.listdir():
with zipfile.ZipFile(zip_path) as ziph:
upload_md5sum = json.loads(ziph.comment).get("upload_md5sum")
assert (
str(os.path.basename(zip_path)) == f"mly_tools_{upload_md5sum}.zip"
), zip_path
assert str(os.path.basename(zip_path)) == f"mly_tools_{upload_md5sum}.zip", (
zip_path
)
descs.extend(validate_and_extract_zip(str(zip_path)))
return descs

Expand Down

0 comments on commit 9c0c59c

Please sign in to comment.