Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8dc226f

Browse files
committed
Merged revisions 62774-62775,62785,62787-62788 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r62774 | georg.brandl | 2008-05-06 19:11:42 +0200 (Tue, 06 May 2008) | 2 lines #2773: fix description of 'g' and 'G' formatting spec. ........ r62775 | georg.brandl | 2008-05-06 19:20:54 +0200 (Tue, 06 May 2008) | 2 lines > != (!<). ........ r62785 | benjamin.peterson | 2008-05-07 00:18:11 +0200 (Wed, 07 May 2008) | 2 lines Fix logic error in Python/_warnings.c and add a test to verify ........ r62787 | benjamin.peterson | 2008-05-07 00:31:52 +0200 (Wed, 07 May 2008) | 2 lines Make the Python implementation of warnings compatible with the C implementation regarding non-callable showwarning ........ r62788 | christian.heimes | 2008-05-07 00:41:46 +0200 (Wed, 07 May 2008) | 1 line Implemented PEP 370 ........
1 parent 1bf7108 commit 8dc226f

13 files changed

Lines changed: 458 additions & 74 deletions

File tree

Doc/library/site.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,51 @@ Note that for some non-Unix systems, ``sys.prefix`` and ``sys.exec_prefix`` are
8282
empty, and the path manipulations are skipped; however the import of
8383
:mod:`sitecustomize` is still attempted.
8484

85+
86+
.. data:: PREFIXES
87+
88+
A list of prefixes for site package directories
89+
90+
.. versionadded:: 2.6
91+
92+
93+
.. data:: ENABLE_USER_SITE
94+
95+
Flag showing the status of the user site directory. True means the
96+
user site directory is enabled and added to sys.path. When the flag
97+
is None the user site directory is disabled for security reasons.
98+
99+
.. versionadded:: 2.6
100+
101+
102+
.. data:: USER_SITE
103+
104+
Path to the user site directory for the current Python version or None
105+
106+
.. versionadded:: 2.6
107+
108+
109+
.. data:: USER_BASE
110+
111+
Path to the base directory for user site directories
112+
113+
.. versionadded:: 2.6
114+
115+
116+
.. envvar:: PYTHONNOUSERSITE
117+
118+
.. versionadded:: 2.6
119+
120+
121+
.. envvar:: PYTHONUSERBASE
122+
123+
.. versionadded:: 2.6
124+
125+
126+
.. function:: addsitedir(sitedir, known_paths=None)
127+
128+
Adds a directory to sys.path and processes its pth files.
129+
130+
131+
XXX Update documentation
132+
XXX document python -m site --user-base --user-site

Doc/library/stdtypes.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,13 +1141,13 @@ The conversion types are:
11411141
+------------+-----------------------------------------------------+-------+
11421142
| ``'F'`` | Floating point decimal format. | \(3) |
11431143
+------------+-----------------------------------------------------+-------+
1144-
| ``'g'`` | Floating point format. Uses exponential format if | \(4) |
1145-
| | exponent is greater than -4 or less than precision, | |
1146-
| | decimal format otherwise. | |
1144+
| ``'g'`` | Floating point format. Uses lowercase exponential | \(4) |
1145+
| | format if exponent is less than -4 or not less than | |
1146+
| | precision, decimal format otherwise. | |
11471147
+------------+-----------------------------------------------------+-------+
1148-
| ``'G'`` | Floating point format. Uses exponential format if | \(4) |
1149-
| | exponent is greater than -4 or less than precision, | |
1150-
| | decimal format otherwise. | |
1148+
| ``'G'`` | Floating point format. Uses uppercase exponential | \(4) |
1149+
| | format if exponent is less than -4 or not less than | |
1150+
| | precision, decimal format otherwise. | |
11511151
+------------+-----------------------------------------------------+-------+
11521152
| ``'c'`` | Single character (accepts integer or single | |
11531153
| | character string). | |

Doc/using/cmdline.rst

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Command line
2121

2222
When invoking Python, you may specify any of these options::
2323

24-
python [-bdEiOStuUvxX?] [-c command | -m module-name | script | - ] [args]
24+
python [-bdEiOsStuUvxX?] [-c command | -m module-name | script | - ] [args]
2525

2626
The most common use case is, of course, a simple invocation of a script::
2727

@@ -214,6 +214,29 @@ Miscellaneous options
214214

215215

216216

217+
<<<<<<< .working
218+
=======
219+
.. seealso::
220+
:file:`Tools/scripts/fixdiv.py`
221+
for a use of ``warnall``
222+
223+
:pep:`238` -- Changing the division operator
224+
225+
226+
.. cmdoption:: -s
227+
228+
Don't add user site directory to sys.path
229+
230+
.. versionadded:: 2.6
231+
232+
.. seealso::
233+
234+
:pep:`370` -- Per user site-packages directory
235+
236+
237+
.. cmdoption:: -S
238+
239+
>>>>>>> .merge-right.r62788
217240
Disable the import of the module :mod:`site` and the site-dependent
218241
manipulations of :data:`sys.path` that it entails.
219242

@@ -424,6 +447,24 @@ These environment variables influence Python's behavior.
424447
.. versionadded:: 2.6
425448

426449

450+
.. envvar:: PYTHONNOUSERSITE
451+
452+
If this is set, Python won't add the user site directory to sys.path
453+
454+
.. seealso::
455+
456+
:pep:`370` -- Per user site-packages directory
457+
458+
459+
.. envvar:: PYTHONUSERBASE
460+
461+
Sets the base directory for the user site directory
462+
463+
.. seealso::
464+
465+
:pep:`370` -- Per user site-packages directory
466+
467+
427468
.. envvar:: PYTHONEXECUTABLE
428469

429470
If this environment variable is set, ``sys.argv[0]`` will be set to its

Include/pydebug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ PyAPI_DATA(int) Py_TabcheckFlag;
1818
PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
1919
PyAPI_DATA(int) Py_DivisionWarningFlag;
2020
PyAPI_DATA(int) Py_DontWriteBytecodeFlag;
21+
PyAPI_DATA(int) Py_NoUserSiteDirectory;
2122

2223
/* this is a wrapper around getenv() that pays attention to
2324
Py_IgnoreEnvironmentFlag. It should be used for getting variables like

Lib/distutils/command/install.py

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
from distutils.util import convert_path, subst_vars, change_root
1616
from distutils.util import get_platform
1717
from distutils.errors import DistutilsOptionError
18+
from site import USER_BASE
19+
from site import USER_SITE
20+
1821

1922
if sys.version < "2.2":
2023
WINDOWS_SCHEME = {
@@ -48,21 +51,49 @@
4851
'scripts': '$base/bin',
4952
'data' : '$base',
5053
},
54+
'unix_user': {
55+
'purelib': '$usersite',
56+
'platlib': '$usersite',
57+
'headers': '$userbase/include/python$py_version_short/$dist_name',
58+
'scripts': '$userbase/bin',
59+
'data' : '$userbase',
60+
},
5161
'nt': WINDOWS_SCHEME,
62+
'nt_user': {
63+
'purelib': '$usersite',
64+
'platlib': '$usersite',
65+
'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
66+
'scripts': '$userbase/Scripts',
67+
'data' : '$userbase',
68+
},
5269
'mac': {
5370
'purelib': '$base/Lib/site-packages',
5471
'platlib': '$base/Lib/site-packages',
5572
'headers': '$base/Include/$dist_name',
5673
'scripts': '$base/Scripts',
5774
'data' : '$base',
5875
},
76+
'mac_user': {
77+
'purelib': '$usersite',
78+
'platlib': '$usersite',
79+
'headers': '$userbase/$py_version_short/include/$dist_name',
80+
'scripts': '$userbase/bin',
81+
'data' : '$userbase',
82+
},
5983
'os2': {
6084
'purelib': '$base/Lib/site-packages',
6185
'platlib': '$base/Lib/site-packages',
6286
'headers': '$base/Include/$dist_name',
6387
'scripts': '$base/Scripts',
6488
'data' : '$base',
65-
}
89+
},
90+
'os2_home': {
91+
'purelib': '$usersite',
92+
'platlib': '$usersite',
93+
'headers': '$userbase/include/python$py_version_short/$dist_name',
94+
'scripts': '$userbase/bin',
95+
'data' : '$userbase',
96+
},
6697
}
6798

6899
# The keys to an installation scheme; if any new types of files are to be
@@ -83,6 +114,8 @@ class install (Command):
83114
"(Unix only) prefix for platform-specific files"),
84115
('home=', None,
85116
"(Unix only) home directory to install under"),
117+
('user', None,
118+
"install in user site-package '%s'" % USER_SITE),
86119

87120
# Or, just set the base director(y|ies)
88121
('install-base=', None,
@@ -134,7 +167,7 @@ class install (Command):
134167
"filename in which to record list of installed files"),
135168
]
136169

137-
boolean_options = ['compile', 'force', 'skip-build']
170+
boolean_options = ['compile', 'force', 'skip-build', 'user']
138171
negative_opt = {'no-compile' : 'compile'}
139172

140173

@@ -145,6 +178,7 @@ def initialize_options(self):
145178
self.prefix = None
146179
self.exec_prefix = None
147180
self.home = None
181+
self.user = 0
148182

149183
# These select only the installation base; it's up to the user to
150184
# specify the installation scheme (currently, that means supplying
@@ -163,6 +197,8 @@ def initialize_options(self):
163197
self.install_lib = None # set to either purelib or platlib
164198
self.install_scripts = None
165199
self.install_data = None
200+
self.install_userbase = USER_BASE
201+
self.install_usersite = USER_SITE
166202

167203
self.compile = None
168204
self.optimize = None
@@ -238,6 +274,11 @@ def finalize_options(self):
238274
raise DistutilsOptionError(
239275
"must supply either home or prefix/exec-prefix -- not both")
240276

277+
if self.user and (self.prefix or self.exec_prefix or self.home or
278+
self.install_base or self.install_platbase):
279+
raise DistutilsOptionError("can't combine user with with prefix/"
280+
"exec_prefix/home or install_(plat)base")
281+
241282
# Next, stuff that's wrong (or dubious) only on certain platforms.
242283
if os.name != "posix":
243284
if self.exec_prefix:
@@ -273,10 +314,13 @@ def finalize_options(self):
273314
'dist_fullname': self.distribution.get_fullname(),
274315
'py_version': py_version,
275316
'py_version_short': py_version[0:3],
317+
'py_version_nodot': py_version[0] + py_version[2],
276318
'sys_prefix': prefix,
277319
'prefix': prefix,
278320
'sys_exec_prefix': exec_prefix,
279321
'exec_prefix': exec_prefix,
322+
'userbase': self.install_userbase,
323+
'usersite': self.install_usersite,
280324
}
281325
self.expand_basedirs()
282326

@@ -298,6 +342,10 @@ def finalize_options(self):
298342

299343
self.dump_dirs("post-expand_dirs()")
300344

345+
# Create directories in the home dir:
346+
if self.user:
347+
self.create_home_path()
348+
301349
# Pick the actual directory to install all modules to: either
302350
# install_purelib or install_platlib, depending on whether this
303351
# module distribution is pure or not. Of course, if the user
@@ -312,7 +360,8 @@ def finalize_options(self):
312360
# Convert directories from Unix /-separated syntax to the local
313361
# convention.
314362
self.convert_paths('lib', 'purelib', 'platlib',
315-
'scripts', 'data', 'headers')
363+
'scripts', 'data', 'headers',
364+
'userbase', 'usersite')
316365

317366
# Well, we're not actually fully completely finalized yet: we still
318367
# have to deal with 'extra_path', which is the hack for allowing
@@ -369,7 +418,13 @@ def finalize_unix(self):
369418
"installation scheme is incomplete")
370419
return
371420

372-
if self.home is not None:
421+
if self.user:
422+
if self.install_userbase is None:
423+
raise DistutilsPlatformError(
424+
"User base directory is not specified")
425+
self.install_base = self.install_platbase = self.install_userbase
426+
self.select_scheme("unix_user")
427+
elif self.home is not None:
373428
self.install_base = self.install_platbase = self.home
374429
self.select_scheme("unix_home")
375430
else:
@@ -391,7 +446,13 @@ def finalize_unix(self):
391446

392447

393448
def finalize_other(self): # Windows and Mac OS for now
394-
if self.home is not None:
449+
if self.user:
450+
if self.install_userbase is None:
451+
raise DistutilsPlatformError(
452+
"User base directory is not specified")
453+
self.install_base = self.install_platbase = self.install_userbase
454+
self.select_scheme(os.name + "_user")
455+
elif self.home is not None:
395456
self.install_base = self.install_platbase = self.home
396457
self.select_scheme("unix_home")
397458
else:
@@ -419,7 +480,7 @@ def _expand_attrs(self, attrs):
419480
for attr in attrs:
420481
val = getattr(self, attr)
421482
if val is not None:
422-
if os.name == 'posix':
483+
if os.name == 'posix' or os.name == 'nt':
423484
val = os.path.expanduser(val)
424485
val = subst_vars(val, self.config_vars)
425486
setattr(self, attr, val)
@@ -479,6 +540,16 @@ def change_roots(self, *names):
479540
attr = "install_" + name
480541
setattr(self, attr, change_root(self.root, getattr(self, attr)))
481542

543+
def create_home_path(self):
544+
"""Create directories under ~
545+
"""
546+
if not self.user:
547+
return
548+
home = convert_path(os.path.expanduser("~"))
549+
for name, path in self.config_vars.iteritems():
550+
if path.startswith(home) and not os.path.isdir(path):
551+
self.debug_print("os.makedirs('%s', 0o700)" % path)
552+
os.makedirs(path, 0o700)
482553

483554
# -- Command execution methods -------------------------------------
484555

0 commit comments

Comments
 (0)