[yt-svn] commit/yt: mzingale: use try/except for creating the config directory and writing

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Apr 14 07:59:19 PDT 2017


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/4d27dc97e6a5/
Changeset:   4d27dc97e6a5
Branch:      yt
User:        mzingale
Date:        2017-04-13 19:35:55+00:00
Summary:     use try/except for creating the config directory and writing
the file.  on supercomputers, we don't always have access to
the home directory from the compute nodes, so the import of
yt fails.  This patch makes yt work at OLCF
Affected #:  1 file

diff -r 6092116f9fb53882a622814c5f37a0ea37b03509 -r 4d27dc97e6a5d4c84c2747b666246250bf13d51c yt/config.py
--- a/yt/config.py
+++ b/yt/config.py
@@ -75,7 +75,10 @@
 CONFIG_DIR = os.environ.get(
     'XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), '.config', 'yt'))
 if not os.path.exists(CONFIG_DIR):
-    os.makedirs(CONFIG_DIR)
+    try: 
+        os.makedirs(CONFIG_DIR)
+    except OSError:
+        warnings.warn("unable to create yt config directory")
 
 CURRENT_CONFIG_FILE = os.path.join(CONFIG_DIR, 'ytrc')
 _OLD_CONFIG_FILE = os.path.join(os.path.expanduser('~'), '.yt', 'config')
@@ -116,8 +119,11 @@
 if not os.path.exists(CURRENT_CONFIG_FILE):
     cp = configparser.ConfigParser()
     cp.add_section("yt")
-    with open(CURRENT_CONFIG_FILE, 'w') as new_cfg:
-        cp.write(new_cfg)
+    try:
+        with open(CURRENT_CONFIG_FILE, 'w') as new_cfg:
+            cp.write(new_cfg)
+    except IOError:
+        warnings.warn("unable to write new config file")
 
 class YTConfigParser(configparser.ConfigParser, object):
     def __setitem__(self, key, val):

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list