Skip to content

fix: do not create a nipype folder in the home directory by default #2076

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

Merged
merged 2 commits into from
Jun 15, 2017
Merged
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
25 changes: 7 additions & 18 deletions nipype/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,11 @@ class NipypeConfig(object):
def __init__(self, *args, **kwargs):
self._config = configparser.ConfigParser()
config_dir = os.path.expanduser('~/.nipype')
mkdir_p(config_dir)
old_config_file = os.path.expanduser('~/.nipype.cfg')
new_config_file = os.path.join(config_dir, 'nipype.cfg')
# To be deprecated in two releases
if os.path.exists(old_config_file):
if os.path.exists(new_config_file):
msg = ("Detected presence of both old (%s, used by versions "
"< 0.5.2) and new (%s) config files. This version will "
"proceed with the new one. We advise to merge settings "
"and remove old config file if you are not planning to "
"use previous releases of nipype.") % (old_config_file,
new_config_file)
warn(msg)
else:
warn("Moving old config file from: %s to %s" % (old_config_file,
new_config_file))
shutil.move(old_config_file, new_config_file)
config_file = os.path.join(config_dir, 'nipype.cfg')
self.data_file = os.path.join(config_dir, 'nipype.json')
self._config.readfp(StringIO(default_cfg))
self._config.read([new_config_file, old_config_file, 'nipype.cfg'])
if os.path.exists(config_dir):
self._config.read([config_file, 'nipype.cfg'])

def set_default_config(self):
self._config.readfp(StringIO(default_cfg))
Expand Down Expand Up @@ -164,6 +149,10 @@ def save_data(self, key, value):
with open(self.data_file, 'rt') as file:
portalocker.lock(file, portalocker.LOCK_EX)
datadict = load(file)
else:
dirname = os.path.dirname(self.data_file)
if not os.path.exists(dirname):
mkdir_p(dirname)
with open(self.data_file, 'wt') as file:
portalocker.lock(file, portalocker.LOCK_EX)
datadict[key] = value
Expand Down