Skip to content

Commit

Permalink
fix linting setup and fix all linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-wer committed Jul 24, 2023
1 parent de4abb2 commit 12761b1
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 26 deletions.
12 changes: 1 addition & 11 deletions cluster_tools/cluster_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import logging
import multiprocessing
import os
import tempfile
from concurrent import futures
from concurrent.futures import ProcessPoolExecutor
from functools import partial
from pathlib import Path
from shutil import rmtree
from typing import Any, Union, overload

from typing_extensions import Literal

from cluster_tools._utils.warning import enrich_future_with_uncaught_warning
from cluster_tools.executors.debug_sequential import DebugSequentialExecutor
from cluster_tools.executors.multiprocessing_ import MultiprocessingExecutor
from cluster_tools.executors.pickle import PickleExecutor
from cluster_tools.executors.pickle_ import PickleExecutor
from cluster_tools.executors.sequential import SequentialExecutor
from cluster_tools.schedulers.cluster_executor import (
ClusterExecutor,
Expand Down
2 changes: 2 additions & 0 deletions cluster_tools/cluster_tools/_utils/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def call(command: str, stdin: Optional[str] = None) -> Tuple[str, str, int]:
stdin_flag = None
p = subprocess.run(
command,
stdin=stdin_flag,
check=False,
shell=True,
capture_output=True,
text=True,
Expand Down
2 changes: 1 addition & 1 deletion cluster_tools/cluster_tools/_utils/file_wait_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import threading
import time
from typing import TYPE_CHECKING, Callable, Dict, Tuple
from typing import TYPE_CHECKING, Callable, Dict

if TYPE_CHECKING:
from cluster_tools.schedulers.cluster_executor import ClusterExecutor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from logging.handlers import QueueHandler
from queue import Empty as QueueEmpty
from queue import Queue
from typing import Any, Callable, List, Tuple
from typing import Any, Callable, List

# Inspired by https://stackoverflow.com/a/894284

Expand Down
2 changes: 0 additions & 2 deletions cluster_tools/cluster_tools/_utils/reflection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os
import pickle
import sys
from typing import Callable

WARNING_TIMEOUT = 10 * 60 # seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import random
import string

# The module name includes a _-suffix to avoid name clashes with the standard library string module.


def local_filename(filename: str = "") -> str:
return os.path.join(os.getenv("CFUT_DIR", ".cfut"), filename)
Expand Down
2 changes: 1 addition & 1 deletion cluster_tools/cluster_tools/_utils/tailf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def follow(self, seconds: int = 1) -> None:
"""

self.check_file_validity(self.tailed_file)
with open(self.tailed_file, errors="replace") as file_:
with open(self.tailed_file, encoding="utf-8", errors="replace") as file_:
# Don't seek, since we want to print the entire file here.
while True:
line = file_.readline()
Expand Down
2 changes: 0 additions & 2 deletions cluster_tools/cluster_tools/_utils/warning.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import logging
import os
import string
import threading
import time
from concurrent.futures import Future
Expand Down
6 changes: 3 additions & 3 deletions cluster_tools/cluster_tools/executors/multiprocessing_.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import multiprocessing
import os
import sys
import tempfile
from concurrent import futures
from concurrent.futures import Future, ProcessPoolExecutor
Expand All @@ -12,7 +11,6 @@
from typing import (
Any,
Callable,
Dict,
Iterable,
Iterator,
List,
Expand All @@ -22,14 +20,16 @@
cast,
)

from typing_extensions import Literal, ParamSpec, TypedDict
from typing_extensions import ParamSpec, TypedDict

from cluster_tools._utils import pickling
from cluster_tools._utils.multiprocessing_logging_handler import (
_MultiprocessingLoggingHandlerPool,
)
from cluster_tools._utils.warning import enrich_future_with_uncaught_warning

# The module name includes a _-suffix to avoid name clashes with the standard library multiprocessing module.


class CFutDict(TypedDict):
output_pickle_path: str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from cluster_tools._utils import pickling
from cluster_tools.executors.multiprocessing_ import MultiprocessingExecutor

# The module name includes a _-suffix to avoid name clashes with the standard library pickle module.

_T = TypeVar("_T")


Expand Down
2 changes: 1 addition & 1 deletion cluster_tools/cluster_tools/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Any, Dict, Optional, Type

from cluster_tools._utils import pickling
from cluster_tools._utils.string import with_preliminary_postfix
from cluster_tools._utils.string_ import with_preliminary_postfix
from cluster_tools.schedulers.cluster_executor import ClusterExecutor
from cluster_tools.schedulers.kube import KubernetesExecutor
from cluster_tools.schedulers.pbs import PBSExecutor
Expand Down
2 changes: 1 addition & 1 deletion cluster_tools/cluster_tools/schedulers/cluster_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
file_path_to_absolute_module,
get_function_name,
)
from cluster_tools._utils.string import random_string, with_preliminary_postfix
from cluster_tools._utils.string_ import random_string, with_preliminary_postfix
from cluster_tools._utils.tailf import Tail
from cluster_tools._utils.warning import enrich_future_with_uncaught_warning
from cluster_tools.executors.multiprocessing_ import CFutDict
Expand Down
2 changes: 1 addition & 1 deletion cluster_tools/cluster_tools/schedulers/pbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing_extensions import Literal

from cluster_tools._utils.call import call, chcall
from cluster_tools._utils.string import random_string
from cluster_tools._utils.string_ import random_string
from cluster_tools.schedulers.cluster_executor import ClusterExecutor

# qstat vs. checkjob
Expand Down
2 changes: 1 addition & 1 deletion cluster_tools/cluster_tools/schedulers/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from typing_extensions import Literal

from cluster_tools._utils.call import call, chcall
from cluster_tools._utils.string import random_string
from cluster_tools._utils.string_ import random_string
from cluster_tools.schedulers.cluster_executor import (
NOT_YET_SUBMITTED_STATE,
ClusterExecutor,
Expand Down
5 changes: 4 additions & 1 deletion cluster_tools/lint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env bash
set -eEuo pipefail

poetry run python -m pylint -j2 cluster_tools
# Pylint doesn't lint files in directories that don't have an __init__.py
# This is not fixed by the --recursive=y flag (https://github.com/PyCQA/pylint/issues/352)
# Inspired by https://stackoverflow.com/questions/4210042/how-to-exclude-a-directory-in-find-command
find cluster_tools -iname "*.py" | xargs poetry run python -m pylint -j2

0 comments on commit 12761b1

Please sign in to comment.