From 00a78df371ad8a5325fcd9b6baae3c8c0ebe0cd9 Mon Sep 17 00:00:00 2001 From: Mike Lin Date: Fri, 28 Jun 2024 09:53:58 -0700 Subject: [PATCH] migrate linting to ruff --- Makefile | 3 +-- WDL/CLI.py | 4 ++-- WDL/Lint.py | 4 ++-- WDL/StdLib.py | 4 +--- WDL/Zip.py | 6 ++---- WDL/__init__.py | 6 ++---- WDL/_util.py | 3 +-- WDL/runtime/__init__.py | 7 +++---- WDL/runtime/backend/singularity.py | 2 +- WDL/runtime/backend/udocker.py | 2 +- WDL/runtime/config.py | 4 ++-- WDL/runtime/task.py | 2 +- WDL/runtime/task_container.py | 4 ++-- WDL/runtime/workflow.py | 2 +- requirements.dev.txt | 4 +--- 15 files changed, 23 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 447ba422..5b1efeea 100644 --- a/Makefile +++ b/Makefile @@ -41,9 +41,8 @@ ci_housekeeping: sopretty check_check check doc ci_unit_tests: unit_tests check: + ruff check --ignore E741 WDL mypy WDL - pylint -j `python3 -c 'import multiprocessing as mp; print(mp.cpu_count())'` --errors-only WDL - flake8 WDL check_check: # regression test against pyre/mypy doing nothing (issue #100) diff --git a/WDL/CLI.py b/WDL/CLI.py index 7e8f02d8..24fdc9b5 100644 --- a/WDL/CLI.py +++ b/WDL/CLI.py @@ -1586,7 +1586,7 @@ def localize( ) logging.basicConfig(level=level) logger = logging.getLogger("miniwdl-localize") - with configure_logger(json=log_json) as set_status: + with configure_logger(json=log_json) as _set_status: from . import runtime cfg_arg = None @@ -1767,7 +1767,7 @@ def configure(cfg=None, show=False, force=False, **kwargs): logging.raiseExceptions = False logging.basicConfig(level=VERBOSE_LEVEL) logger = logging.getLogger("miniwdl-configure") - with configure_logger() as set_status: + with configure_logger() as _set_status: if (show or not force) and configure_existing(logger, cfg, always=show): sys.exit(0) diff --git a/WDL/Lint.py b/WDL/Lint.py index 3c778f3a..d03eea61 100644 --- a/WDL/Lint.py +++ b/WDL/Lint.py @@ -208,7 +208,7 @@ def _compound_coercion( if predicates: return predicates(to_type, from_type) if not from_type_predicate: - from_type_predicate = lambda ty: not isinstance( # noqa: disable=E731 + from_type_predicate = lambda ty: not isinstance( # noqa: E731 ty, (base_to_type, Type.Any) ) return from_type_predicate(from_type) @@ -1167,7 +1167,7 @@ def task(self, obj: Tree.Task) -> Any: if isinstance(lit, str): try: _util.parse_byte_size(lit) - except: + except Exception: self.add( obj, "runtime.memory doesn't follow expected format like '8G' or '1024 MiB'", diff --git a/WDL/StdLib.py b/WDL/StdLib.py index 20a1e6f8..c16e43c2 100644 --- a/WDL/StdLib.py +++ b/WDL/StdLib.py @@ -1037,9 +1037,7 @@ def infer_type(self, expr: "Expr.Apply") -> Type.Base: expr.arguments[0].typecheck(Type.Array(Type.String())) arg0ty = expr.arguments[0].type nonempty = isinstance(arg0ty, Type.Array) and arg0ty.nonempty - return Type.Array( - Type.String(), nonempty=(isinstance(arg0ty, Type.Array) and arg0ty.nonempty) - ) + return Type.Array(Type.String(), nonempty=nonempty) def _call_eager(self, expr: "Expr.Apply", arguments: List[Value.Base]) -> Value.Base: return Value.Array( diff --git a/WDL/Zip.py b/WDL/Zip.py index a234fe5a..b4b9a1d7 100644 --- a/WDL/Zip.py +++ b/WDL/Zip.py @@ -113,8 +113,6 @@ def build_zip_paths( main_dir: str, wdls: Dict[str, Tree.Document], logger: logging.Logger ) -> Dict[str, str]: # compute the path inside the archive at which to store each document - import hashlib - import base64 ans = {} outside_warn = False @@ -249,7 +247,7 @@ def unpack(archive_fn: str) -> Iterator[UnpackedZip]: dn = cleanup.enter_context(tempfile.TemporaryDirectory(prefix="miniwdl_run_zip_")) try: shutil.unpack_archive(archive_fn, dn) - except: + except Exception: raise Error.InputError("Unreadable source archive " + archive_fn) manifest_fn = os.path.join(dn, "MANIFEST.json") @@ -259,7 +257,7 @@ def unpack(archive_fn: str) -> Iterator[UnpackedZip]: assert isinstance(manifest, dict) and isinstance( manifest.get("mainWorkflowURL", None), str ) - except: + except Exception: raise Error.InputError("Missing or invalid MANIFEST.json in " + archive_fn) dn = os.path.abspath(os.path.dirname(manifest_fn)) diff --git a/WDL/__init__.py b/WDL/__init__.py index 81a5fc90..c0dc645f 100644 --- a/WDL/__init__.py +++ b/WDL/__init__.py @@ -10,11 +10,9 @@ import sys import os -import errno -import inspect from typing import List, Optional, Callable, Dict, Any, Awaitable, Union -from . import _util, _parser, Error, Type, Value, Env, Expr, Tree, Walker, Zip -from .Tree import ( +from . import _util, _parser, Error, Type, Value, Env, Expr, Tree, Walker +from .Tree import ( # noqa: F401 Decl, StructTypeDef, Task, diff --git a/WDL/_util.py b/WDL/_util.py index db178780..aa6a306f 100644 --- a/WDL/_util.py +++ b/WDL/_util.py @@ -9,7 +9,6 @@ import time import fcntl import shutil -import hashlib import uuid from time import sleep from datetime import datetime @@ -923,5 +922,5 @@ def currently_in_container() -> bool: try: with open(f"/proc/{os.getpid()}/mounts") as infile: return " / overlay" in infile.read() - except: + except Exception: return False diff --git a/WDL/runtime/__init__.py b/WDL/runtime/__init__.py index dda5591b..10ba1eed 100644 --- a/WDL/runtime/__init__.py +++ b/WDL/runtime/__init__.py @@ -8,10 +8,9 @@ from typing import Union, Dict, Tuple, Any from .. import Tree, Value, Env from . import config -from . import task -from . import workflow -from . import _statusbar -from .error import ( +from . import task # noqa: F401 +from . import workflow # noqa: F401 +from .error import ( # noqa: F401 RunFailed, CommandFailed, Terminated, diff --git a/WDL/runtime/backend/singularity.py b/WDL/runtime/backend/singularity.py index 67763ad8..be21f78c 100644 --- a/WDL/runtime/backend/singularity.py +++ b/WDL/runtime/backend/singularity.py @@ -31,7 +31,7 @@ def global_init(cls, cfg: config.Loader, logger: logging.Logger) -> None: check=True, universal_newlines=True, ) - except: + except Exception: raise RuntimeError( f"Unable to check `{' '.join(cmd)}`; verify Singularity installation" ) diff --git a/WDL/runtime/backend/udocker.py b/WDL/runtime/backend/udocker.py index a1c1a44a..9420cda2 100644 --- a/WDL/runtime/backend/udocker.py +++ b/WDL/runtime/backend/udocker.py @@ -28,7 +28,7 @@ def global_init(cls, cfg: config.Loader, logger: logging.Logger) -> None: check=True, universal_newlines=True, ) - except: + except Exception: raise RuntimeError(f"Unable to check `{' '.join(cmd)}`; verify udocker installation") logger.notice( _( diff --git a/WDL/runtime/config.py b/WDL/runtime/config.py index f9f2ba82..c80d2d2f 100644 --- a/WDL/runtime/config.py +++ b/WDL/runtime/config.py @@ -234,7 +234,7 @@ def _parse( raise try: return parse(ans) - except: + except Exception: self._logger.debug( _( "failed to parse configuration option", @@ -370,7 +370,7 @@ def _parse_list(v: str) -> List[Any]: return ans -def default_plugins() -> "Dict[str,List[importlib_metadata.EntryPoint]]": # type: ignore +def default_plugins() -> "Dict[str,List[importlib_metadata.EntryPoint]]": # type: ignore # noqa: F821 import importlib_metadata # delayed heavy import return { diff --git a/WDL/runtime/task.py b/WDL/runtime/task.py index f303e014..d9c27623 100644 --- a/WDL/runtime/task.py +++ b/WDL/runtime/task.py @@ -842,7 +842,7 @@ def map_paths(v: Value.Base, dn: str) -> Value.Base: # might otherwise have trouble distinguishing Directory outputs among the # structured subdirectories we create for compound types. if isinstance(v, Value.Directory): - with open(os.path.join(dn, ".WDL_Directory"), "w") as dotfile: + with open(os.path.join(dn, ".WDL_Directory"), "w") as _dotfile: pass v.value = link # recurse into compound values diff --git a/WDL/runtime/task_container.py b/WDL/runtime/task_container.py index be1dd4a6..81faa3b1 100644 --- a/WDL/runtime/task_container.py +++ b/WDL/runtime/task_container.py @@ -10,7 +10,7 @@ from typing import Callable, Iterable, Any, Dict, Optional, ContextManager, Set from abc import ABC, abstractmethod from contextlib import suppress -from .. import Error, Env, Value, Type +from .. import Error, Value, Type from .._util import ( TerminationSignalFlag, path_really_within, @@ -283,7 +283,7 @@ def process_runtime(self, logger: logging.Logger, runtime_eval: Dict[str, Value. elif isinstance(rcv, Value.Array): try: ans["returnCodes"] = [v.coerce(Type.Int()).value for v in rcv.value] - except: + except Exception: pass if "returnCodes" not in ans: raise Error.RuntimeError("invalid setting of runtime.returnCodes") diff --git a/WDL/runtime/workflow.py b/WDL/runtime/workflow.py index 2c5311f0..b58fb841 100644 --- a/WDL/runtime/workflow.py +++ b/WDL/runtime/workflow.py @@ -913,7 +913,7 @@ def run_local_workflow( if not _thread_pools: # delayed heavy imports -- load .task_container now to work around python issue41567 import importlib_metadata - from .task_container import new as _new_task_container + from .task_container import new as _new_task_container # noqa: F401 assert not _run_id_stack try: diff --git a/requirements.dev.txt b/requirements.dev.txt index 063c121c..04af9271 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1,8 +1,6 @@ # Packages needed for miniwdl development, in addition to those in # requirements.txt which are needed for miniwdl to run in common use. -r requirements.txt -black==24.4.2 -pylint sphinx sphinx-autobuild sphinx_rtd_theme @@ -19,5 +17,5 @@ pytest-xdist recommonmark sphinx-argparse boto3 -flake8 mypy +ruff