Skip to content

Commit

Permalink
Access project from job (#808)
Browse files Browse the repository at this point in the history
* First pass

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Initialize job

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update tests/test_job.py

* Add test for custom Project subclass.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix test.

* Update changelog and contributors

* Formatting

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hardik Ojha <44747868+kidrahahjo@users.noreply.github.com>
Co-authored-by: Bradley Dice <bdice@bradleydice.com>
  • Loading branch information
4 people committed Aug 30, 2022
1 parent b4d6512 commit c7a233a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Version 2

Added
+++++

- ``H5Store`` related errors are now included in the public API (#775).
- Users can now access the project which a job belongs to from the job object.

Changed
+++++++
Expand Down
4 changes: 4 additions & 0 deletions contributors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,8 @@ contributors:
family-names: Takada
given-names: Kody
affiliation: "University of Michigan"
-
family-names: Kadar
given-names: Alain
affiliation: "University of Michigan"
...
1 change: 1 addition & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ The Job class
Job.move
Job.open
Job.path
Job.project
Job.remove
Job.reset
Job.sp
Expand Down
11 changes: 11 additions & 0 deletions signac/contrib/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,17 @@ def data(self, new_data):
"""
self.stores[self.KEY_DATA] = new_data

@property
def project(self):
"""Get the project that contains this job.
Returns
-------
signac.Project
Returns the project containing this job.
"""
return self._project

def init(self, force=False):
"""Initialize the job's workspace directory.
Expand Down
17 changes: 17 additions & 0 deletions tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,23 @@ def test_deepcopy(self):
copied_job.sp.a = 3
assert copied_job in self.project

def test_project_access_from_job(self):
job = self.project.open_job({"a": 0}).init()
assert isinstance(job.project, signac.Project)
assert job in job.project
assert job.project.path == self._tmp_pr

def test_custom_project_access_from_job(self):
# Test a custom project subclass to ensure compatibility with signac-flow's FlowProject
class CustomProject(signac.Project):
pass

custom_project = CustomProject.get_project(self._tmp_pr)
job = custom_project.open_job({"a": 0}).init()
assert isinstance(job.project, CustomProject)
assert job in job.project
assert job.project.path == self._tmp_pr


class TestJobSpInterface(TestJobBase):
def test_interface_read_only(self):
Expand Down

0 comments on commit c7a233a

Please sign in to comment.