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

Skip to content

Commit df0d335

Browse files
committed
Ditched the whole notion of "alias options": this meant dropping the
'alias_options' table and getting rid of some hairy code in the Distribution constructor. Resurrected the distribution options that describe the modules present in the module distribution ('py_modules', 'ext_modules'), and added a bunch more: 'packages', 'package_dir', 'ext_package', 'include_dirs', 'install_path'. Updated some comments. Added 'warn()' method to Command. 'Command.get_command_name()' now stores generated command name in self.command_name.
1 parent ac1424a commit df0d335

1 file changed

Lines changed: 21 additions & 39 deletions

File tree

Lib/distutils/core.py

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,6 @@ class Distribution:
114114
('dry-run', 'n', "don't actually do anything"),
115115
]
116116

117-
# 'alias_options' map distribution options to command options -- the
118-
# idea is that the most common, essential options can be directly
119-
# specified as Distribution attributes, and the rest can go in the
120-
# 'options' dictionary. These aliases are for those common, essential
121-
# options.
122-
alias_options = { 'py_modules': ('build_py', 'modules'),
123-
'ext_modules': ('build_ext', 'extensions'),
124-
'package': [('build_py', 'package',),
125-
('build_ext', 'package')],
126-
'include_dirs': ('build_ext', 'include_dirs'),
127-
128-
}
129-
130117

131118
# -- Creation/initialization methods -------------------------------
132119

@@ -151,6 +138,7 @@ def __init__ (self, attrs=None):
151138
self.name = None
152139
self.version = None
153140
self.author = None
141+
self.author_email = None
154142
self.url = None
155143
self.licence = None
156144
self.description = None
@@ -165,10 +153,13 @@ def __init__ (self, attrs=None):
165153
# than of the Distribution itself. We provide aliases for them in
166154
# Distribution as a convenience to the developer.
167155
# dictionary.
168-
# XXX not needed anymore! (I think...)
169-
#self.py_modules = None
170-
#self.ext_modules = None
171-
#self.package = None
156+
self.packages = None
157+
self.package_dir = None
158+
self.py_modules = None
159+
self.ext_modules = None
160+
self.ext_package = None
161+
self.include_dirs = None
162+
self.install_path = None
172163

173164
# And now initialize bookkeeping stuff that can't be supplied by
174165
# the caller at all. 'command_obj' maps command names to
@@ -188,8 +179,9 @@ def __init__ (self, attrs=None):
188179
# '.get()' rather than a straight lookup.
189180
self.have_run = {}
190181

191-
# Now we'll use the attrs dictionary (from the client) to possibly
192-
# override any or all of these distribution options
182+
# Now we'll use the attrs dictionary (ultimately, keyword args from
183+
# the client) to possibly override any or all of these distribution
184+
# options.
193185
if attrs:
194186

195187
# Pull out the set of command options and work on them
@@ -206,26 +198,10 @@ def __init__ (self, attrs=None):
206198
# loop over commands
207199
# if any command options
208200

209-
# Now work on the rest of the attributes. Note that some of
210-
# these may be aliases for command options, so we might go
211-
# through some of the above again.
201+
# Now work on the rest of the attributes. Any attribute that's
202+
# not already defined is invalid!
212203
for (key,val) in attrs.items():
213-
alias = self.alias_options.get (key)
214-
if alias:
215-
if type (alias) is ListType:
216-
for (command, cmd_option) in alias:
217-
cmd_obj = self.find_command_obj (command)
218-
cmd_obj.set_option (cmd_option, val)
219-
elif type (alias) is TupleType:
220-
(command, cmd_option) = alias
221-
cmd_obj = self.find_command_obj (command)
222-
cmd_obj.set_option (cmd_option, val)
223-
else:
224-
raise RuntimeError, \
225-
("oops! bad alias option for '%s': " +
226-
"must be tuple or list of tuples") % key
227-
228-
elif hasattr (self, key):
204+
if hasattr (self, key):
229205
setattr (self, key, val)
230206
else:
231207
raise DistutilsOptionError, \
@@ -653,7 +629,8 @@ def get_command_name (self):
653629
# splits to ['', 'Foo', '', 'Bar', '', 'Baz', '']. Hence
654630
# the 'filter' to strip out the empties.
655631
words = filter (None, re.split (r'([A-Z][a-z]+)', class_name))
656-
return string.join (map (string.lower, words), "_")
632+
self.command_name = string.join (map (string.lower, words), "_")
633+
return self.command_name
657634

658635

659636
def set_undefined_options (self, src_cmd, *option_pairs):
@@ -717,6 +694,11 @@ def run_peer (self, command):
717694

718695
# -- External world manipulation -----------------------------------
719696

697+
def warn (self, msg):
698+
sys.stderr.write ("warning: %s: %s\n" %
699+
(self.get_command_name(), msg))
700+
701+
720702
def execute (self, func, args, msg=None, level=1):
721703
"""Perform some action that affects the outside world (eg.
722704
by writing to the filesystem). Such actions are special because

0 commit comments

Comments
 (0)