massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / coc-python-data / languageServer.0.5.59 / get_search_paths.py
1 # Python Tools for Visual Studio\r
2 # Copyright(c) Microsoft Corporation\r
3 # All rights reserved.\r
4\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
8\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
13\r
14 # See the Apache Version 2.0 License for specific language governing\r
15 # permissions and limitations under the License.\r
16 \r
17 __author__ = "Microsoft Corporation <ptvshelp@microsoft.com>"\r
18 __version__ = "3.2"\r
19 \r
20 import sys\r
21 \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
24 __cached__ = ''\r
25 \r
26 if 'site' in sys.modules:\r
27     raise RuntimeError('script must be run with -S')\r
28 \r
29 BEFORE_SITE = list(sys.path)\r
30 \r
31 import site\r
32 try:\r
33     site.main()\r
34 except:\r
35     import traceback\r
36     traceback.print_exc(file=sys.stderr)\r
37 AFTER_SITE = list(sys.path)\r
38 \r
39 import os\r
40 def clean(path):\r
41     if path:\r
42         return os.path.normcase(os.path.abspath(path).rstrip(os.sep))\r
43     return None\r
44 \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
48 \r
49 try:\r
50     SITE_PKGS = set(clean(p) for p in site.getsitepackages())\r
51 except AttributeError:\r
52     SITE_PKGS = set()\r
53 \r
54 for prefix in [\r
55     sys.prefix,\r
56     sys.exec_prefix,\r
57     getattr(sys, 'real_prefix', ''),\r
58     getattr(sys, 'base_prefix', '')\r
59 ]:\r
60     if not prefix:\r
61         continue\r
62 \r
63     BEFORE_SITE.add(clean(prefix))\r
64     \r
65     for subdir in ['DLLs', 'Lib', 'Scripts']:\r
66         d = clean(os.path.join(prefix, subdir))\r
67         BEFORE_SITE.add(d)\r
68 \r
69 BEFORE_SITE.discard(None)\r
70 AFTER_SITE.discard(None)\r
71 \r
72 import zipfile\r
73 \r
74 for p in sys.path:\r
75     p = clean(p)\r
76     \r
77     if p == SCRIPT_DIR or p.startswith(SCRIPT_DIR + os.sep):\r
78         continue\r
79 \r
80     if not os.path.isdir(p) and not (os.path.isfile(p) and zipfile.is_zipfile(p)):\r
81         continue\r
82 \r
83     if p in BEFORE_SITE:\r
84         print("%s|stdlib|" % p)\r
85     elif p in AFTER_SITE:\r
86         if p in SITE_PKGS:\r
87             print("%s|site|" % p)\r
88         else:\r
89             print("%s|pth|" % p)\r