Skip to content

Commit

Permalink
Merge 363bc7f into c1aa430
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen committed Mar 25, 2024
2 parents c1aa430 + 363bc7f commit 9f17088
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
17 changes: 14 additions & 3 deletions pyiron_base/jobs/job/extension/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,24 @@ def __getattr__(self, item):
raise FileNotFoundError(item) from None


class File(str):
class File:
__slots__ = ("_path",)

def __init__(self, path):
self._path = path

def __str__(self):
return self._path

def tail(self, lines: int = 100):
print(
*_working_directory_read_file(
working_directory=os.path.dirname(self),
file_name=os.path.basename(self),
working_directory=os.path.dirname(self._path),
file_name=os.path.basename(self._path),
tail=lines,
),
sep="",
)

def __eq__(self, other):
return self.__str__().__eq__(other)
9 changes: 7 additions & 2 deletions pyiron_base/jobs/job/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
_doc_str_job_core_attr,
)
from pyiron_base.jobs.job.extension.executable import Executable
from pyiron_base.jobs.job.extension.files import File
from pyiron_base.jobs.job.extension.jobstatus import JobStatus
from pyiron_base.jobs.job.runfunction import (
run_job_with_parameter_repair,
Expand Down Expand Up @@ -286,6 +287,8 @@ def restart_file_list(self, filenames):
filenames (list):
"""
for f in filenames:
if isinstance(f, File):
f = str(f)
if not (os.path.isfile(f)):
raise IOError("File: {} does not exist".format(f))
self.restart_file_list.append(f)
Expand All @@ -296,6 +299,8 @@ def restart_file_dict(self):
A dictionary of the new name of the copied restart files
"""
for actual_name in [os.path.basename(f) for f in self._restart_file_list]:
if isinstance(actual_name, File):
actual_name = str(actual_name)
if actual_name not in self._restart_file_dict.keys():
self._restart_file_dict[actual_name] = actual_name
return self._restart_file_dict
Expand Down Expand Up @@ -1043,8 +1048,8 @@ def to_dict(self):
data_dict = self._type_to_dict()
data_dict["status"] = self.status.string
data_dict["input/generic_dict"] = {
"restart_file_list": self._restart_file_list,
"restart_file_dict": self._restart_file_dict,
"restart_file_list": [str(f) for f in self._restart_file_list],
"restart_file_dict": {str(f): n for f, n in self._restart_file_dict.items()},
"exclude_nodes_hdf": self._exclude_nodes_hdf,
"exclude_groups_hdf": self._exclude_groups_hdf,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/flex/test_executablecontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_job_files(self):
if os.name != "nt":
self.assertEqual(job.files.error_out, output_file_path)
else:
self.assertEqual(job.files.error_out.replace("/", "\\"), output_file_path)
self.assertEqual(job.files.error_out, output_file_path.replace("\\", "/"))

def test_create_job_factory_typeerror(self):
create_catjob = create_job_factory(
Expand Down

0 comments on commit 9f17088

Please sign in to comment.