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

Use Config class to write config during init_project. #252

Merged
merged 4 commits into from
Dec 6, 2019
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 @@ -34,6 +34,7 @@ Fixed
+++++

- Attempting to create a linked view for a Project on Windows now raises an informative error message.
- Project configuration is initialized using ConfigObj, allowing the configuration to include commas and special characters (#251, #252).

Deprecated
++++++++++
Expand Down
11 changes: 6 additions & 5 deletions signac/contrib/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from ..core.jsondict import JSONDict
from ..core.h5store import H5StoreManager
from .collection import Collection
from ..common.config import load_config, Config
from ..common.config import get_config, load_config, Config
from ..sync import sync_projects
from .job import Job
from .hashing import calc_id
Expand Down Expand Up @@ -1461,10 +1461,11 @@ def init_project(cls, name, root=None, workspace=None, make_dir=True):
fn_config = os.path.join(root, 'signac.rc')
if make_dir:
_mkdir_p(os.path.dirname(fn_config))
with open(fn_config, 'a') as config_file:
config_file.write('project={}\n'.format(name))
if workspace is not None:
config_file.write('workspace_dir={}\n'.format(workspace))
config = get_config(fn_config)
config['project'] = name
if workspace is not None:
config['workspace_dir'] = workspace
config.write()
project = cls.get_project(root=root)
assert project.get_id() == str(name)
return project
Expand Down
9 changes: 9 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import itertools
import json
import pickle
import string
from tarfile import TarFile
from zipfile import ZipFile
from tempfile import TemporaryDirectory
Expand Down Expand Up @@ -1794,6 +1795,14 @@ def test_get_project(self):
self.assertEqual(project.workspace(), os.path.join(root, 'workspace'))
self.assertEqual(project.root_directory(), root)

def test_get_project_all_printable_characters(self):
root = self._tmp_dir.name
with self.assertRaises(LookupError):
signac.get_project(root=root)
project_name = 'testproject' + string.printable
project = signac.init_project(name=project_name, root=root)
self.assertEqual(project.get_id(), project_name)

def test_get_project_non_local(self):
root = self._tmp_dir.name
subdir = os.path.join(root, 'subdir')
Expand Down