Skip to content

Commit 8d5881a

Browse files
committed
Bastian Kleineidam: the "build_scripts" command and changes
necessary to support it. Details: - build command additionally calls build_scripts - build_scripts builds your scripts in 'build/scripts' and adjusts the first line if it begins with "#!" and ends with "python", optionally ending with commandline options (like -O, -t ...). Adjusting means we write the current path to the Python interpreter in the first line. - install_scripts copies the scripts to the install_scripts dir - install_data copies your data_files in install_data. You can supply individual directories for your data_files: data_files = ['doc/info.txt', # copy this file in install_scripts dir ('testdata', ['a.dat', 'b.dat']), # copy these files in # install_scripts/testdata ('/etc', ['packagerc']), # copy this in /etc. When --root is # given, copy this in rootdir/etc ] So you can use the --root option with absolute data paths.
1 parent fcd974e commit 8d5881a

4 files changed

Lines changed: 74 additions & 11 deletions

File tree

‎Lib/distutils/command/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'build_py',
1010
'build_ext',
1111
'build_clib',
12+
'build_scripts',
1213
'install',
1314
'install_lib',
1415
'install_scripts',

‎Lib/distutils/command/build.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class build (Command):
2424
('build-lib=', None,
2525
"build directory for all distribution (defaults to either " +
2626
"build-purelib or build-platlib"),
27+
('build-scripts=', None,
28+
"build directory for scripts"),
2729
('build-temp=', 't',
2830
"temporary build directory"),
2931
('compiler=', 'c',
@@ -42,6 +44,7 @@ def initialize_options (self):
4244
self.build_platlib = None
4345
self.build_lib = None
4446
self.build_temp = None
47+
self.build_scripts = None
4548
self.compiler = None
4649
self.debug = None
4750
self.force = 0
@@ -76,6 +79,8 @@ def finalize_options (self):
7679
if self.build_temp is None:
7780
self.build_temp = os.path.join (self.build_base,
7881
'temp.' + self.plat)
82+
if self.build_scripts is None:
83+
self.build_scripts = os.path.join (self.build_base, 'scripts')
7984
# finalize_options ()
8085

8186

@@ -100,4 +105,7 @@ def run (self):
100105
if self.distribution.has_ext_modules():
101106
self.run_peer ('build_ext')
102107

108+
if self.distribution.scripts:
109+
self.run_peer ('build_scripts')
110+
103111
# class build

‎Lib/distutils/command/install_data.py‎

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,52 @@
77

88
__revision__ = "$Id$"
99

10-
from distutils.cmd import install_misc
10+
import os
11+
from types import StringType
12+
from distutils.core import Command
1113

12-
class install_data (install_misc):
14+
class install_data (Command):
1315

1416
description = "install data files"
1517

18+
user_options = [
19+
('install-dir=', 'd',
20+
"directory to install the files to"),
21+
('root=', None,
22+
"install everything relative to this alternate root directory"),
23+
]
24+
25+
def initialize_options (self):
26+
self.install_dir = None
27+
self.outfiles = None
28+
self.root = None
29+
self.data_files = self.distribution.data_files
30+
1631
def finalize_options (self):
17-
self._install_dir_from('install_data')
32+
self.set_undefined_options('install',
33+
('install_data', 'install_dir'),
34+
('root', 'root'),
35+
)
1836

1937
def run (self):
20-
self._copy_files(self.distribution.data_files)
38+
self.mkpath(self.install_dir)
39+
for f in self.data_files:
40+
if type(f) == StringType:
41+
# its a simple file, so copy it
42+
self.copy_file(f, self.install_dir)
43+
else:
44+
# its a tuple with path to install to and a list of files
45+
dir = f[0]
46+
if not os.path.isabs(dir):
47+
dir = os.path.join(self.install_dir, dir)
48+
elif self.root:
49+
dir = os.path.join(self.root, dir[1:])
50+
self.mkpath(dir)
51+
for data in f[1]:
52+
self.copy_file(data, dir)
2153

2254
def get_inputs (self):
23-
return self.distribution.data_files or []
55+
return self.data_files or []
56+
57+
def get_outputs (self):
58+
return self.outfiles

‎Lib/distutils/command/install_scripts.py‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,39 @@
88
__revision__ = "$Id$"
99

1010
import os
11-
from distutils.cmd import install_misc
11+
from distutils.core import Command
1212
from stat import ST_MODE
1313

14-
class install_scripts(install_misc):
14+
class install_scripts(Command):
1515

1616
description = "install scripts"
1717

18+
user_options = [
19+
('install-dir=', 'd', "directory to install to"),
20+
('build-dir=','b', "build directory (where to install from)"),
21+
('skip-build', None, "skip the build steps"),
22+
]
23+
24+
def initialize_options (self):
25+
self.install_dir = None
26+
self.build_dir = None
27+
self.skip_build = None
28+
1829
def finalize_options (self):
19-
self._install_dir_from('install_scripts')
30+
self.set_undefined_options('build', ('build_scripts', 'build_dir'))
31+
self.set_undefined_options ('install',
32+
('install_scripts', 'install_dir'),
33+
('skip_build', 'skip_build'),
34+
)
2035

2136
def run (self):
22-
self._copy_files(self.distribution.scripts)
37+
if not self.skip_build:
38+
self.run_peer('build_scripts')
39+
self.outfiles = self.copy_tree (self.build_dir, self.install_dir)
2340
if os.name == 'posix':
2441
# Set the executable bits (owner, group, and world) on
2542
# all the scripts we just installed.
26-
files = self.get_outputs()
27-
for file in files:
43+
for file in self.get_outputs():
2844
if self.dry_run:
2945
self.announce("changing mode of %s" % file)
3046
else:
@@ -35,4 +51,7 @@ def run (self):
3551
def get_inputs (self):
3652
return self.distribution.scripts or []
3753

54+
def get_outputs(self):
55+
return self.outfiles or []
56+
3857
# class install_scripts

0 commit comments

Comments
 (0)