Skip to content

Commit 22025bf

Browse files
committed
linting
1 parent b1a93bc commit 22025bf

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

Diff for: src/atomate2/abinit/run.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def run_mrgddb(
9999
open(LOG_FILE_NAME, "w") as stdout,
100100
open(STDERR_FILE_NAME, "w") as stderr,
101101
):
102-
process = subprocess.Popen(command, stdin=stdin, stdout=stdout, stderr=stderr) # noqa: S603
102+
process = subprocess.Popen(command, stdin=stdin, stdout=stdout, stderr=stderr)
103103

104104
if wall_time is not None:
105105
while True:
@@ -146,7 +146,7 @@ def run_anaddb(
146146
open(STDERR_FILE_NAME, "w") as stderr,
147147
):
148148
# process = subprocess.Popen(command, stdin=stdin, stdout=stdout, stderr=stderr)
149-
process = subprocess.Popen(command, stdout=stdout, stderr=stderr) # noqa: S603
149+
process = subprocess.Popen(command, stdout=stdout, stderr=stderr)
150150

151151
if wall_time is not None:
152152
while True:

Diff for: src/atomate2/abinit/schemas/outfiles.py

+34-19
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import os
1+
"""Class to store the raw data of Abinit files."""
2+
23
import base64
3-
from monty.json import MSONable
4-
from typing import TYPE_CHECKING
4+
import os
55
from pathlib import Path
6+
7+
from monty.json import MSONable
68
from typing_extensions import Self
79

10+
811
class AbinitStoredFile(MSONable):
912
"""Wrap a file to store its raw data."""
1013

@@ -13,57 +16,69 @@ def __init__(self, data: str | bytes, source_filepath: str | Path) -> None:
1316
self.source_filepath = source_filepath
1417

1518
def as_dict(self) -> dict:
16-
data = base64.b64encode(self.data).decode('ascii') if self.data_type == "bytes" else self.data
17-
19+
"""Return a dict of the stored file."""
20+
data = (
21+
base64.b64encode(self.data).decode("ascii")
22+
if isinstance(self.data, bytes)
23+
else self.data
24+
)
25+
1826
return {
1927
"@module": self.__class__.__module__,
2028
"@class": self.__class__.__name__,
2129
"data": data,
2230
"data_type": self.data_type,
2331
"source_filepath": self.source_filepath,
24-
}
32+
}
2533

2634
@classmethod
2735
def from_dict(cls, d: dict) -> Self:
36+
"""Create an AbinitStoredFile from a dict."""
2837
data_type = d["data_type"]
2938
data = base64.b64decode(d["data"]) if data_type == "bytes" else d["data"]
3039
return cls(data=data, source_filepath=d["source_filepath"])
3140

3241
@classmethod
3342
def from_file(cls, filepath: str | Path, data_type: str | type) -> Self:
43+
"""Create an AbinitStoredFile from the original file."""
3444
source_filepath = os.path.abspath(filepath)
35-
if data_type=="bytes" or data_type==bytes:
36-
read_type = 'rb'
37-
elif data_type=="str" or data_type==str:
38-
read_type = 'r'
45+
if data_type in {"bytes", bytes}:
46+
read_type = "rb"
47+
elif data_type in {"str", str}:
48+
read_type = "r"
3949
else:
4050
raise TypeError("data_type should be either bytes or str.")
4151
with open(source_filepath, read_type) as f:
4252
data = f.read()
43-
53+
4454
return cls(data=data, source_filepath=source_filepath)
4555

4656
@property
4757
def data_type(self) -> str:
58+
"""Return the type of the data."""
4859
return type(self.data).__name__
4960

5061
@property
5162
def filename(self) -> str:
63+
"""Return the name of the source file."""
5264
return os.path.basename(self.source_filepath)
5365

5466
@property
5567
def extension(self) -> str:
56-
return self.source_filepath.split("_")[-1]
68+
"""Return the extension of the source file."""
69+
return str(self.source_filepath).split("_")[-1]
5770

58-
def write(self, filepath: str | Path=None) -> None:
71+
def write(self, filepath: str | Path = None) -> None:
72+
"""Write the data into a file."""
5973
filepath = filepath or self.filename
60-
out_type = self.data_type[0]
61-
if self.data_type == 'bytes':
62-
write_type = 'wb'
74+
if self.data_type == "bytes":
75+
write_type = "wb"
6376
elif self.data_type == "str":
64-
write_type = 'w'
77+
write_type = "w"
6578
else:
66-
raise TypeError("The data type is neither bytes nor string,\
67-
does it make sense to write it into a file?")
79+
raise TypeError(
80+
"The data type is neither bytes nor string,\
81+
does it make sense to write it into a file?"
82+
)
6883
with open(filepath, write_type) as f:
6984
f.write(self.data)

0 commit comments

Comments
 (0)