diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index dacbaeaa8..177d347ea 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -67,16 +67,13 @@ jobs: python -m pip install . python -m pip install -r requirements-dev.txt - - name: Lint with flake8 + - name: Lint with ruff run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + ruff check mapillary_tools - - name: Lint with black + - name: Format with ruff run: | - black --check mapillary_tools tests + ruff format --check mapillary_tools tests - name: Sort imports with usort run: | diff --git a/mapillary_tools/mp4/mp4_sample_parser.py b/mapillary_tools/mp4/mp4_sample_parser.py index 1cebd682b..38a624a74 100644 --- a/mapillary_tools/mp4/mp4_sample_parser.py +++ b/mapillary_tools/mp4/mp4_sample_parser.py @@ -59,8 +59,8 @@ def _extract_raw_samples( if not chunk_entries: return - assert len(sizes) <= len( - timedeltas + assert ( + len(sizes) <= len(timedeltas) ), f"got less ({len(timedeltas)}) sample time deltas (stts) than expected ({len(sizes)})" sample_idx = 0 diff --git a/mapillary_tools/process_geotag_properties.py b/mapillary_tools/process_geotag_properties.py index 7adda1f55..3515d32c4 100644 --- a/mapillary_tools/process_geotag_properties.py +++ b/mapillary_tools/process_geotag_properties.py @@ -170,7 +170,7 @@ def _process_videos( def _normalize_import_paths( - import_path: T.Union[Path, T.Sequence[Path]] + import_path: T.Union[Path, T.Sequence[Path]], ) -> T.Sequence[Path]: import_paths: T.Sequence[Path] if isinstance(import_path, Path): @@ -283,7 +283,7 @@ def _process_videos_beta(vars_args: T.Dict): options: CliOptions = { "paths": vars_args["import_path"], - "recursive": vars_args["skip_subfolders"] == False, + "recursive": vars_args["skip_subfolders"] is False, "geotag_sources_options": geotag_sources_opts, "geotag_source_path": vars_args["geotag_source_path"], "num_processes": vars_args["num_processes"], diff --git a/mapillary_tools/sample_video.py b/mapillary_tools/sample_video.py index 65d1baa72..eb0217063 100644 --- a/mapillary_tools/sample_video.py +++ b/mapillary_tools/sample_video.py @@ -167,7 +167,7 @@ def wip_dir_context(wip_dir: Path, done_dir: Path, rename_timeout_sec: int = 10) except Exception as e: time.sleep(1) error = e - if not renamed and not error is None: + if not renamed and error is not None: raise error else: wip_dir.rename(done_dir) diff --git a/mapillary_tools/video_data_extraction/extractors/base_parser.py b/mapillary_tools/video_data_extraction/extractors/base_parser.py index d0a29ee6b..275310614 100644 --- a/mapillary_tools/video_data_extraction/extractors/base_parser.py +++ b/mapillary_tools/video_data_extraction/extractors/base_parser.py @@ -2,7 +2,6 @@ import functools import logging import os -import sys import typing as T from pathlib import Path diff --git a/mapillary_tools/video_data_extraction/extractors/camm_parser.py b/mapillary_tools/video_data_extraction/extractors/camm_parser.py index 122a0ca5f..fa40c7589 100644 --- a/mapillary_tools/video_data_extraction/extractors/camm_parser.py +++ b/mapillary_tools/video_data_extraction/extractors/camm_parser.py @@ -31,12 +31,12 @@ def extract_make(self) -> T.Optional[str]: source_path = self.geotag_source_path if not source_path: return None - with source_path.open("rb") as fp: + with source_path.open("rb") as _fp: return self.__camera_info[0] or None def extract_model(self) -> T.Optional[str]: source_path = self.geotag_source_path if not source_path: return None - with source_path.open("rb") as fp: + with source_path.open("rb") as _fp: return self.__camera_info[1] or None diff --git a/mapillary_tools/video_data_extraction/extractors/gpx_parser.py b/mapillary_tools/video_data_extraction/extractors/gpx_parser.py index d38347b83..6a75e9c65 100644 --- a/mapillary_tools/video_data_extraction/extractors/gpx_parser.py +++ b/mapillary_tools/video_data_extraction/extractors/gpx_parser.py @@ -16,7 +16,7 @@ def extract_points(self) -> T.Sequence[geo.Point]: return [] try: tracks = geotag_images_from_gpx_file.parse_gpx(path) - except Exception as e: + except Exception: return [] points: T.Sequence[geo.Point] = sum(tracks, []) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7834f0c08..e230ed265 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,9 +1,8 @@ Pillow; python_version>='3.8' pytest -black mypy +ruff pyinstaller -flake8 types-requests types-appdirs usort diff --git a/tests/unit/test_sequence_processing.py b/tests/unit/test_sequence_processing.py index 466d4dafd..053ee2fbe 100644 --- a/tests/unit/test_sequence_processing.py +++ b/tests/unit/test_sequence_processing.py @@ -231,7 +231,8 @@ def test_duplication(tmpdir: py.path.local): error_metadatas = [d for d in metadatas if isinstance(d, types.ErrorMetadata)] assert len(error_metadatas) == 4 assert set(d.filename for d in sequence[1:-2]) == set( - Path(d.error.desc["filename"]) for d in error_metadatas # type: ignore + Path(d.error.desc["filename"]) + for d in error_metadatas # type: ignore )