Commit a4adafd5 authored by Greg Ward's avatar Greg Ward

Changed the semantics of the 'sub_commands' list: instead of function

  objects, it now has method names.
Added three methods, 'has_lib()', 'has_scripts()', and 'has_data()'
  to determine if we need to run each of the three possible sub-commands.
Added 'get_sub_commands()' to take care of finding the methods named
  in 'sub_commands', running them, and interpreting the results to
  build a list of sub-commands that actually have to be run.
parent f355d473
...@@ -93,14 +93,14 @@ class install (Command): ...@@ -93,14 +93,14 @@ class install (Command):
"filename in which to record list of installed files"), "filename in which to record list of installed files"),
] ]
# 'sub_commands': a list of commands this command might have to run # 'sub_commands': a list of commands this command might have to run to
# to get its work done. Each command is represented as a tuple # get its work done. Each command is represented as a tuple (method,
# (func, command) where 'func' is a function to call that returns # command) where 'method' is the name of a method to call that returns
# true if 'command' (the sub-command name, a string) needs to be # true if 'command' (the sub-command name, a string) needs to be run.
# run. If 'func' is None, assume that 'command' must always be run. # If 'method' is None, assume that 'command' must always be run.
sub_commands = [(None, 'install_lib'), sub_commands = [('has_lib', 'install_lib'),
(None, 'install_scripts'), ('has_scripts', 'install_scripts'),
(None, 'install_data'), ('has_data', 'install_data'),
] ]
...@@ -422,17 +422,29 @@ class install (Command): ...@@ -422,17 +422,29 @@ class install (Command):
# handle_extra_path () # handle_extra_path ()
def get_sub_commands (self):
"""Return the list of subcommands that we need to run. This is
based on the 'subcommands' class attribute: each tuple in that list
can name a method that we call to determine if the subcommand needs
to be run for the current distribution."""
commands = []
for (method, cmd_name) in self.sub_commands:
if method is not None:
method = getattr(self, method)
if method is None or method():
commands.append(cmd_name)
return commands
def run (self): def run (self):
# Obviously have to build before we can install # Obviously have to build before we can install
if not self.skip_build: if not self.skip_build:
self.run_peer ('build') self.run_peer ('build')
# Run all sub-commands: currently this just means install all # Run all sub-commands (at least those that need to be run)
# Python modules using 'install_lib'. for cmd_name in self.get_sub_commands():
for (func, cmd_name) in self.sub_commands: self.run_peer (cmd_name)
if func is None or func():
self.run_peer (cmd_name)
if self.path_file: if self.path_file:
self.create_path_file () self.create_path_file ()
...@@ -460,14 +472,26 @@ class install (Command): ...@@ -460,14 +472,26 @@ class install (Command):
# run () # run ()
def has_lib (self):
"""Return true if the current distribution has any Python
modules to install."""
return (self.distribution.has_pure_modules() or
self.distribution.has_ext_modules())
def has_scripts (self):
return self.distribution.has_scripts()
def has_data (self):
return self.distribution.has_data_files()
def get_outputs (self): def get_outputs (self):
# This command doesn't have any outputs of its own, so just # This command doesn't have any outputs of its own, so just
# get the outputs of all its sub-commands. # get the outputs of all its sub-commands.
outputs = [] outputs = []
for (func, cmd_name) in self.sub_commands: for cmd_name in self.get_sub_commands():
if func is None or func(): cmd = self.find_peer (cmd_name)
cmd = self.find_peer (cmd_name) outputs.extend (cmd.get_outputs())
outputs.extend (cmd.get_outputs())
return outputs return outputs
...@@ -475,10 +499,9 @@ class install (Command): ...@@ -475,10 +499,9 @@ class install (Command):
def get_inputs (self): def get_inputs (self):
# XXX gee, this looks familiar ;-( # XXX gee, this looks familiar ;-(
inputs = [] inputs = []
for (func, cmd_name) in self.sub_commands: for cmd_name in self.get_sub_commands():
if func is None or func(): cmd = self.find_peer (cmd_name)
cmd = self.find_peer (cmd_name) inputs.extend (cmd.get_inputs())
inputs.extend (cmd.get_inputs())
return inputs return inputs
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment