Mercurial > cpython-lru_cache-weakref
annotate Lib/site.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 2d1ef9487c31 |
| children | 8d8c9bf2a04e 8976ec2cdfe5 |
| rev | line source |
|---|---|
|
6200
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
1 """Append module search paths for third-party packages to sys.path. |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
2 |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
3 **************************************************************** |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
4 * This module is automatically imported during initialization. * |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
5 **************************************************************** |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
6 |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
7 In earlier versions of Python (up to 1.5a3), scripts or modules that |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
8 needed to use site-specific modules would place ``import site'' |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
9 somewhere near the top of their code. Because of the automatic |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
10 import, this is no longer necessary (but code that does it still |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
11 works). |
| 4010 | 12 |
| 30723 | 13 This will append site-specific paths to the module search path. On |
|
38776
8fe373fb21d4
Fix site module docstring to match the code for Mac OSX, too
Nick Coghlan <ncoghlan@gmail.com>
parents:
38775
diff
changeset
|
14 Unix (including Mac OSX), it starts with sys.prefix and |
|
8fe373fb21d4
Fix site module docstring to match the code for Mac OSX, too
Nick Coghlan <ncoghlan@gmail.com>
parents:
38775
diff
changeset
|
15 sys.exec_prefix (if different) and appends |
|
8fe373fb21d4
Fix site module docstring to match the code for Mac OSX, too
Nick Coghlan <ncoghlan@gmail.com>
parents:
38775
diff
changeset
|
16 lib/python<version>/site-packages as well as lib/site-python. |
|
8fe373fb21d4
Fix site module docstring to match the code for Mac OSX, too
Nick Coghlan <ncoghlan@gmail.com>
parents:
38775
diff
changeset
|
17 On other platforms (such as Windows), it tries each of the |
|
38775
51732e81c796
Fix site module docstring to match the code
Nick Coghlan <ncoghlan@gmail.com>
parents:
37594
diff
changeset
|
18 prefixes directly, as well as with lib/site-packages appended. The |
|
6267
eb8d1a098b9d
Change packages -> site-packages
Guido van Rossum <guido@python.org>
parents:
6231
diff
changeset
|
19 resulting directories, if they exist, are appended to sys.path, and |
|
eb8d1a098b9d
Change packages -> site-packages
Guido van Rossum <guido@python.org>
parents:
6231
diff
changeset
|
20 also inspected for path configuration files. |
| 4010 | 21 |
|
6200
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
22 A path configuration file is a file whose name has the form |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
23 <package>.pth; its contents are additional directories (one per line) |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
24 to be added to sys.path. Non-existing directories (or |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
25 non-directories) are never added to sys.path; no directory is added to |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
26 sys.path more than once. Blank lines and lines beginning with |
|
21450
fa0bde3c86b2
Don't use Latex \code{...} in docstrings.
Guido van Rossum <guido@python.org>
parents:
21449
diff
changeset
|
27 '#' are skipped. Lines starting with 'import' are executed. |
| 4010 | 28 |
|
6200
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
29 For example, suppose sys.prefix and sys.exec_prefix are set to |
|
39506
e6fc4f99a61b
Update the docstring to use a version a little newer than 1999. This was
Neal Norwitz <nnorwitz@gmail.com>
parents:
38776
diff
changeset
|
30 /usr/local and there is a directory /usr/local/lib/python2.5/site-packages |
|
6267
eb8d1a098b9d
Change packages -> site-packages
Guido van Rossum <guido@python.org>
parents:
6231
diff
changeset
|
31 with three subdirectories, foo, bar and spam, and two path |
|
eb8d1a098b9d
Change packages -> site-packages
Guido van Rossum <guido@python.org>
parents:
6231
diff
changeset
|
32 configuration files, foo.pth and bar.pth. Assume foo.pth contains the |
|
eb8d1a098b9d
Change packages -> site-packages
Guido van Rossum <guido@python.org>
parents:
6231
diff
changeset
|
33 following: |
|
6200
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
34 |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
35 # foo package configuration |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
36 foo |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
37 bar |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
38 bletch |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
39 |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
40 and bar.pth contains: |
| 4010 | 41 |
|
6200
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
42 # bar package configuration |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
43 bar |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
44 |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
45 Then the following directories are added to sys.path, in this order: |
| 4010 | 46 |
|
39506
e6fc4f99a61b
Update the docstring to use a version a little newer than 1999. This was
Neal Norwitz <nnorwitz@gmail.com>
parents:
38776
diff
changeset
|
47 /usr/local/lib/python2.5/site-packages/bar |
|
e6fc4f99a61b
Update the docstring to use a version a little newer than 1999. This was
Neal Norwitz <nnorwitz@gmail.com>
parents:
38776
diff
changeset
|
48 /usr/local/lib/python2.5/site-packages/foo |
|
6200
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
49 |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
50 Note that bletch is omitted because it doesn't exist; bar precedes foo |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
51 because bar.pth comes alphabetically before foo.pth; and spam is |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
52 omitted because it is not mentioned in either path configuration file. |
| 4010 | 53 |
| 54 After these path manipulations, an attempt is made to import a module | |
|
6200
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
55 named sitecustomize, which can perform arbitrary additional |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
56 site-specific customizations. If this import fails with an |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
57 ImportError exception, it is silently ignored. |
| 4010 | 58 |
| 59 """ | |
| 60 | |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
61 import sys |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
62 import os |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
63 import __builtin__ |
| 4010 | 64 |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
65 # Prefixes for site-packages; add additional prefixes like /usr/local here |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
66 PREFIXES = [sys.prefix, sys.exec_prefix] |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
67 # Enable per user site-packages directory |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
68 # set it to False to disable the feature or True to force the feature |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
69 ENABLE_USER_SITE = None |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
70 # for distutils.commands.install |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
71 USER_SITE = None |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
72 USER_BASE = None |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
73 |
|
16949
09ba15ee1961
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16050
diff
changeset
|
74 |
|
14911
af8d77aa90f8
Convert all entries on sys.path to absolute paths, and also update the
Fred Drake <fdrake@acm.org>
parents:
14658
diff
changeset
|
75 def makepath(*paths): |
|
18364
2e1adbe89e4a
Avoid using os.path.normcase() on sys.path elements; doing so causes paths
Fred Drake <fdrake@acm.org>
parents:
18090
diff
changeset
|
76 dir = os.path.abspath(os.path.join(*paths)) |
|
2e1adbe89e4a
Avoid using os.path.normcase() on sys.path elements; doing so causes paths
Fred Drake <fdrake@acm.org>
parents:
18090
diff
changeset
|
77 return dir, os.path.normcase(dir) |
|
14911
af8d77aa90f8
Convert all entries on sys.path to absolute paths, and also update the
Fred Drake <fdrake@acm.org>
parents:
14658
diff
changeset
|
78 |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
79 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
80 def abs__file__(): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
81 """Set all module' __file__ attribute to an absolute path""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
82 for m in sys.modules.values(): |
| 37594 | 83 if hasattr(m, '__loader__'): |
|
37576
d11366f7e1e7
Updated the warnings, linecache, inspect, traceback, site, and doctest modules
Phillip J. Eby <pje@telecommunity.com>
parents:
36937
diff
changeset
|
84 continue # don't mess with a PEP 302-supplied __file__ |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
85 try: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
86 m.__file__ = os.path.abspath(m.__file__) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
87 except AttributeError: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
88 continue |
|
14911
af8d77aa90f8
Convert all entries on sys.path to absolute paths, and also update the
Fred Drake <fdrake@acm.org>
parents:
14658
diff
changeset
|
89 |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
90 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
91 def removeduppaths(): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
92 """ Remove duplicate entries from sys.path along with making them |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
93 absolute""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
94 # This ensures that the initial path provided by the interpreter contains |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
95 # only absolute pathnames, even if we're running from the build directory. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
96 L = [] |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
97 known_paths = set() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
98 for dir in sys.path: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
99 # Filter out duplicate paths (on case-insensitive file systems also |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
100 # if they only differ in case); turn relative paths into absolute |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
101 # paths. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
102 dir, dircase = makepath(dir) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
103 if not dircase in known_paths: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
104 L.append(dir) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
105 known_paths.add(dircase) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
106 sys.path[:] = L |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
107 return known_paths |
|
14911
af8d77aa90f8
Convert all entries on sys.path to absolute paths, and also update the
Fred Drake <fdrake@acm.org>
parents:
14658
diff
changeset
|
108 |
|
24382
4156bf9b0043
Add an XXX comment and a pointer to a full bug report.
Fred Drake <fdrake@acm.org>
parents:
23620
diff
changeset
|
109 # XXX This should not be part of site.py, since it is needed even when |
|
4156bf9b0043
Add an XXX comment and a pointer to a full bug report.
Fred Drake <fdrake@acm.org>
parents:
23620
diff
changeset
|
110 # using the -S option for Python. See http://www.python.org/sf/586680 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
111 def addbuilddir(): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
112 """Append ./build/lib.<platform> in case we're running in the build dir |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
113 (especially for Guido :-)""" |
|
29943
9013d3c1d655
Repair operator error.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29942
diff
changeset
|
114 from distutils.util import get_platform |
|
9013d3c1d655
Repair operator error.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29942
diff
changeset
|
115 s = "build/lib.%s-%.3s" % (get_platform(), sys.version) |
|
44862
101d86a1af85
Add the correct build dir when building with pydebug.
Georg Brandl <georg@python.org>
parents:
41781
diff
changeset
|
116 if hasattr(sys, 'gettotalrefcount'): |
|
101d86a1af85
Add the correct build dir when building with pydebug.
Georg Brandl <georg@python.org>
parents:
41781
diff
changeset
|
117 s += '-pydebug' |
|
16050
e62d5aff0c3a
A hack to augment sys.path with the build/lib.<platform> directory
Guido van Rossum <guido@python.org>
parents:
15815
diff
changeset
|
118 s = os.path.join(os.path.dirname(sys.path[-1]), s) |
|
e62d5aff0c3a
A hack to augment sys.path with the build/lib.<platform> directory
Guido van Rossum <guido@python.org>
parents:
15815
diff
changeset
|
119 sys.path.append(s) |
|
e62d5aff0c3a
A hack to augment sys.path with the build/lib.<platform> directory
Guido van Rossum <guido@python.org>
parents:
15815
diff
changeset
|
120 |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
121 |
|
18783
ac13a6ce13e2
Make the add*() helper functions more robust for use after intialization
Fred Drake <fdrake@acm.org>
parents:
18771
diff
changeset
|
122 def _init_pathinfo(): |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
123 """Return a set containing all existing directory entries from sys.path""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
124 d = set() |
|
18783
ac13a6ce13e2
Make the add*() helper functions more robust for use after intialization
Fred Drake <fdrake@acm.org>
parents:
18771
diff
changeset
|
125 for dir in sys.path: |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
126 try: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
127 if os.path.isdir(dir): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
128 dir, dircase = makepath(dir) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
129 d.add(dircase) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
130 except TypeError: |
|
18783
ac13a6ce13e2
Make the add*() helper functions more robust for use after intialization
Fred Drake <fdrake@acm.org>
parents:
18771
diff
changeset
|
131 continue |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
132 return d |
|
18783
ac13a6ce13e2
Make the add*() helper functions more robust for use after intialization
Fred Drake <fdrake@acm.org>
parents:
18771
diff
changeset
|
133 |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
134 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
135 def addpackage(sitedir, name, known_paths): |
|
41781
f14a5b005a1e
Fix docstring for add_package in site.py.
Georg Brandl <georg@python.org>
parents:
41123
diff
changeset
|
136 """Process a .pth file within the site-packages directory: |
|
f14a5b005a1e
Fix docstring for add_package in site.py.
Georg Brandl <georg@python.org>
parents:
41123
diff
changeset
|
137 For each line in the file, either combine it with sitedir to a path |
|
f14a5b005a1e
Fix docstring for add_package in site.py.
Georg Brandl <georg@python.org>
parents:
41123
diff
changeset
|
138 and add that to known_paths, or execute it if it starts with 'import '. |
|
f14a5b005a1e
Fix docstring for add_package in site.py.
Georg Brandl <georg@python.org>
parents:
41123
diff
changeset
|
139 """ |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
140 if known_paths is None: |
|
18783
ac13a6ce13e2
Make the add*() helper functions more robust for use after intialization
Fred Drake <fdrake@acm.org>
parents:
18771
diff
changeset
|
141 _init_pathinfo() |
|
ac13a6ce13e2
Make the add*() helper functions more robust for use after intialization
Fred Drake <fdrake@acm.org>
parents:
18771
diff
changeset
|
142 reset = 1 |
|
ac13a6ce13e2
Make the add*() helper functions more robust for use after intialization
Fred Drake <fdrake@acm.org>
parents:
18771
diff
changeset
|
143 else: |
|
ac13a6ce13e2
Make the add*() helper functions more robust for use after intialization
Fred Drake <fdrake@acm.org>
parents:
18771
diff
changeset
|
144 reset = 0 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
145 fullname = os.path.join(sitedir, name) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
146 try: |
|
32766
d15517f2abe8
Fix bug in addsitedir() to properly handle the lack of a second argument.
Brett Cannon <bcannon@gmail.com>
parents:
32566
diff
changeset
|
147 f = open(fullname, "rU") |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
148 except IOError: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
149 return |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
150 with f: |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
151 for line in f: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
152 if line.startswith("#"): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
153 continue |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
154 if line.startswith(("import ", "import\t")): |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
155 exec line |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
156 continue |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
157 line = line.rstrip() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
158 dir, dircase = makepath(sitedir, line) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
159 if not dircase in known_paths and os.path.exists(dir): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
160 sys.path.append(dir) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
161 known_paths.add(dircase) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
162 if reset: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
163 known_paths = None |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
164 return known_paths |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
165 |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
166 |
|
32566
3aadfc3fc4e6
Change argument list for addsitedir() to not require a second argument and thus
Brett Cannon <bcannon@gmail.com>
parents:
32528
diff
changeset
|
167 def addsitedir(sitedir, known_paths=None): |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
168 """Add 'sitedir' argument to sys.path if missing and handle .pth files in |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
169 'sitedir'""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
170 if known_paths is None: |
|
32766
d15517f2abe8
Fix bug in addsitedir() to properly handle the lack of a second argument.
Brett Cannon <bcannon@gmail.com>
parents:
32566
diff
changeset
|
171 known_paths = _init_pathinfo() |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
172 reset = 1 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
173 else: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
174 reset = 0 |
|
18364
2e1adbe89e4a
Avoid using os.path.normcase() on sys.path elements; doing so causes paths
Fred Drake <fdrake@acm.org>
parents:
18090
diff
changeset
|
175 sitedir, sitedircase = makepath(sitedir) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
176 if not sitedircase in known_paths: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7077
diff
changeset
|
177 sys.path.append(sitedir) # Add path component |
|
6200
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
178 try: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7077
diff
changeset
|
179 names = os.listdir(sitedir) |
|
6200
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
180 except os.error: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7077
diff
changeset
|
181 return |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
182 dotpth = os.extsep + "pth" |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
183 names = [name for name in names if name.endswith(dotpth)] |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
184 for name in sorted(names): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
185 addpackage(sitedir, name, known_paths) |
|
18783
ac13a6ce13e2
Make the add*() helper functions more robust for use after intialization
Fred Drake <fdrake@acm.org>
parents:
18771
diff
changeset
|
186 if reset: |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
187 known_paths = None |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
188 return known_paths |
|
6200
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
189 |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
190 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
191 def check_enableusersite(): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
192 """Check if user site directory is safe for inclusion |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
193 |
| 46830 | 194 The function tests for the command line flag (including environment var), |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
195 process uid/gid equal to effective uid/gid. |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
196 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
197 None: Disabled for security reasons |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
198 False: Disabled by user (command line option) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
199 True: Safe and enabled |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
200 """ |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
201 if sys.flags.no_user_site: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
202 return False |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
203 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
204 if hasattr(os, "getuid") and hasattr(os, "geteuid"): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
205 # check process uid == effective uid |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
206 if os.geteuid() != os.getuid(): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
207 return None |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
208 if hasattr(os, "getgid") and hasattr(os, "getegid"): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
209 # check process gid == effective gid |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
210 if os.getegid() != os.getgid(): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
211 return None |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
212 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
213 return True |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
214 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
215 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
216 def addusersitepackages(known_paths): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
217 """Add a per user site-package to sys.path |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
218 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
219 Each user has its own python directory with site-packages in the |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
220 home directory. |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
221 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
222 USER_BASE is the root directory for all Python versions |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
223 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
224 USER_SITE is the user specific site-packages directory |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
225 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
226 USER_SITE/.. can be used for data. |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
227 """ |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
228 global USER_BASE, USER_SITE, ENABLE_USER_SITE |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
229 env_base = os.environ.get("PYTHONUSERBASE", None) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
230 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
231 def joinuser(*args): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
232 return os.path.expanduser(os.path.join(*args)) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
233 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
234 #if sys.platform in ('os2emx', 'riscos'): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
235 # # Don't know what to put here |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
236 # USER_BASE = '' |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
237 # USER_SITE = '' |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
238 if os.name == "nt": |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
239 base = os.environ.get("APPDATA") or "~" |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
240 USER_BASE = env_base if env_base else joinuser(base, "Python") |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
241 USER_SITE = os.path.join(USER_BASE, |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
242 "Python" + sys.version[0] + sys.version[2], |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
243 "site-packages") |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
244 else: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
245 USER_BASE = env_base if env_base else joinuser("~", ".local") |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
246 USER_SITE = os.path.join(USER_BASE, "lib", |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
247 "python" + sys.version[:3], |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
248 "site-packages") |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
249 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
250 if ENABLE_USER_SITE and os.path.isdir(USER_SITE): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
251 addsitedir(USER_SITE, known_paths) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
252 return known_paths |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
253 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
254 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
255 def addsitepackages(known_paths): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
256 """Add site-packages (and possibly site-python) to sys.path""" |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
257 sitedirs = [] |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
258 seen = [] |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
259 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
260 for prefix in PREFIXES: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
261 if not prefix or prefix in seen: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
262 continue |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
263 seen.append(prefix) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
264 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
265 if sys.platform in ('os2emx', 'riscos'): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
266 sitedirs.append(os.path.join(prefix, "Lib", "site-packages")) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
267 elif os.sep == '/': |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
268 sitedirs.append(os.path.join(prefix, "lib", |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
269 "python" + sys.version[:3], |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
270 "site-packages")) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
271 sitedirs.append(os.path.join(prefix, "lib", "site-python")) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
272 else: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
273 sitedirs.append(prefix) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
274 sitedirs.append(os.path.join(prefix, "lib", "site-packages")) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
275 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
276 if sys.platform == "darwin": |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
277 # for framework builds *only* we add the standard Apple |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
278 # locations. Currently only per-user, but /Library and |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
279 # /Network/Library could be added too |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
280 if 'Python.framework' in prefix: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
281 sitedirs.append( |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
282 os.path.expanduser( |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
283 os.path.join("~", "Library", "Python", |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
284 sys.version[:3], "site-packages"))) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
285 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
286 for sitedir in sitedirs: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
287 if os.path.isdir(sitedir): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
288 addsitedir(sitedir, known_paths) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
289 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
290 return known_paths |
|
18783
ac13a6ce13e2
Make the add*() helper functions more robust for use after intialization
Fred Drake <fdrake@acm.org>
parents:
18771
diff
changeset
|
291 |
|
18364
2e1adbe89e4a
Avoid using os.path.normcase() on sys.path elements; doing so causes paths
Fred Drake <fdrake@acm.org>
parents:
18090
diff
changeset
|
292 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
293 def setBEGINLIBPATH(): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
294 """The OS/2 EMX port has optional extension modules that do double duty |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
295 as DLLs (and must use the .DLL file extension) for other extensions. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
296 The library search path needs to be amended so these will be found |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
297 during module import. Use BEGINLIBPATH so that these are at the start |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
298 of the library search path. |
|
32528
67539cfcf09f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
32246
diff
changeset
|
299 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
300 """ |
|
31065
41f4ce6c4e50
To find the curses extension as a DLL (on OS/2), we need to adjust the
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
30723
diff
changeset
|
301 dllpath = os.path.join(sys.prefix, "Lib", "lib-dynload") |
|
41f4ce6c4e50
To find the curses extension as a DLL (on OS/2), we need to adjust the
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
30723
diff
changeset
|
302 libpath = os.environ['BEGINLIBPATH'].split(';') |
|
41f4ce6c4e50
To find the curses extension as a DLL (on OS/2), we need to adjust the
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
30723
diff
changeset
|
303 if libpath[-1]: |
|
41f4ce6c4e50
To find the curses extension as a DLL (on OS/2), we need to adjust the
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
30723
diff
changeset
|
304 libpath.append(dllpath) |
|
41f4ce6c4e50
To find the curses extension as a DLL (on OS/2), we need to adjust the
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
30723
diff
changeset
|
305 else: |
|
41f4ce6c4e50
To find the curses extension as a DLL (on OS/2), we need to adjust the
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
30723
diff
changeset
|
306 libpath[-1] = dllpath |
|
41f4ce6c4e50
To find the curses extension as a DLL (on OS/2), we need to adjust the
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
30723
diff
changeset
|
307 os.environ['BEGINLIBPATH'] = ';'.join(libpath) |
|
41f4ce6c4e50
To find the curses extension as a DLL (on OS/2), we need to adjust the
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
30723
diff
changeset
|
308 |
|
41f4ce6c4e50
To find the curses extension as a DLL (on OS/2), we need to adjust the
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
30723
diff
changeset
|
309 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
310 def setquit(): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
311 """Define new built-ins 'quit' and 'exit'. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
312 These are simply strings that display a hint on how to exit. |
|
8878
813f527f3bec
Add built-in string variables 'quit' and 'exit' that display a hint on
Guido van Rossum <guido@python.org>
parents:
7755
diff
changeset
|
313 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
314 """ |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
315 if os.sep == ':': |
|
36922
d3d2f9ffdc06
Patch #1446372: quit and exit can now be called from the interactive
Georg Brandl <georg@python.org>
parents:
32766
diff
changeset
|
316 eof = 'Cmd-Q' |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
317 elif os.sep == '\\': |
|
36922
d3d2f9ffdc06
Patch #1446372: quit and exit can now be called from the interactive
Georg Brandl <georg@python.org>
parents:
32766
diff
changeset
|
318 eof = 'Ctrl-Z plus Return' |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
319 else: |
|
36922
d3d2f9ffdc06
Patch #1446372: quit and exit can now be called from the interactive
Georg Brandl <georg@python.org>
parents:
32766
diff
changeset
|
320 eof = 'Ctrl-D (i.e. EOF)' |
|
36937
df43c04d2554
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
36922
diff
changeset
|
321 |
|
36922
d3d2f9ffdc06
Patch #1446372: quit and exit can now be called from the interactive
Georg Brandl <georg@python.org>
parents:
32766
diff
changeset
|
322 class Quitter(object): |
|
d3d2f9ffdc06
Patch #1446372: quit and exit can now be called from the interactive
Georg Brandl <georg@python.org>
parents:
32766
diff
changeset
|
323 def __init__(self, name): |
|
d3d2f9ffdc06
Patch #1446372: quit and exit can now be called from the interactive
Georg Brandl <georg@python.org>
parents:
32766
diff
changeset
|
324 self.name = name |
|
d3d2f9ffdc06
Patch #1446372: quit and exit can now be called from the interactive
Georg Brandl <georg@python.org>
parents:
32766
diff
changeset
|
325 def __repr__(self): |
|
d3d2f9ffdc06
Patch #1446372: quit and exit can now be called from the interactive
Georg Brandl <georg@python.org>
parents:
32766
diff
changeset
|
326 return 'Use %s() or %s to exit' % (self.name, eof) |
|
d3d2f9ffdc06
Patch #1446372: quit and exit can now be called from the interactive
Georg Brandl <georg@python.org>
parents:
32766
diff
changeset
|
327 def __call__(self, code=None): |
|
39512
6e7b3dd58f98
Patch #1540892: site.py Quitter() class attempts to close sys.stdin
Kurt B. Kaiser <kbk@shore.net>
parents:
39506
diff
changeset
|
328 # Shells like IDLE catch the SystemExit, but listen when their |
|
6e7b3dd58f98
Patch #1540892: site.py Quitter() class attempts to close sys.stdin
Kurt B. Kaiser <kbk@shore.net>
parents:
39506
diff
changeset
|
329 # stdin wrapper is closed. |
|
6e7b3dd58f98
Patch #1540892: site.py Quitter() class attempts to close sys.stdin
Kurt B. Kaiser <kbk@shore.net>
parents:
39506
diff
changeset
|
330 try: |
|
6e7b3dd58f98
Patch #1540892: site.py Quitter() class attempts to close sys.stdin
Kurt B. Kaiser <kbk@shore.net>
parents:
39506
diff
changeset
|
331 sys.stdin.close() |
|
6e7b3dd58f98
Patch #1540892: site.py Quitter() class attempts to close sys.stdin
Kurt B. Kaiser <kbk@shore.net>
parents:
39506
diff
changeset
|
332 except: |
|
6e7b3dd58f98
Patch #1540892: site.py Quitter() class attempts to close sys.stdin
Kurt B. Kaiser <kbk@shore.net>
parents:
39506
diff
changeset
|
333 pass |
|
36922
d3d2f9ffdc06
Patch #1446372: quit and exit can now be called from the interactive
Georg Brandl <georg@python.org>
parents:
32766
diff
changeset
|
334 raise SystemExit(code) |
|
d3d2f9ffdc06
Patch #1446372: quit and exit can now be called from the interactive
Georg Brandl <georg@python.org>
parents:
32766
diff
changeset
|
335 __builtin__.quit = Quitter('quit') |
|
d3d2f9ffdc06
Patch #1446372: quit and exit can now be called from the interactive
Georg Brandl <georg@python.org>
parents:
32766
diff
changeset
|
336 __builtin__.exit = Quitter('exit') |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
337 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
338 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
339 class _Printer(object): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
340 """interactive prompt objects for printing the license text, a list of |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
341 contributors and the copyright notice.""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
342 |
|
14409
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
343 MAXLINES = 23 |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
344 |
|
14996
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
345 def __init__(self, name, data, files=(), dirs=()): |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
346 self.__name = name |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
347 self.__data = data |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
348 self.__files = files |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
349 self.__dirs = dirs |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
350 self.__lines = None |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
351 |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
352 def __setup(self): |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
353 if self.__lines: |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
354 return |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
355 data = None |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
356 for dir in self.__dirs: |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
357 for filename in self.__files: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
358 filename = os.path.join(dir, filename) |
|
14996
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
359 try: |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
360 fp = file(filename, "rU") |
|
14996
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
361 data = fp.read() |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
362 fp.close() |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
363 break |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
364 except IOError: |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
365 pass |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
366 if data: |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
367 break |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
368 if not data: |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
369 data = self.__data |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
370 self.__lines = data.split('\n') |
|
14409
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
371 self.__linecnt = len(self.__lines) |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
372 |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
373 def __repr__(self): |
|
14996
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
374 self.__setup() |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
375 if len(self.__lines) <= self.MAXLINES: |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
376 return "\n".join(self.__lines) |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
377 else: |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
378 return "Type %s() to see the full %s text" % ((self.__name,)*2) |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
379 |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
380 def __call__(self): |
|
5e4eed062b54
Fix a few problems with the _Printer class and the license variable.
Guido van Rossum <guido@python.org>
parents:
14911
diff
changeset
|
381 self.__setup() |
|
14409
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
382 prompt = 'Hit Return for more, or q (and Return) to quit: ' |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
383 lineno = 0 |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
384 while 1: |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
385 try: |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
386 for i in range(lineno, lineno + self.MAXLINES): |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
387 print self.__lines[i] |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
388 except IndexError: |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
389 break |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
390 else: |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
391 lineno += self.MAXLINES |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
392 key = None |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
393 while key is None: |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
394 key = raw_input(prompt) |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
395 if key not in ('', 'q'): |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
396 key = None |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
397 if key == 'q': |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
398 break |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
399 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
400 def setcopyright(): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
401 """Set 'copyright' and 'credits' in __builtin__""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
402 __builtin__.copyright = _Printer("copyright", sys.copyright) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
403 if sys.platform[:4] == 'java': |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
404 __builtin__.credits = _Printer( |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
405 "credits", |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
406 "Jython is maintained by the Jython developers (www.jython.org).") |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
407 else: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
408 __builtin__.credits = _Printer("credits", """\ |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
409 Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
410 for supporting Python development. See www.python.org for more information.""") |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
411 here = os.path.dirname(os.__file__) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
412 __builtin__.license = _Printer( |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
413 "license", "See http://www.python.org/%.3s/license.html" % sys.version, |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
414 ["LICENSE.txt", "LICENSE"], |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
415 [os.path.join(here, os.pardir), here, os.curdir]) |
|
14409
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
416 |
|
a76ab7c8fc29
Add new builtin commands "copyright", "license", "credits" which
Guido van Rossum <guido@python.org>
parents:
13614
diff
changeset
|
417 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
418 class _Helper(object): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
419 """Define the built-in 'help'. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
420 This is a wrapper around pydoc.help (with a twist). |
|
18090
41016675002f
Add new built-in 'help' which invokes pydoc.help (with a twist).
Guido van Rossum <guido@python.org>
parents:
17211
diff
changeset
|
421 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
422 """ |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
423 |
|
18090
41016675002f
Add new built-in 'help' which invokes pydoc.help (with a twist).
Guido van Rossum <guido@python.org>
parents:
17211
diff
changeset
|
424 def __repr__(self): |
|
41016675002f
Add new built-in 'help' which invokes pydoc.help (with a twist).
Guido van Rossum <guido@python.org>
parents:
17211
diff
changeset
|
425 return "Type help() for interactive help, " \ |
|
41016675002f
Add new built-in 'help' which invokes pydoc.help (with a twist).
Guido van Rossum <guido@python.org>
parents:
17211
diff
changeset
|
426 "or help(object) for help about object." |
|
41016675002f
Add new built-in 'help' which invokes pydoc.help (with a twist).
Guido van Rossum <guido@python.org>
parents:
17211
diff
changeset
|
427 def __call__(self, *args, **kwds): |
|
41016675002f
Add new built-in 'help' which invokes pydoc.help (with a twist).
Guido van Rossum <guido@python.org>
parents:
17211
diff
changeset
|
428 import pydoc |
|
41016675002f
Add new built-in 'help' which invokes pydoc.help (with a twist).
Guido van Rossum <guido@python.org>
parents:
17211
diff
changeset
|
429 return pydoc.help(*args, **kwds) |
|
41016675002f
Add new built-in 'help' which invokes pydoc.help (with a twist).
Guido van Rossum <guido@python.org>
parents:
17211
diff
changeset
|
430 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
431 def sethelper(): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
432 __builtin__.help = _Helper() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
433 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
434 def aliasmbcs(): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
435 """On Windows, some default encodings are not provided by Python, |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
436 while they are always available as "mbcs" in each locale. Make |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
437 them usable by aliasing to "mbcs" in such a case.""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
438 if sys.platform == 'win32': |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
439 import locale, codecs |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
440 enc = locale.getdefaultlocale()[1] |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
441 if enc.startswith('cp'): # "cp***" ? |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
442 try: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
443 codecs.lookup(enc) |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
444 except LookupError: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
445 import encodings |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
446 encodings._cache[enc] = encodings._unknown |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
447 encodings.aliases.aliases[enc] = 'mbcs' |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
448 |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
449 def setencoding(): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
450 """Set the string encoding used by the Unicode implementation. The |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
451 default is 'ascii', but if you're willing to experiment, you can |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
452 change this.""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
453 encoding = "ascii" # Default value set by _PyUnicode_Init() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
454 if 0: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
455 # Enable to support locale aware default string encodings. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
456 import locale |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
457 loc = locale.getdefaultlocale() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
458 if loc[1]: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
459 encoding = loc[1] |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
460 if 0: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
461 # Enable to switch off string to Unicode coercion and implicit |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
462 # Unicode to string conversion. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
463 encoding = "undefined" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
464 if encoding != "ascii": |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
465 # On Non-Unicode builds this will raise an AttributeError... |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
466 sys.setdefaultencoding(encoding) # Needs Python Unicode build ! |
|
18090
41016675002f
Add new built-in 'help' which invokes pydoc.help (with a twist).
Guido van Rossum <guido@python.org>
parents:
17211
diff
changeset
|
467 |
|
41016675002f
Add new built-in 'help' which invokes pydoc.help (with a twist).
Guido van Rossum <guido@python.org>
parents:
17211
diff
changeset
|
468 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
469 def execsitecustomize(): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
470 """Run custom site specific code, if available.""" |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
471 try: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
472 import sitecustomize |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
473 except ImportError: |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
474 pass |
|
28141
a3cf07bac373
Patch #671666: Alias ANSI code page to "mbcs".
Martin v. Löwis <martin@v.loewis.de>
parents:
26885
diff
changeset
|
475 |
|
13612
f3401ed132a1
-- changed default encoding to "ascii". you can still change
Fredrik Lundh <fredrik@pythonware.com>
parents:
13523
diff
changeset
|
476 |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
477 def execusercustomize(): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
478 """Run custom user specific code, if available.""" |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
479 try: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
480 import usercustomize |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
481 except ImportError: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
482 pass |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
483 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
484 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
485 def main(): |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
486 global ENABLE_USER_SITE |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
487 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
488 abs__file__() |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
489 known_paths = removeduppaths() |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
490 if (os.name == "posix" and sys.path and |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
491 os.path.basename(sys.path[-1]) == "Modules"): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
492 addbuilddir() |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
493 if ENABLE_USER_SITE is None: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
494 ENABLE_USER_SITE = check_enableusersite() |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
495 known_paths = addusersitepackages(known_paths) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
496 known_paths = addsitepackages(known_paths) |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
497 if sys.platform == 'os2emx': |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
498 setBEGINLIBPATH() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
499 setquit() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
500 setcopyright() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
501 sethelper() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
502 aliasmbcs() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
503 setencoding() |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
504 execsitecustomize() |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
505 if ENABLE_USER_SITE: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
506 execusercustomize() |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
507 # Remove sys.setdefaultencoding() so that users cannot change the |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
508 # encoding after initialization. The test for presence is needed when |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
509 # this module is run as a script, because this code is executed twice. |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
510 if hasattr(sys, "setdefaultencoding"): |
|
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
511 del sys.setdefaultencoding |
|
12873
efc6d7789d9e
Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents:
9520
diff
changeset
|
512 |
|
32246
70cfe065eac5
Refactored site.py into functions. Also moved over to using sets.
Brett Cannon <bcannon@gmail.com>
parents:
31726
diff
changeset
|
513 main() |
|
6200
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
514 |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
515 def _script(): |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
516 help = """\ |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
517 %s [--user-base] [--user-site] |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
518 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
519 Without arguments print some useful information |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
520 With arguments print the value of USER_BASE and/or USER_SITE separated |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
521 by '%s'. |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
522 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
523 Exit codes with --user-base or --user-site: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
524 0 - user site directory is enabled |
|
46788
f3f6a895a555
Add --user option to build_ext
Christian Heimes <christian@cheimes.de>
parents:
46698
diff
changeset
|
525 1 - user site directory is disabled by user |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
526 2 - uses site directory is disabled by super user |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
527 or for security reasons |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
528 >2 - unknown error |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
529 """ |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
530 args = sys.argv[1:] |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
531 if not args: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
532 print "sys.path = [" |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
533 for dir in sys.path: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
534 print " %r," % (dir,) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
535 print "]" |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
536 print "USER_BASE: %r (%s)" % (USER_BASE, |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
537 "exists" if os.path.isdir(USER_BASE) else "doesn't exist") |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
538 print "USER_SITE: %r (%s)" % (USER_SITE, |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
539 "exists" if os.path.isdir(USER_SITE) else "doesn't exist") |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
540 print "ENABLE_USER_SITE: %r" % ENABLE_USER_SITE |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
541 sys.exit(0) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
542 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
543 buffer = [] |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
544 if '--user-base' in args: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
545 buffer.append(USER_BASE) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
546 if '--user-site' in args: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
547 buffer.append(USER_SITE) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
548 |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
549 if buffer: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
550 print os.pathsep.join(buffer) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
551 if ENABLE_USER_SITE: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
552 sys.exit(0) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
553 elif ENABLE_USER_SITE is False: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
554 sys.exit(1) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
555 elif ENABLE_USER_SITE is None: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
556 sys.exit(2) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
557 else: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
558 sys.exit(3) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
559 else: |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
560 import textwrap |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
561 print textwrap.dedent(help % (sys.argv[0], os.pathsep)) |
|
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
562 sys.exit(10) |
|
6200
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
563 |
|
c57cede3c7c0
New site.py semantics. Searches in
Guido van Rossum <guido@python.org>
parents:
4010
diff
changeset
|
564 if __name__ == '__main__': |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
44862
diff
changeset
|
565 _script() |
