1414from packaging .errors import PackagingOptionError
1515
1616
17- HAS_USER_SITE = True
18-
19-
2017class install_dist (Command ):
2118
2219 description = "install everything from build directory"
@@ -27,6 +24,9 @@ class install_dist(Command):
2724 "installation prefix" ),
2825 ('exec-prefix=' , None ,
2926 "(Unix only) prefix for platform-specific files" ),
27+ ('user' , None ,
28+ "install in user site-packages directory [%s]" %
29+ get_path ('purelib' , '%s_user' % os .name )),
3030 ('home=' , None ,
3131 "(Unix only) home directory to install under" ),
3232
@@ -97,15 +97,7 @@ class install_dist(Command):
9797 ]
9898
9999 boolean_options = ['compile' , 'force' , 'skip-build' , 'no-distinfo' ,
100- 'requested' , 'no-record' ]
101-
102- if HAS_USER_SITE :
103- user_options .append (
104- ('user' , None ,
105- "install in user site-packages directory [%s]" %
106- get_path ('purelib' , '%s_user' % os .name )))
107-
108- boolean_options .append ('user' )
100+ 'requested' , 'no-record' , 'user' ]
109101
110102 negative_opt = {'no-compile' : 'compile' , 'no-requested' : 'requested' }
111103
@@ -115,8 +107,7 @@ def initialize_options(self):
115107 self .prefix = None
116108 self .exec_prefix = None
117109 self .home = None
118- if HAS_USER_SITE :
119- self .user = False
110+ self .user = False
120111
121112 # These select only the installation base; it's up to the user to
122113 # specify the installation scheme (currently, that means supplying
@@ -135,9 +126,8 @@ def initialize_options(self):
135126 self .install_lib = None # set to either purelib or platlib
136127 self .install_scripts = None
137128 self .install_data = None
138- if HAS_USER_SITE :
139- self .install_userbase = get_config_var ('userbase' )
140- self .install_usersite = get_path ('purelib' , '%s_user' % os .name )
129+ self .install_userbase = get_config_var ('userbase' )
130+ self .install_usersite = get_path ('purelib' , '%s_user' % os .name )
141131
142132 self .compile = None
143133 self .optimize = None
@@ -219,9 +209,8 @@ def finalize_options(self):
219209 raise PackagingOptionError (
220210 "must supply either home or prefix/exec-prefix -- not both" )
221211
222- if HAS_USER_SITE and self .user and (
223- self .prefix or self .exec_prefix or self .home or
224- self .install_base or self .install_platbase ):
212+ if self .user and (self .prefix or self .exec_prefix or self .home or
213+ self .install_base or self .install_platbase ):
225214 raise PackagingOptionError (
226215 "can't combine user with prefix/exec_prefix/home or "
227216 "install_base/install_platbase" )
@@ -274,11 +263,9 @@ def finalize_options(self):
274263 'exec_prefix' : exec_prefix ,
275264 'srcdir' : srcdir ,
276265 'projectbase' : projectbase ,
277- }
278-
279- if HAS_USER_SITE :
280- self .config_vars ['userbase' ] = self .install_userbase
281- self .config_vars ['usersite' ] = self .install_usersite
266+ 'userbase' : self .install_userbase ,
267+ 'usersite' : self .install_usersite ,
268+ }
282269
283270 self .expand_basedirs ()
284271
@@ -295,9 +282,9 @@ def finalize_options(self):
295282
296283 self .dump_dirs ("post-expand_dirs()" )
297284
298- # Create directories in the home dir:
299- if HAS_USER_SITE and self .user :
300- self .create_home_path ()
285+ # Create directories under USERBASE
286+ if self .user :
287+ self .create_user_dirs ()
301288
302289 # Pick the actual directory to install all modules to: either
303290 # install_purelib or install_platlib, depending on whether this
@@ -311,10 +298,8 @@ def finalize_options(self):
311298
312299 # Convert directories from Unix /-separated syntax to the local
313300 # convention.
314- self .convert_paths ('lib' , 'purelib' , 'platlib' ,
315- 'scripts' , 'data' , 'headers' )
316- if HAS_USER_SITE :
317- self .convert_paths ('userbase' , 'usersite' )
301+ self .convert_paths ('lib' , 'purelib' , 'platlib' , 'scripts' ,
302+ 'data' , 'headers' , 'userbase' , 'usersite' )
318303
319304 # Well, we're not actually fully completely finalized yet: we still
320305 # have to deal with 'extra_path', which is the hack for allowing
@@ -355,7 +340,7 @@ def finalize_unix(self):
355340 "installation scheme is incomplete" )
356341 return
357342
358- if HAS_USER_SITE and self .user :
343+ if self .user :
359344 if self .install_userbase is None :
360345 raise PackagingPlatformError (
361346 "user base directory is not specified" )
@@ -383,7 +368,7 @@ def finalize_unix(self):
383368
384369 def finalize_other (self ):
385370 """Finalize options for non-posix platforms"""
386- if HAS_USER_SITE and self .user :
371+ if self .user :
387372 if self .install_userbase is None :
388373 raise PackagingPlatformError (
389374 "user base directory is not specified" )
@@ -494,10 +479,8 @@ def change_roots(self, *names):
494479 attr = "install_" + name
495480 setattr (self , attr , change_root (self .root , getattr (self , attr )))
496481
497- def create_home_path (self ):
498- """Create directories under ~."""
499- if HAS_USER_SITE and not self .user :
500- return
482+ def create_user_dirs (self ):
483+ """Create directories under USERBASE as needed."""
501484 home = convert_path (os .path .expanduser ("~" ))
502485 for name , path in self .config_vars .items ():
503486 if path .startswith (home ) and not os .path .isdir (path ):
0 commit comments