Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored internal use of get_statepoints #282

Merged
merged 11 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Changed

- Workspace directory is created when ``Project`` is initialized (#267, #271).
- Changed testing framework from ``unittest`` to ``pytest`` (#212, #275).
- Refactored internal use of deprecated ``get_statepoint`` function (#227, #282).


Fixed
Expand Down
64 changes: 36 additions & 28 deletions signac/contrib/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def open_job(self, statepoint=None, id=None):
id = matches[0]
elif len(matches) > 1:
raise LookupError(id)
return self.Job(project=self, statepoint=self.get_statepoint(id), _id=id)
return self.Job(project=self, statepoint=self._get_statepoint(id), _id=id)

def _job_dirs(self):
try:
Expand Down Expand Up @@ -778,7 +778,7 @@ def write_statepoints(self, statepoints=None, fn=None, indent=2):
tmp = dict()
if statepoints is None:
job_ids = self._job_dirs()
_cache = {_id: self.get_statepoint(_id) for _id in job_ids}
_cache = {_id: self._get_statepoint(_id) for _id in job_ids}
else:
_cache = {calc_id(sp): sp for sp in statepoints}

Expand All @@ -805,32 +805,11 @@ def _get_statepoint_from_workspace(self, jobid):
raise JobsCorruptedError([jobid])
raise KeyError(jobid)

@deprecated(deprecated_in="1.3", removed_in="2.0", current_version=__version__,
details="Use open_job(id=jobid).statepoint() function instead.")
def get_statepoint(self, jobid, fn=None):
def _get_statepoint(self, jobid, fn=None):
"""Get the statepoint associated with a job id.

The state point is retrieved from the internal cache, from
the workspace or from a state points file.

:param jobid:
A job id to get the statepoint for.
:type jobid:
str
:param fn:
The filename of the file containing the statepoints, defaults
to :const:`~signac.contrib.project.FN_STATEPOINTS`.
:type fn:
str
:return:
The state point corresponding to jobid.
:rtype:
dict
:raises KeyError:
If the state point associated with jobid could not be found.
:raises JobsCorruptedError:
If the state point manifest file corresponding to jobid is
inaccessible or corrupted.
"""
if not self._sp_cache:
self._read_cache()
Expand All @@ -857,6 +836,35 @@ def get_statepoint(self, jobid, fn=None):
self._sp_cache[jobid] = sp
return sp

@deprecated(deprecated_in="1.3", removed_in="2.0", current_version=__version__,
details="Use open_job(id=jobid).statepoint() function instead.")
def get_statepoint(self, jobid, fn=None):
"""Get the statepoint associated with a job id.

The state point is retrieved from the internal cache, from
the workspace or from a state points file.

:param jobid:
A job id to get the statepoint for.
:type jobid:
str
:param fn:
The filename of the file containing the statepoints, defaults
to :const:`~signac.contrib.project.FN_STATEPOINTS`.
:type fn:
str
:return:
The state point corresponding to jobid.
:rtype:
dict
:raises KeyError:
If the state point associated with jobid could not be found.
:raises JobsCorruptedError:
If the state point manifest file corresponding to jobid is
inaccessible or corrupted.
"""
return self._get_statepoint(jobid=jobid, fn=fn)

def create_linked_view(self, prefix=None, job_ids=None, index=None, path=None):
"""Create or update a persistent linked view of the selected data space.

Expand Down Expand Up @@ -1171,7 +1179,7 @@ def check(self):
logger.info("Checking workspace for corruption...")
for job_id in self._find_job_ids():
try:
sp = self.get_statepoint(job_id)
sp = self._get_statepoint(job_id)
if calc_id(sp) != job_id:
corrupted.append(job_id)
else:
Expand Down Expand Up @@ -1220,7 +1228,7 @@ def repair(self, fn_statepoints=None, index=None, job_ids=None):
for job_id in job_ids:
try:
# First, check if we can look up the state point.
sp = self.get_statepoint(job_id)
sp = self._get_statepoint(job_id)
# Check if state point and id correspond.
correct_id = calc_id(sp)
if correct_id != job_id:
Expand Down Expand Up @@ -1272,7 +1280,7 @@ def _sp_index(self):
for _id in to_remove:
del self._index_cache[_id]
for _id in to_add:
self._index_cache[_id] = dict(statepoint=self.get_statepoint(_id), _id=_id)
self._index_cache[_id] = dict(statepoint=self._get_statepoint(_id), _id=_id)
return self._index_cache.values()

def _build_index(self, include_job_document=False):
Expand All @@ -1281,7 +1289,7 @@ def _build_index(self, include_job_document=False):
"""
wd = self.workspace() if self.Job is Job else None
for _id in self._find_job_ids():
doc = dict(_id=_id, statepoint=self.get_statepoint(_id))
doc = dict(_id=_id, statepoint=self._get_statepoint(_id))
if include_job_document:
if wd is None:
doc.update(self.open_job(id=_id).document)
Expand Down