Skip to content

Commit b2e3bb3

Browse files
committed
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.)
1 parent bb8c71d commit b2e3bb3

6 files changed

Lines changed: 68 additions & 1 deletion

File tree

Lib/distutils/cmd.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,5 +344,35 @@ def make_file (self, infiles, outfile, func, args,
344344
# class Command
345345

346346

347+
class install_misc (Command):
348+
"""Common base class for installing some files in a subdirectory.
349+
Currently used by install_data and install_scripts.
350+
"""
351+
352+
user_options = [('install-dir=', 'd', "directory to install the files to")]
353+
354+
def initialize_options (self):
355+
self.install_dir = None
356+
self.outfiles = None
357+
358+
def _install_dir_from(self, dirname):
359+
self.set_undefined_options('install', (dirname, 'install_dir'))
360+
361+
def _copydata(self, filelist):
362+
self.outfiles = []
363+
if not filelist:
364+
return
365+
self.mkpath(self.install_dir)
366+
for f in filelist:
367+
self.outfiles.append(self.copy_file (f, self.install_dir))
368+
369+
def _outputdata(self, filelist):
370+
if self.outfiles is not None:
371+
return self.outfiles
372+
# XXX de-lambda-fy
373+
return map(lambda x: os.path.join(self.install_dir, x), filelist)
374+
375+
376+
347377
if __name__ == "__main__":
348378
print "ok"

Lib/distutils/command/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
'build_clib',
1212
'install',
1313
'install_lib',
14+
'install_scripts',
15+
'install_data',
1416
'clean',
1517
'sdist',
1618
'bdist',

Lib/distutils/command/install.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ class install (Command):
9090
# (func, command) where 'func' is a function to call that returns
9191
# true if 'command' (the sub-command name, a string) needs to be
9292
# run. If 'func' is None, assume that 'command' must always be run.
93-
sub_commands = [(None, 'install_lib')]
93+
sub_commands = [(None, 'install_lib'),
94+
(None, 'install_scripts'),
95+
(None, 'install_data'),
96+
]
9497

9598

9699
def initialize_options (self):
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from distutils.cmd import install_misc
2+
3+
class install_data (install_misc):
4+
5+
description = "install data files"
6+
7+
def finalize_options (self):
8+
self._install_dir_from('install_data')
9+
10+
def run (self):
11+
self._copydata(self.distribution.data)
12+
13+
def get_outputs (self):
14+
return self._outputdata(self.distribution.data)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from distutils.cmd import install_misc
2+
3+
class install_scripts(install_misc):
4+
5+
description = "install scripts"
6+
# XXX needed?
7+
user_options = [('install-dir=', 'd', "directory to install to")]
8+
9+
def finalize_options (self):
10+
self._install_dir_from('install_scripts')
11+
12+
def run (self):
13+
self._copydata(self.distribution.scripts)
14+
15+
def get_outputs(self):
16+
return self._outputdata(self.distribution.scripts)

Lib/distutils/dist.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ def __init__ (self, attrs=None):
154154
self.ext_package = None
155155
self.include_dirs = None
156156
self.extra_path = None
157+
self.scripts = None
158+
self.data = None
157159

158160
# And now initialize bookkeeping stuff that can't be supplied by
159161
# the caller at all. 'command_obj' maps command names to

0 commit comments

Comments
 (0)