Skip to content

Commit

Permalink
migrate linting to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Jun 28, 2024
1 parent 04ca37e commit 00a78df
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 34 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions WDL/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions WDL/Lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'",
Expand Down
4 changes: 1 addition & 3 deletions WDL/StdLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 2 additions & 4 deletions WDL/Zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand All @@ -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))
Expand Down
6 changes: 2 additions & 4 deletions WDL/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions WDL/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import time
import fcntl
import shutil
import hashlib
import uuid
from time import sleep
from datetime import datetime
Expand Down Expand Up @@ -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
7 changes: 3 additions & 4 deletions WDL/runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion WDL/runtime/backend/singularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion WDL/runtime/backend/udocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
_(
Expand Down
4 changes: 2 additions & 2 deletions WDL/runtime/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _parse(
raise
try:
return parse(ans)
except:
except Exception:
self._logger.debug(
_(
"failed to parse configuration option",
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion WDL/runtime/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions WDL/runtime/task_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion WDL/runtime/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,5 +17,5 @@ pytest-xdist
recommonmark
sphinx-argparse
boto3
flake8
mypy
ruff

0 comments on commit 00a78df

Please sign in to comment.