Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f8d4cc7d
Commit
f8d4cc7d
authored
Jul 16, 2019
by
Cheryl Sabella
Committed by
Terry Jan Reedy
Jul 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-27452: IDLE: Cleanup config.py code (GH-14577)
parent
f69d5c61
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
39 deletions
+10
-39
Lib/idlelib/config.py
Lib/idlelib/config.py
+9
-26
Lib/idlelib/idle_test/test_config.py
Lib/idlelib/idle_test/test_config.py
+0
-13
Misc/NEWS.d/next/IDLE/2019-07-03-22-47-44.bpo-27452.nePPLi.rst
...NEWS.d/next/IDLE/2019-07-03-22-47-44.bpo-27452.nePPLi.rst
+1
-0
No files found.
Lib/idlelib/config.py
View file @
f8d4cc7d
...
...
@@ -123,17 +123,11 @@ class IdleUserConfParser(IdleConfParser):
self
.
RemoveEmptySections
()
return
not
self
.
sections
()
def
RemoveFile
(
self
):
"Remove user config file self.file from disk if it exists."
if
os
.
path
.
exists
(
self
.
file
):
os
.
remove
(
self
.
file
)
def
Save
(
self
):
"""Update user configuration file.
If self not empty after removing empty sections, write the file
to disk. Otherwise, remove the file from disk if it exists.
"""
fname
=
self
.
file
if
fname
:
...
...
@@ -145,8 +139,8 @@ class IdleUserConfParser(IdleConfParser):
cfgFile
=
open
(
fname
,
'w'
)
with
cfgFile
:
self
.
write
(
cfgFile
)
el
se
:
self
.
RemoveFile
(
)
el
if
os
.
path
.
exists
(
self
.
file
)
:
os
.
remove
(
self
.
file
)
class
IdleConf
:
"""Hold config parsers for all idle config files in singleton instance.
...
...
@@ -171,24 +165,13 @@ class IdleConf:
def
CreateConfigHandlers
(
self
):
"Populate default and user config parser dictionaries."
#build idle install path
if
__name__
!=
'__main__'
:
# we were imported
idleDir
=
os
.
path
.
dirname
(
__file__
)
else
:
# we were exec'ed (for testing only)
idleDir
=
os
.
path
.
abspath
(
sys
.
path
[
0
])
self
.
userdir
=
userDir
=
self
.
GetUserCfgDir
()
defCfgFiles
=
{}
usrCfgFiles
=
{}
# TODO eliminate these temporaries by combining loops
for
cfgType
in
self
.
config_types
:
#build config file names
defCfgFiles
[
cfgType
]
=
os
.
path
.
join
(
idleDir
,
'config-'
+
cfgType
+
'.def'
)
usrCfgFiles
[
cfgType
]
=
os
.
path
.
join
(
userDir
,
'config-'
+
cfgType
+
'.cfg'
)
for
cfgType
in
self
.
config_types
:
#create config parsers
self
.
defaultCfg
[
cfgType
]
=
IdleConfParser
(
defCfgFiles
[
cfgType
])
self
.
userCfg
[
cfgType
]
=
IdleUserConfParser
(
usrCfgFiles
[
cfgType
])
idledir
=
os
.
path
.
dirname
(
__file__
)
self
.
userdir
=
userdir
=
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'
))
def
GetUserCfgDir
(
self
):
"""Return a filesystem directory for storing user config files.
...
...
Lib/idlelib/idle_test/test_config.py
View file @
f8d4cc7d
...
...
@@ -159,19 +159,6 @@ class IdleUserConfParserTest(unittest.TestCase):
self
.
assertFalse
(
parser
.
IsEmpty
())
self
.
assertCountEqual
(
parser
.
sections
(),
[
'Foo'
])
def
test_remove_file
(
self
):
with
tempfile
.
TemporaryDirectory
()
as
tdir
:
path
=
os
.
path
.
join
(
tdir
,
'test.cfg'
)
parser
=
self
.
new_parser
(
path
)
parser
.
RemoveFile
()
# Should not raise exception.
parser
.
AddSection
(
'Foo'
)
parser
.
SetOption
(
'Foo'
,
'bar'
,
'true'
)
parser
.
Save
()
self
.
assertTrue
(
os
.
path
.
exists
(
path
))
parser
.
RemoveFile
()
self
.
assertFalse
(
os
.
path
.
exists
(
path
))
def
test_save
(
self
):
with
tempfile
.
TemporaryDirectory
()
as
tdir
:
path
=
os
.
path
.
join
(
tdir
,
'test.cfg'
)
...
...
Misc/NEWS.d/next/IDLE/2019-07-03-22-47-44.bpo-27452.nePPLi.rst
0 → 100644
View file @
f8d4cc7d
Cleanup ``config.py`` by inlining ``RemoveFile`` and simplifying the handling of ``file`` in ``CreateConfigHandlers``.
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment