1 # Python Tools for Visual Studio
\r
2 # Copyright(c) Microsoft Corporation
\r
3 # All rights reserved.
\r
5 # Licensed under the Apache License, Version 2.0 (the License); you may not use
\r
6 # this file except in compliance with the License. You may obtain a copy of the
\r
7 # License at http://www.apache.org/licenses/LICENSE-2.0
\r
9 # THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
\r
10 # OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
\r
11 # IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
\r
12 # MERCHANTABLITY OR NON-INFRINGEMENT.
\r
14 # See the Apache Version 2.0 License for specific language governing
\r
15 # permissions and limitations under the License.
\r
17 __author__ = "Microsoft Corporation <ptvshelp@microsoft.com>"
\r
22 # HACK: macOS sets __cached__ to None for __main__
\r
23 # but site.main() cannot handle it. So we force it to a str.
\r
26 if 'site' in sys.modules:
\r
27 raise RuntimeError('script must be run with -S')
\r
29 BEFORE_SITE = list(sys.path)
\r
36 traceback.print_exc(file=sys.stderr)
\r
37 AFTER_SITE = list(sys.path)
\r
42 return os.path.normcase(os.path.abspath(path).rstrip(os.sep))
\r
45 BEFORE_SITE = set(clean(p) for p in BEFORE_SITE)
\r
46 AFTER_SITE = set(clean(p) for p in AFTER_SITE)
\r
47 SCRIPT_DIR = clean(os.path.dirname(os.path.realpath(__file__)))
\r
50 SITE_PKGS = set(clean(p) for p in site.getsitepackages())
\r
51 except AttributeError:
\r
57 getattr(sys, 'real_prefix', ''),
\r
58 getattr(sys, 'base_prefix', '')
\r
63 BEFORE_SITE.add(clean(prefix))
\r
65 for subdir in ['DLLs', 'Lib', 'Scripts']:
\r
66 d = clean(os.path.join(prefix, subdir))
\r
69 BEFORE_SITE.discard(None)
\r
70 AFTER_SITE.discard(None)
\r
77 if p == SCRIPT_DIR or p.startswith(SCRIPT_DIR + os.sep):
\r
80 if not os.path.isdir(p) and not (os.path.isfile(p) and zipfile.is_zipfile(p)):
\r
83 if p in BEFORE_SITE:
\r
84 print("%s|stdlib|" % p)
\r
85 elif p in AFTER_SITE:
\r
87 print("%s|site|" % p)
\r
89 print("%s|pth|" % p)
\r