Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e48cfd

Browse files
committed
Factored out code for extracting-or-creating one of the option
dictionaries in 'self.command_options' to 'get_option_dict()'. Simplified code in 'parse_config_files()' and 'parse_command_line()' accordingly. Fixed code in constructor that processes the 'options' dictionary from the setup script so it actually works: uses the new 'self.command_options' dictionary rather than creating command objects and calling 'set_option()' on them.
1 parent 37af1c3 commit 0e48cfd

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

Lib/distutils/dist.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,9 @@ def __init__ (self, attrs=None):
185185
if options:
186186
del attrs['options']
187187
for (command, cmd_options) in options.items():
188-
cmd_obj = self.get_command_obj (command)
189-
for (key, val) in cmd_options.items():
190-
cmd_obj.set_option (key, val)
191-
# loop over commands
192-
# if any command options
188+
opt_dict = self.get_option_dict(command)
189+
for (opt, val) in cmd_options.items():
190+
opt_dict[opt] = ("setup script", val)
193191

194192
# Now work on the rest of the attributes. Any attribute that's
195193
# not already defined is invalid!
@@ -205,6 +203,19 @@ def __init__ (self, attrs=None):
205203
# __init__ ()
206204

207205

206+
def get_option_dict (self, command):
207+
"""Get the option dictionary for a given command. If that
208+
command's option dictionary hasn't been created yet, then create it
209+
and return the new dictionary; otherwise, return the existing
210+
option dictionary.
211+
"""
212+
213+
dict = self.command_options.get(command)
214+
if dict is None:
215+
dict = self.command_options[command] = {}
216+
return dict
217+
218+
208219
# -- Config file finding/parsing methods ---------------------------
209220

210221
def find_config_files (self):
@@ -266,13 +277,11 @@ def parse_config_files (self, filenames=None):
266277
parser.read(filename)
267278
for section in parser.sections():
268279
options = parser.options(section)
269-
if not self.command_options.has_key(section):
270-
self.command_options[section] = {}
271-
opts = self.command_options[section]
280+
opt_dict = self.get_option_dict(section)
272281

273282
for opt in options:
274283
if opt != '__name__':
275-
opts[opt] = (filename, parser.get(section,opt))
284+
opt_dict[opt] = (filename, parser.get(section,opt))
276285

277286
# Make the ConfigParser forget everything (so we retain
278287
# the original filenames that options come from) -- gag,
@@ -409,11 +418,9 @@ def _parse_command_opts (self, parser, args):
409418

410419
# Put the options from the command-line into their official
411420
# holding pen, the 'command_options' dictionary.
412-
if not self.command_options.has_key(command):
413-
self.command_options[command] = {}
414-
cmd_opts = self.command_options[command]
421+
opt_dict = self.get_option_dict(command)
415422
for (name, value) in vars(opts).items():
416-
cmd_opts[name] = ("command line", value)
423+
opt_dict[name] = ("command line", value)
417424

418425
return args
419426

0 commit comments

Comments
 (0)