From b2e3bb3d6aaf4ef04211b932c64ef9cd5adc56bb Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 12 May 2000 00:52:23 +0000 Subject: [PATCH] Patch from Bastien Kleineidam: adds the 'install_data' and 'install_scripts' commands; these two are trivial thanks to the 'install_misc' base class in cmd.py. (Minor tweaks and commentary by me; the code is untested so far.) --- Lib/distutils/cmd.py | 30 ++++++++++++++++++++++++ Lib/distutils/command/__init__.py | 2 ++ Lib/distutils/command/install.py | 5 +++- Lib/distutils/command/install_data.py | 14 +++++++++++ Lib/distutils/command/install_scripts.py | 16 +++++++++++++ Lib/distutils/dist.py | 2 ++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 Lib/distutils/command/install_data.py create mode 100644 Lib/distutils/command/install_scripts.py diff --git a/Lib/distutils/cmd.py b/Lib/distutils/cmd.py index abb23c9fb2..393734401d 100644 --- a/Lib/distutils/cmd.py +++ b/Lib/distutils/cmd.py @@ -344,5 +344,35 @@ class Command: # class Command +class install_misc (Command): + """Common base class for installing some files in a subdirectory. + Currently used by install_data and install_scripts. + """ + + user_options = [('install-dir=', 'd', "directory to install the files to")] + + def initialize_options (self): + self.install_dir = None + self.outfiles = None + + def _install_dir_from(self, dirname): + self.set_undefined_options('install', (dirname, 'install_dir')) + + def _copydata(self, filelist): + self.outfiles = [] + if not filelist: + return + self.mkpath(self.install_dir) + for f in filelist: + self.outfiles.append(self.copy_file (f, self.install_dir)) + + def _outputdata(self, filelist): + if self.outfiles is not None: + return self.outfiles + # XXX de-lambda-fy + return map(lambda x: os.path.join(self.install_dir, x), filelist) + + + if __name__ == "__main__": print "ok" diff --git a/Lib/distutils/command/__init__.py b/Lib/distutils/command/__init__.py index 385330b5e0..573ae5138e 100644 --- a/Lib/distutils/command/__init__.py +++ b/Lib/distutils/command/__init__.py @@ -11,6 +11,8 @@ __all__ = ['build', 'build_clib', 'install', 'install_lib', + 'install_scripts', + 'install_data', 'clean', 'sdist', 'bdist', diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py index c70ed9a1d1..3f6fa33fc6 100644 --- a/Lib/distutils/command/install.py +++ b/Lib/distutils/command/install.py @@ -90,7 +90,10 @@ class install (Command): # (func, command) where 'func' is a function to call that returns # true if 'command' (the sub-command name, a string) needs to be # run. If 'func' is None, assume that 'command' must always be run. - sub_commands = [(None, 'install_lib')] + sub_commands = [(None, 'install_lib'), + (None, 'install_scripts'), + (None, 'install_data'), + ] def initialize_options (self): diff --git a/Lib/distutils/command/install_data.py b/Lib/distutils/command/install_data.py new file mode 100644 index 0000000000..f86d95e54b --- /dev/null +++ b/Lib/distutils/command/install_data.py @@ -0,0 +1,14 @@ +from distutils.cmd import install_misc + +class install_data (install_misc): + + description = "install data files" + + def finalize_options (self): + self._install_dir_from('install_data') + + def run (self): + self._copydata(self.distribution.data) + + def get_outputs (self): + return self._outputdata(self.distribution.data) diff --git a/Lib/distutils/command/install_scripts.py b/Lib/distutils/command/install_scripts.py new file mode 100644 index 0000000000..665208eb78 --- /dev/null +++ b/Lib/distutils/command/install_scripts.py @@ -0,0 +1,16 @@ +from distutils.cmd import install_misc + +class install_scripts(install_misc): + + description = "install scripts" + # XXX needed? + user_options = [('install-dir=', 'd', "directory to install to")] + + def finalize_options (self): + self._install_dir_from('install_scripts') + + def run (self): + self._copydata(self.distribution.scripts) + + def get_outputs(self): + return self._outputdata(self.distribution.scripts) diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py index a0c6c9ea3d..998cff7190 100644 --- a/Lib/distutils/dist.py +++ b/Lib/distutils/dist.py @@ -154,6 +154,8 @@ class Distribution: self.ext_package = None self.include_dirs = None self.extra_path = None + self.scripts = None + self.data = None # And now initialize bookkeeping stuff that can't be supplied by # the caller at all. 'command_obj' maps command names to -- 2.40.0