diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2019-09-16 23:04:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-16 23:04:21 (GMT) |
commit | 0048afc16a7e7301d5c565237db271505e5fbed9 (patch) | |
tree | 51784b04b971073163df417c8cc81dddc98e1480 /Lib/idlelib/config.py | |
parent | 81528ba2e81c39f4d6bca5b785e818c7d08b8501 (diff) | |
download | cpython-0048afc16a7e7301d5c565237db271505e5fbed9.zip cpython-0048afc16a7e7301d5c565237db271505e5fbed9.tar.gz cpython-0048afc16a7e7301d5c565237db271505e5fbed9.tar.bz2 |
bpo-38183: Test_idle ignores user config directory GH-16198)
It no longer tries to create or access .idlerc or any files within.
Users must run IDLE to discover problems with saving settings.
Diffstat (limited to 'Lib/idlelib/config.py')
-rw-r--r-- | Lib/idlelib/config.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/Lib/idlelib/config.py b/Lib/idlelib/config.py index 683b000..12e6f9f 100644 --- a/Lib/idlelib/config.py +++ b/Lib/idlelib/config.py @@ -130,7 +130,7 @@ class IdleUserConfParser(IdleConfParser): to disk. Otherwise, remove the file from disk if it exists. """ fname = self.file - if fname: + if fname and fname[0] != '#': if not self.IsEmpty(): try: cfgFile = open(fname, 'w') @@ -166,12 +166,12 @@ class IdleConf: def CreateConfigHandlers(self): "Populate default and user config parser dictionaries." idledir = os.path.dirname(__file__) - self.userdir = userdir = self.GetUserCfgDir() + self.userdir = userdir = '' if idlelib.testing else self.GetUserCfgDir() for cfg_type in self.config_types: self.defaultCfg[cfg_type] = IdleConfParser( os.path.join(idledir, f'config-{cfg_type}.def')) self.userCfg[cfg_type] = IdleUserConfParser( - os.path.join(userdir, f'config-{cfg_type}.cfg')) + os.path.join(userdir or '#', f'config-{cfg_type}.cfg')) def GetUserCfgDir(self): """Return a filesystem directory for storing user config files. @@ -182,12 +182,13 @@ class IdleConf: userDir = os.path.expanduser('~') if userDir != '~': # expanduser() found user home dir if not os.path.exists(userDir): - warn = ('\n Warning: os.path.expanduser("~") points to\n ' + - userDir + ',\n but the path does not exist.') - try: - print(warn, file=sys.stderr) - except OSError: - pass + if not idlelib.testing: + warn = ('\n Warning: os.path.expanduser("~") points to\n ' + + userDir + ',\n but the path does not exist.') + try: + print(warn, file=sys.stderr) + except OSError: + pass userDir = '~' if userDir == "~": # still no path to home! # traditionally IDLE has defaulted to os.getcwd(), is this adequate? @@ -197,10 +198,13 @@ class IdleConf: try: os.mkdir(userDir) except OSError: - warn = ('\n Warning: unable to create user config directory\n' + - userDir + '\n Check path and permissions.\n Exiting!\n') if not idlelib.testing: - print(warn, file=sys.stderr) + warn = ('\n Warning: unable to create user config directory\n' + + userDir + '\n Check path and permissions.\n Exiting!\n') + try: + print(warn, file=sys.stderr) + except OSError: + pass raise SystemExit # TODO continue without userDIr instead of exit return userDir |