Skip to content

Commit f30244c

Browse files
sort imports (#307)
- add hook - sort imports --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent b0ecd5c commit f30244c

File tree

78 files changed

+613
-388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+613
-388
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ repos:
2020
rev: 22.12.0
2121
hooks:
2222
- id: black-jupyter
23+
- repo: https://github.com/PyCQA/isort
24+
rev: 5.12.0
25+
hooks:
26+
- id: isort
27+
files: \.py$
2328
# numpydoc
2429
- repo: https://github.com/Carreau/velin
2530
rev: 0.0.12

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
#
1313
import os
14-
import sys
1514
import subprocess
15+
import sys
1616
from datetime import date
1717

1818
# sys.path.insert(0, os.path.abspath('.'))

dpdispatcher/__init__.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
2-
import os, sys
2+
import os
3+
import sys
34
import warnings
45

56
ROOT_PATH = tuple(__path__)[0]
@@ -39,24 +40,19 @@
3940
except ImportError:
4041
__version__ = "unkown"
4142

42-
from .submission import Submission
43-
from .submission import Task
44-
from .submission import Job
45-
from .submission import Resources
46-
from .slurm import Slurm
47-
from .pbs import PBS
48-
from .pbs import Torque
49-
from .shell import Shell
50-
from .lsf import LSF
51-
from .dp_cloud_server import DpCloudServer, Lebesgue
5243
from .distributed_shell import DistributedShell
53-
from .machine import Machine
54-
44+
from .dp_cloud_server import DpCloudServer, Lebesgue
45+
from .dp_cloud_server_context import DpCloudServerContext, LebesgueContext
46+
from .hdfs_context import HDFSContext
5547
from .lazy_local_context import LazyLocalContext
5648
from .local_context import LocalContext
49+
from .lsf import LSF
50+
from .machine import Machine
51+
from .pbs import PBS, Torque
52+
from .shell import Shell
53+
from .slurm import Slurm
5754
from .ssh_context import SSHContext
58-
from .dp_cloud_server_context import DpCloudServerContext, LebesgueContext
59-
from .hdfs_context import HDFSContext
55+
from .submission import Job, Resources, Submission, Task
6056

6157

6258
def info():

dpdispatcher/arginfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from dpdispatcher.submission import Resources, Task
21
from dpdispatcher.machine import Machine
2+
from dpdispatcher.submission import Resources, Task
33

44
resources_dargs = Resources.arginfo
55
machine_dargs = Machine.arginfo

dpdispatcher/base_context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from abc import ABCMeta, abstractmethod
2-
from dargs import Argument
32
from typing import List, Optional, Tuple
43

4+
from dargs import Argument
5+
56
from dpdispatcher import dlog
67

78

dpdispatcher/distributed_shell.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from dpdispatcher.JobStatus import JobStatus
1+
import subprocess as sp
2+
23
from dpdispatcher import dlog
4+
from dpdispatcher.JobStatus import JobStatus
35
from dpdispatcher.machine import Machine
46
from dpdispatcher.utils import run_cmd_with_all_output
5-
import subprocess as sp
6-
77

88
shell_script_header_template = """
99
#!/bin/bash -l

dpdispatcher/dp_cloud_server.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
import warnings
66

77
from dpdispatcher import dlog
8-
from dpdispatcher.JobStatus import JobStatus
9-
from dpdispatcher.dpcloudserver import zip_file
10-
from dpdispatcher.dpcloudserver import Client
8+
from dpdispatcher.dpcloudserver import Client, zip_file
119
from dpdispatcher.dpcloudserver.config import ALI_OSS_BUCKET_URL
10+
from dpdispatcher.JobStatus import JobStatus
1211
from dpdispatcher.machine import Machine
1312

1413
shell_script_header_template = """

dpdispatcher/dp_cloud_server_context.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33
# %%
4+
import os
5+
import shutil
46
import time
57
import uuid
8+
from typing import List
69

10+
import tqdm
711
from dargs.dargs import Argument
8-
from dpdispatcher.base_context import BaseContext
9-
from typing import List
10-
import os
12+
1113
from dpdispatcher import dlog
14+
from dpdispatcher.base_context import BaseContext
1215

1316
# from dpdispatcher.submission import Machine
1417
# from . import dlog
15-
from .dpcloudserver import Client
16-
from .dpcloudserver import zip_file
17-
import shutil
18-
import tqdm
18+
from .dpcloudserver import Client, zip_file
1919

2020
# from zip_file import zip_files
2121
from .dpcloudserver.config import ALI_OSS_BUCKET_URL

dpdispatcher/dpcloudserver/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import re
44
import time
55
import urllib.parse
6-
import requests
7-
from .retcode import RETCODE
8-
from .config import HTTP_TIME_OUT, API_HOST, API_LOGGER_STACK_INFO
96
from urllib.parse import urljoin
107

8+
import requests
9+
1110
from dpdispatcher import dlog
1211

12+
from .config import API_HOST, API_LOGGER_STACK_INFO, HTTP_TIME_OUT
13+
from .retcode import RETCODE
14+
1315
try:
1416
import oss2
1517
from oss2 import SizedFileAdapter, determine_part_size

dpdispatcher/dpcloudserver/temp_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#%%
22
import os
33
import sys
4-
import uuid
54
import unittest
5+
import uuid
66

77
from dpdispatcher.dpcloudserver import api
88
from dpdispatcher.dpcloudserver.zip_file import zip_files

dpdispatcher/dpcloudserver/zip_file.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import os, glob
1+
import glob
2+
import os
23
from zipfile import ZipFile
34

45
# def zip_file_list(root_path, zip_filename, file_list=[]):

dpdispatcher/hdfs_cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import os
55
import sys
6+
67
from dpdispatcher.utils import run_cmd_with_all_output
78

89

dpdispatcher/hdfs_context.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
from dpdispatcher.base_context import BaseContext
2-
import os, shutil, hashlib, tarfile
1+
import hashlib
2+
import os
3+
import shutil
4+
import tarfile
35
from glob import glob
6+
47
from dpdispatcher import dlog
8+
from dpdispatcher.base_context import BaseContext
59
from dpdispatcher.hdfs_cli import HDFS
610

711

dpdispatcher/lazy_local_context.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from dpdispatcher.base_context import BaseContext
2-
import os, signal
1+
import os
2+
import signal
33
import subprocess as sp
44

5+
from dpdispatcher.base_context import BaseContext
6+
57

68
class SPRetObj(object):
79
def __init__(self, ret):

dpdispatcher/local_context.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
from dpdispatcher.base_context import BaseContext
2-
import os, shutil, hashlib, signal
1+
import hashlib
2+
import os
3+
import shutil
4+
import signal
35
import subprocess as sp
46
from glob import glob
5-
from dpdispatcher import dlog
67
from subprocess import TimeoutExpired
78

9+
from dpdispatcher import dlog
10+
from dpdispatcher.base_context import BaseContext
11+
812

913
class SPRetObj(object):
1014
def __init__(self, ret):

dpdispatcher/lsf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33

44
from dargs import Argument
55

6-
from dpdispatcher.machine import Machine
76
from dpdispatcher import dlog
87
from dpdispatcher.JobStatus import JobStatus
9-
from dpdispatcher.utils import retry, RetrySignal
10-
8+
from dpdispatcher.machine import Machine
9+
from dpdispatcher.utils import RetrySignal, retry
1110

1211
lsf_script_header_template = """\
1312
#!/bin/bash -l

dpdispatcher/machine.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import json
2-
import shlex
32
import pathlib
3+
import shlex
44
from abc import ABCMeta, abstractmethod
55
from typing import List, Optional, Tuple
66

77
from dargs import Argument, Variant
8+
89
from dpdispatcher import dlog
910
from dpdispatcher.base_context import BaseContext
1011

dpdispatcher/pbs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import shlex
22

3-
from dpdispatcher.JobStatus import JobStatus
43
from dpdispatcher import dlog
4+
from dpdispatcher.JobStatus import JobStatus
55
from dpdispatcher.machine import Machine
66

7-
87
pbs_script_header_template = """
98
#!/bin/bash -l
109
{select_node_line}

dpdispatcher/shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import shlex
22

3-
from dpdispatcher.JobStatus import JobStatus
43
from dpdispatcher import dlog
4+
from dpdispatcher.JobStatus import JobStatus
55
from dpdispatcher.machine import Machine
66

77
shell_script_header_template = """

dpdispatcher/slurm.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
from dargs import Argument
66

7-
from dpdispatcher.machine import Machine
8-
from dpdispatcher.JobStatus import JobStatus
97
from dpdispatcher import dlog
10-
from dpdispatcher.machine import script_command_template
11-
from dpdispatcher.utils import retry, RetrySignal
8+
from dpdispatcher.JobStatus import JobStatus
9+
from dpdispatcher.machine import Machine, script_command_template
10+
from dpdispatcher.utils import RetrySignal, retry
1211

1312
# from dpdispatcher.submission import Resources
1413

dpdispatcher/ssh_context.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4-
import os, paramiko, tarfile, time
5-
import uuid
6-
import shutil
4+
import os
75
import pathlib
8-
import socket
96
import shlex
7+
import shutil
8+
import socket
9+
import tarfile
10+
import time
11+
import uuid
1012
from functools import lru_cache
1113
from glob import glob
1214
from typing import List
1315

16+
import paramiko
1417
import paramiko.ssh_exception
1518
from dargs.dargs import Argument
1619

17-
from dpdispatcher.base_context import BaseContext
1820
from dpdispatcher import dlog
21+
from dpdispatcher.base_context import BaseContext
1922

2023
# from dpdispatcher.submission import Machine
21-
from dpdispatcher.utils import (
22-
get_sha256,
23-
generate_totp,
24-
rsync,
25-
retry,
26-
RetrySignal,
27-
)
24+
from dpdispatcher.utils import RetrySignal, generate_totp, get_sha256, retry, rsync
2825

2926

3027
class SSHSession(object):

dpdispatcher/submission.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# %%
2-
import time, random, uuid, json, copy, os
3-
from dargs.dargs import Argument, Variant
4-
from dpdispatcher.JobStatus import JobStatus
5-
from dpdispatcher import dlog
2+
import copy
3+
import json
4+
import os
5+
import random
6+
import time
7+
import uuid
68
from hashlib import sha1
79

10+
from dargs.dargs import Argument, Variant
11+
12+
from dpdispatcher import dlog
13+
from dpdispatcher.JobStatus import JobStatus
814
from dpdispatcher.machine import Machine
915

1016
# from dpdispatcher.slurm import SlurmResources
@@ -318,7 +324,8 @@ def remove_unfinished_jobs(self):
318324
dlog.info("Can not kill job %s" % job.job_id)
319325

320326
# remove unfinished tasks
321-
import os, shutil
327+
import os
328+
import shutil
322329

323330
for task in job.job_task_list:
324331
shutil.rmtree(

dpdispatcher/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import base64
12
import hashlib
2-
import time
3-
import struct
43
import hmac
5-
import base64
4+
import struct
65
import subprocess
7-
from typing import Iterable, Optional, Callable, Type, Union
6+
import time
7+
from typing import Callable, Iterable, Optional, Type, Union
88

99
from dpdispatcher import dlog
1010

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ write_to = "dpdispatcher/_version.py"
6161
[tool.pyright]
6262
include = ['dpdispatcher']
6363
exclude = ['dpdispatcher/dpcloudserver/temp_test.py']
64+
65+
[tool.isort]
66+
profile = "black"

scripts/script_gen_dargs_docs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
# import sys, os
33
# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..' )))
44
# import dpdispatcher
5-
from dpdispatcher.submission import Resources, Task
65
from dpdispatcher.machine import Machine
7-
6+
from dpdispatcher.submission import Resources, Task
87

98
# %%
109
resources_dargs_doc = Resources.arginfo().gen_doc()

0 commit comments

Comments
 (0)