~pythonregexp2.7/python/issue2636

« back to all changes in this revision

Viewing changes to Lib/distutils/command/install.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-05-24 16:05:21 UTC
  • mfrom: (39021.1.401 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080524160521-1xenj7p6u3wb89et
Merged in changes from the latest python source snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from distutils.util import convert_path, subst_vars, change_root
19
19
from distutils.util import get_platform
20
20
from distutils.errors import DistutilsOptionError
 
21
from site import USER_BASE
 
22
from site import USER_SITE
 
23
 
21
24
 
22
25
if sys.version < "2.2":
23
26
    WINDOWS_SCHEME = {
51
54
        'scripts': '$base/bin',
52
55
        'data'   : '$base',
53
56
        },
 
57
    'unix_user': {
 
58
        'purelib': '$usersite',
 
59
        'platlib': '$usersite',
 
60
        'headers': '$userbase/include/python$py_version_short/$dist_name',
 
61
        'scripts': '$userbase/bin',
 
62
        'data'   : '$userbase',
 
63
        },
54
64
    'nt': WINDOWS_SCHEME,
 
65
    'nt_user': {
 
66
        'purelib': '$usersite',
 
67
        'platlib': '$usersite',
 
68
        'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
 
69
        'scripts': '$userbase/Scripts',
 
70
        'data'   : '$userbase',
 
71
        },
55
72
    'mac': {
56
73
        'purelib': '$base/Lib/site-packages',
57
74
        'platlib': '$base/Lib/site-packages',
59
76
        'scripts': '$base/Scripts',
60
77
        'data'   : '$base',
61
78
        },
 
79
    'mac_user': {
 
80
        'purelib': '$usersite',
 
81
        'platlib': '$usersite',
 
82
        'headers': '$userbase/$py_version_short/include/$dist_name',
 
83
        'scripts': '$userbase/bin',
 
84
        'data'   : '$userbase',
 
85
        },
62
86
    'os2': {
63
87
        'purelib': '$base/Lib/site-packages',
64
88
        'platlib': '$base/Lib/site-packages',
65
89
        'headers': '$base/Include/$dist_name',
66
90
        'scripts': '$base/Scripts',
67
91
        'data'   : '$base',
68
 
        }
 
92
        },
 
93
    'os2_home': {
 
94
        'purelib': '$usersite',
 
95
        'platlib': '$usersite',
 
96
        'headers': '$userbase/include/python$py_version_short/$dist_name',
 
97
        'scripts': '$userbase/bin',
 
98
        'data'   : '$userbase',
 
99
        },
69
100
    }
70
101
 
71
102
# The keys to an installation scheme; if any new types of files are to be
86
117
         "(Unix only) prefix for platform-specific files"),
87
118
        ('home=', None,
88
119
         "(Unix only) home directory to install under"),
 
120
        ('user', None,
 
121
         "install in user site-package '%s'" % USER_SITE),
89
122
 
90
123
        # Or, just set the base director(y|ies)
91
124
        ('install-base=', None,
137
170
         "filename in which to record list of installed files"),
138
171
        ]
139
172
 
140
 
    boolean_options = ['compile', 'force', 'skip-build']
 
173
    boolean_options = ['compile', 'force', 'skip-build', 'user']
141
174
    negative_opt = {'no-compile' : 'compile'}
142
175
 
143
176
 
148
181
        self.prefix = None
149
182
        self.exec_prefix = None
150
183
        self.home = None
 
184
        self.user = 0
151
185
 
152
186
        # These select only the installation base; it's up to the user to
153
187
        # specify the installation scheme (currently, that means supplying
166
200
        self.install_lib = None         # set to either purelib or platlib
167
201
        self.install_scripts = None
168
202
        self.install_data = None
 
203
        self.install_userbase = USER_BASE
 
204
        self.install_usersite = USER_SITE
169
205
 
170
206
        self.compile = None
171
207
        self.optimize = None
241
277
            raise DistutilsOptionError, \
242
278
                  "must supply either home or prefix/exec-prefix -- not both"
243
279
 
 
280
        if self.user and (self.prefix or self.exec_prefix or self.home or
 
281
                self.install_base or self.install_platbase):
 
282
            raise DistutilsOptionError("can't combine user with with prefix/"
 
283
                                       "exec_prefix/home or install_(plat)base")
 
284
 
244
285
        # Next, stuff that's wrong (or dubious) only on certain platforms.
245
286
        if os.name != "posix":
246
287
            if self.exec_prefix:
276
317
                            'dist_fullname': self.distribution.get_fullname(),
277
318
                            'py_version': py_version,
278
319
                            'py_version_short': py_version[0:3],
 
320
                            'py_version_nodot': py_version[0] + py_version[2],
279
321
                            'sys_prefix': prefix,
280
322
                            'prefix': prefix,
281
323
                            'sys_exec_prefix': exec_prefix,
282
324
                            'exec_prefix': exec_prefix,
 
325
                            'userbase': self.install_userbase,
 
326
                            'usersite': self.install_usersite,
283
327
                           }
284
328
        self.expand_basedirs()
285
329
 
301
345
 
302
346
        self.dump_dirs("post-expand_dirs()")
303
347
 
 
348
        # Create directories in the home dir:
 
349
        if self.user:
 
350
            self.create_home_path()
 
351
 
304
352
        # Pick the actual directory to install all modules to: either
305
353
        # install_purelib or install_platlib, depending on whether this
306
354
        # module distribution is pure or not.  Of course, if the user
315
363
        # Convert directories from Unix /-separated syntax to the local
316
364
        # convention.
317
365
        self.convert_paths('lib', 'purelib', 'platlib',
318
 
                           'scripts', 'data', 'headers')
 
366
                           'scripts', 'data', 'headers',
 
367
                           'userbase', 'usersite')
319
368
 
320
369
        # Well, we're not actually fully completely finalized yet: we still
321
370
        # have to deal with 'extra_path', which is the hack for allowing
376
425
                      "installation scheme is incomplete")
377
426
            return
378
427
 
379
 
        if self.home is not None:
 
428
        if self.user:
 
429
            if self.install_userbase is None:
 
430
                raise DistutilsPlatformError(
 
431
                    "User base directory is not specified")
 
432
            self.install_base = self.install_platbase = self.install_userbase
 
433
            self.select_scheme("unix_user")
 
434
        elif self.home is not None:
380
435
            self.install_base = self.install_platbase = self.home
381
436
            self.select_scheme("unix_home")
382
437
        else:
401
456
 
402
457
    def finalize_other (self):          # Windows and Mac OS for now
403
458
 
404
 
        if self.home is not None:
 
459
        if self.user:
 
460
            if self.install_userbase is None:
 
461
                raise DistutilsPlatformError(
 
462
                    "User base directory is not specified")
 
463
            self.install_base = self.install_platbase = self.install_userbase
 
464
            self.select_scheme(os.name + "_user")
 
465
        elif self.home is not None:
405
466
            self.install_base = self.install_platbase = self.home
406
467
            self.select_scheme("unix_home")
407
468
        else:
431
492
        for attr in attrs:
432
493
            val = getattr(self, attr)
433
494
            if val is not None:
434
 
                if os.name == 'posix':
 
495
                if os.name == 'posix' or os.name == 'nt':
435
496
                    val = os.path.expanduser(val)
436
497
                val = subst_vars(val, self.config_vars)
437
498
                setattr(self, attr, val)
496
557
            attr = "install_" + name
497
558
            setattr(self, attr, change_root(self.root, getattr(self, attr)))
498
559
 
 
560
    def create_home_path(self):
 
561
        """Create directories under ~
 
562
        """
 
563
        if not self.user:
 
564
            return
 
565
        home = convert_path(os.path.expanduser("~"))
 
566
        for name, path in self.config_vars.iteritems():
 
567
            if path.startswith(home) and not os.path.isdir(path):
 
568
                self.debug_print("os.makedirs('%s', 0700)" % path)
 
569
                os.makedirs(path, 0700)
499
570
 
500
571
    # -- Command execution methods -------------------------------------
501
572