Skip to content

Commit 3b94954

Browse files
committed
add ruff formatter
1 parent 5f3db0e commit 3b94954

20 files changed

+405
-279
lines changed

.ci_support/release.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
def get_setup_version_and_pattern(setup_content):
22
depend_lst, version_lst = [], []
33
for l in setup_content:
4-
if '==' in l:
5-
lst = l.split('[')[-1].split(']')[0].replace(' ', '').replace('"', '').replace("'", '').split(',')
4+
if "==" in l:
5+
lst = (
6+
l.split("[")[-1]
7+
.split("]")[0]
8+
.replace(" ", "")
9+
.replace('"', "")
10+
.replace("'", "")
11+
.split(",")
12+
)
613
for dep in lst:
7-
if dep != '\n':
8-
version_lst.append(dep.split('==')[1])
9-
depend_lst.append(dep.split('==')[0])
14+
if dep != "\n":
15+
version_lst.append(dep.split("==")[1])
16+
depend_lst.append(dep.split("==")[0])
1017

1118
version_high_dict = {d: v for d, v in zip(depend_lst, version_lst)}
1219
return version_high_dict
@@ -16,14 +23,14 @@ def get_env_version(env_content):
1623
read_flag = False
1724
depend_lst, version_lst = [], []
1825
for l in env_content:
19-
if 'dependencies:' in l:
26+
if "dependencies:" in l:
2027
read_flag = True
2128
elif read_flag:
22-
lst = l.replace('-', '').replace(' ', '').replace('\n', '').split("=")
29+
lst = l.replace("-", "").replace(" ", "").replace("\n", "").split("=")
2330
if len(lst) == 2:
2431
depend_lst.append(lst[0])
2532
version_lst.append(lst[1])
26-
return {d:v for d, v in zip(depend_lst, version_lst)}
33+
return {d: v for d, v in zip(depend_lst, version_lst)}
2734

2835

2936
def update_dependencies(setup_content, version_low_dict, version_high_dict):
@@ -35,27 +42,29 @@ def update_dependencies(setup_content, version_low_dict, version_high_dict):
3542
version_combo_dict[dep] = dep + "==" + ver
3643

3744
setup_content_new = ""
38-
pattern_dict = {d:d + "==" + v for d, v in version_high_dict.items()}
45+
pattern_dict = {d: d + "==" + v for d, v in version_high_dict.items()}
3946
for l in setup_content:
4047
for k, v in pattern_dict.items():
4148
if v in l:
4249
l = l.replace(v, version_combo_dict[k])
43-
setup_content_new +=l
50+
setup_content_new += l
4451
return setup_content_new
4552

4653

4754
if __name__ == "__main__":
48-
with open('pyproject.toml', "r") as f:
55+
with open("pyproject.toml", "r") as f:
4956
setup_content = f.readlines()
5057

51-
with open('environment.yml', "r") as f:
58+
with open("environment.yml", "r") as f:
5259
env_content = f.readlines()
5360

5461
setup_content_new = update_dependencies(
5562
setup_content=setup_content[2:],
5663
version_low_dict=get_env_version(env_content=env_content),
57-
version_high_dict=get_setup_version_and_pattern(setup_content=setup_content[2:]),
64+
version_high_dict=get_setup_version_and_pattern(
65+
setup_content=setup_content[2:]
66+
),
5867
)
5968

60-
with open('pyproject.toml', "w") as f:
69+
with open("pyproject.toml", "w") as f:
6170
f.writelines("".join(setup_content[:2]) + setup_content_new)

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.4.4
4+
hooks:
5+
- id: ruff
6+
name: ruff lint
7+
args: ["--fix"]
8+
files: ^pysqa/
9+
- id: ruff-format
10+
name: ruff format

pysqa/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
from ._version import get_versions
44

5+
__all__ = [QueueAdapter]
56
__version__ = get_versions()["version"]

pysqa/executor/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from pysqa.executor.executor import Executor
2+
3+
__all__ = [Executor]

pysqa/wrapper/lsf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def convert_queue_status(queue_status_output: str) -> pandas.DataFrame:
4040
job_id_lst, user_lst, status_lst, job_name_lst = [], [], [], []
4141
line_split_lst = queue_status_output.split("\n")
4242
if len(line_split_lst) > 1:
43-
for l in line_split_lst[1:]:
44-
line_segments = l.split()
43+
for line in line_split_lst[1:]:
44+
line_segments = line.split()
4545
if len(line_segments) > 1:
4646
job_id_lst.append(int(line_segments[0]))
4747
user_lst.append(line_segments[1])

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
setup(
66
version=versioneer.get_version(),
77
cmdclass=versioneer.get_cmdclass(),
8-
)
8+
)

tests/test_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_memory_string_comparison(self):
6464
)
6565
self.assertEqual(
6666
BasisQueueAdapter._value_in_range(
67-
90000 * 1024 ** 2, value_min="1K", value_max="70G"
67+
90000 * 1024**2, value_min="1K", value_max="70G"
6868
),
6969
"70G",
7070
)

tests/test_cmd.py

Lines changed: 89 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ class TestCMD(unittest.TestCase):
1111
def setUpClass(cls):
1212
cls.test_dir = os.path.abspath(os.path.dirname(__file__))
1313

14-
@unittest.mock.patch('sys.stdout', new_callable=io.StringIO)
15-
def assert_stdout_command_line(self, cmd_args, execute_command, expected_output, mock_stdout):
16-
command_line(
17-
arguments_lst=cmd_args,
18-
execute_command=execute_command
19-
)
14+
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
15+
def assert_stdout_command_line(
16+
self, cmd_args, execute_command, expected_output, mock_stdout
17+
):
18+
command_line(arguments_lst=cmd_args, execute_command=execute_command)
2019
self.assertEqual(mock_stdout.getvalue(), expected_output)
2120

2221
def test_help(self):
@@ -45,33 +44,41 @@ def execute_command(
4544

4645
self.assert_stdout_command_line(
4746
[
48-
"--config_directory", os.path.join(self.test_dir, "config", "slurm"),
47+
"--config_directory",
48+
os.path.join(self.test_dir, "config", "slurm"),
4949
"--submit",
50-
"--queue", "slurm",
51-
"--job_name", "test",
52-
"--working_directory", ".",
53-
"--cores", "2",
54-
"--memory", "1GB",
55-
"--run_time", "10",
56-
"--command", "echo hello"
50+
"--queue",
51+
"slurm",
52+
"--job_name",
53+
"test",
54+
"--working_directory",
55+
".",
56+
"--cores",
57+
"2",
58+
"--memory",
59+
"1GB",
60+
"--run_time",
61+
"10",
62+
"--command",
63+
"echo hello",
5764
],
5865
execute_command,
5966
"1\n",
6067
)
6168
with open("run_queue.sh") as f:
6269
output = f.readlines()
6370
content = [
64-
'#!/bin/bash\n',
65-
'#SBATCH --output=time.out\n',
66-
'#SBATCH --job-name=test\n',
67-
'#SBATCH --chdir=.\n',
68-
'#SBATCH --get-user-env=L\n',
69-
'#SBATCH --partition=slurm\n',
70-
'#SBATCH --time=4320\n',
71-
'#SBATCH --mem=1GBG\n',
72-
'#SBATCH --cpus-per-task=10\n',
73-
'\n',
74-
'echo hello'
71+
"#!/bin/bash\n",
72+
"#SBATCH --output=time.out\n",
73+
"#SBATCH --job-name=test\n",
74+
"#SBATCH --chdir=.\n",
75+
"#SBATCH --get-user-env=L\n",
76+
"#SBATCH --partition=slurm\n",
77+
"#SBATCH --time=4320\n",
78+
"#SBATCH --mem=1GBG\n",
79+
"#SBATCH --cpus-per-task=10\n",
80+
"\n",
81+
"echo hello",
7582
]
7683
self.assertEqual(output, content)
7784
os.remove("run_queue.sh")
@@ -88,12 +95,14 @@ def execute_command(
8895

8996
self.assert_stdout_command_line(
9097
[
91-
"--config_directory", os.path.join(self.test_dir, "config", "slurm"),
98+
"--config_directory",
99+
os.path.join(self.test_dir, "config", "slurm"),
92100
"--delete",
93-
"--id", "1"
101+
"--id",
102+
"1",
94103
],
95104
execute_command,
96-
"S\n"
105+
"S\n",
97106
)
98107

99108
def test_status(self):
@@ -104,27 +113,40 @@ def execute_command(
104113
shell=False,
105114
error_filename="pysqa.err",
106115
):
107-
with open(os.path.join(self.test_dir, "config", "slurm", "squeue_output")) as f:
116+
with open(
117+
os.path.join(self.test_dir, "config", "slurm", "squeue_output")
118+
) as f:
108119
return f.read()
109120

110121
self.assert_stdout_command_line(
111122
[
112-
"--config_directory", os.path.join(self.test_dir, "config", "slurm"),
113-
"--status"
123+
"--config_directory",
124+
os.path.join(self.test_dir, "config", "slurm"),
125+
"--status",
114126
],
115127
execute_command,
116-
json.dumps({
117-
"jobid": [5322019, 5322016, 5322017, 5322018, 5322013], "user": ["janj", "janj", "janj", "janj", "maxi"],
118-
"jobname": ["pi_19576488", "pi_19576485", "pi_19576486", "pi_19576487", "pi_19576482"],
119-
"status": ["running", "running", "running", "running", "running"],
120-
"working_directory": [
121-
"/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_1",
122-
"/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_2",
123-
"/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_3",
124-
"/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_4",
125-
"/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_5"
126-
]
127-
}) +"\n"
128+
json.dumps(
129+
{
130+
"jobid": [5322019, 5322016, 5322017, 5322018, 5322013],
131+
"user": ["janj", "janj", "janj", "janj", "maxi"],
132+
"jobname": [
133+
"pi_19576488",
134+
"pi_19576485",
135+
"pi_19576486",
136+
"pi_19576487",
137+
"pi_19576482",
138+
],
139+
"status": ["running", "running", "running", "running", "running"],
140+
"working_directory": [
141+
"/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_1",
142+
"/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_2",
143+
"/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_3",
144+
"/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_4",
145+
"/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_5",
146+
],
147+
}
148+
)
149+
+ "\n",
128150
)
129151

130152
def test_list(self):
@@ -139,19 +161,31 @@ def execute_command(
139161

140162
self.assert_stdout_command_line(
141163
[
142-
"--config_directory", os.path.join(self.test_dir, "config", "slurm"),
164+
"--config_directory",
165+
os.path.join(self.test_dir, "config", "slurm"),
143166
"--list",
144-
"--working_directory", os.path.join(self.test_dir, "config", "slurm"),
145-
167+
"--working_directory",
168+
os.path.join(self.test_dir, "config", "slurm"),
146169
],
147170
execute_command,
148-
json.dumps({
149-
"dirs": [os.path.join(self.test_dir, "config", "slurm")],
150-
"files": sorted([
151-
os.path.join(self.test_dir, "config", "slurm", "squeue_output"),
152-
os.path.join(self.test_dir, "config", "slurm", "slurm_extra.sh"),
153-
os.path.join(self.test_dir, "config", "slurm", "slurm.sh"),
154-
os.path.join(self.test_dir, "config", "slurm", "queue.yaml"),
155-
])
156-
}) + "\n"
171+
json.dumps(
172+
{
173+
"dirs": [os.path.join(self.test_dir, "config", "slurm")],
174+
"files": sorted(
175+
[
176+
os.path.join(
177+
self.test_dir, "config", "slurm", "squeue_output"
178+
),
179+
os.path.join(
180+
self.test_dir, "config", "slurm", "slurm_extra.sh"
181+
),
182+
os.path.join(self.test_dir, "config", "slurm", "slurm.sh"),
183+
os.path.join(
184+
self.test_dir, "config", "slurm", "queue.yaml"
185+
),
186+
]
187+
),
188+
}
189+
)
190+
+ "\n",
157191
)

tests/test_execute_command.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,47 @@ def test_commands_as_lst(self):
1010
working_directory=".",
1111
split_output=True,
1212
shell=False,
13-
error_filename="pysqa.err"
13+
error_filename="pysqa.err",
1414
)
15-
self.assertEqual(output, ['hello', ''])
15+
self.assertEqual(output, ["hello", ""])
1616

1717
def test_commands_as_lst_no_split(self):
1818
output = execute_command(
1919
commands=["echo", "hello"],
2020
working_directory=".",
2121
split_output=False,
2222
shell=False,
23-
error_filename="pysqa.err"
23+
error_filename="pysqa.err",
2424
)
25-
self.assertEqual(output, 'hello\n')
25+
self.assertEqual(output, "hello\n")
2626

2727
def test_commands_as_lst_shell_true(self):
2828
output = execute_command(
2929
commands=["echo", "hello"],
3030
working_directory=".",
3131
split_output=True,
3232
shell=True,
33-
error_filename="pysqa.err"
33+
error_filename="pysqa.err",
3434
)
35-
self.assertEqual(output, ['hello', ''])
35+
self.assertEqual(output, ["hello", ""])
3636

3737
def test_commands_as_str(self):
3838
output = execute_command(
3939
commands="echo hello",
4040
working_directory=".",
4141
split_output=True,
4242
shell=False,
43-
error_filename="pysqa.err"
43+
error_filename="pysqa.err",
4444
)
45-
self.assertEqual(output, ['hello', ''])
45+
self.assertEqual(output, ["hello", ""])
4646

4747
def test_commands_fails(self):
4848
output = execute_command(
4949
commands="exit 1",
5050
working_directory=".",
5151
split_output=True,
5252
shell=False,
53-
error_filename="pysqa_fails.err"
53+
error_filename="pysqa_fails.err",
5454
)
5555
self.assertIsNone(output)
5656
with open("pysqa_fails.err") as f:

0 commit comments

Comments
 (0)