OLD | NEW |
1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. | 1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr | 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # | 3 # |
4 # This file is part of astroid. | 4 # This file is part of astroid. |
5 # | 5 # |
6 # astroid is free software: you can redistribute it and/or modify it under | 6 # astroid is free software: you can redistribute it and/or modify it under |
7 # the terms of the GNU Lesser General Public License as published by the Free | 7 # the terms of the GNU Lesser General Public License as published by the Free |
8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y | 8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y |
9 # later version. | 9 # later version. |
10 # | 10 # |
11 # astroid is distributed in the hope that it will be useful, but WITHOUT | 11 # astroid is distributed in the hope that it will be useful, but WITHOUT |
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | 13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
14 # details. | 14 # details. |
15 # | 15 # |
16 # You should have received a copy of the GNU Lesser General Public License along | 16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with astroid. If not, see <http://www.gnu.org/licenses/>. | 17 # with astroid. If not, see <http://www.gnu.org/licenses/>. |
18 """Python modules manipulation utility functions. | 18 """Python modules manipulation utility functions. |
19 | 19 |
20 :type PY_SOURCE_EXTS: tuple(str) | 20 :type PY_SOURCE_EXTS: tuple(str) |
21 :var PY_SOURCE_EXTS: list of possible python source file extension | 21 :var PY_SOURCE_EXTS: list of possible python source file extension |
22 | 22 |
23 :type STD_LIB_DIRS: list of str | 23 :type STD_LIB_DIRS: set of str |
24 :var STD_LIB_DIRS: directories where standard modules are located | 24 :var STD_LIB_DIRS: directories where standard modules are located |
25 | 25 |
26 :type BUILTIN_MODULES: dict | 26 :type BUILTIN_MODULES: dict |
27 :var BUILTIN_MODULES: dictionary with builtin module names has key | 27 :var BUILTIN_MODULES: dictionary with builtin module names has key |
28 """ | 28 """ |
29 from __future__ import with_statement | 29 from __future__ import with_statement |
30 | 30 |
31 __docformat__ = "restructuredtext en" | 31 __docformat__ = "restructuredtext en" |
32 | 32 |
33 import imp | 33 import imp |
(...skipping 13 matching lines...) Expand all Loading... |
47 PY_ZIPMODULE = object() | 47 PY_ZIPMODULE = object() |
48 | 48 |
49 if sys.platform.startswith('win'): | 49 if sys.platform.startswith('win'): |
50 PY_SOURCE_EXTS = ('py', 'pyw') | 50 PY_SOURCE_EXTS = ('py', 'pyw') |
51 PY_COMPILED_EXTS = ('dll', 'pyd') | 51 PY_COMPILED_EXTS = ('dll', 'pyd') |
52 else: | 52 else: |
53 PY_SOURCE_EXTS = ('py',) | 53 PY_SOURCE_EXTS = ('py',) |
54 PY_COMPILED_EXTS = ('so',) | 54 PY_COMPILED_EXTS = ('so',) |
55 | 55 |
56 # Notes about STD_LIB_DIRS | 56 # Notes about STD_LIB_DIRS |
57 # Consider arch-specific installation for STD_LIB_DIR definition | 57 # Consider arch-specific installation for STD_LIB_DIRS definition |
58 # :mod:`distutils.sysconfig` contains to much hardcoded values to rely on | 58 # :mod:`distutils.sysconfig` contains to much hardcoded values to rely on |
59 # | 59 # |
60 # :see: `Problems with /usr/lib64 builds <http://bugs.python.org/issue1294959>`_ | 60 # :see: `Problems with /usr/lib64 builds <http://bugs.python.org/issue1294959>`_ |
61 # :see: `FHS <http://www.pathname.com/fhs/pub/fhs-2.3.html#LIBLTQUALGTALTERNATEF
ORMATESSENTIAL>`_ | 61 # :see: `FHS <http://www.pathname.com/fhs/pub/fhs-2.3.html#LIBLTQUALGTALTERNATEF
ORMATESSENTIAL>`_ |
62 try: | 62 try: |
63 # The explicit prefix is to work around a patch in virtualenv that | 63 # The explicit sys.prefix is to work around a patch in virtualenv that |
64 # replaces the 'real' sys.prefix (i.e. the location of the binary) | 64 # replaces the 'real' sys.prefix (i.e. the location of the binary) |
65 # with the prefix from which the virtualenv was created. This throws | 65 # with the prefix from which the virtualenv was created. This throws |
66 # off the detection logic for standard library modules, thus the | 66 # off the detection logic for standard library modules, thus the |
67 # workaround. | 67 # workaround. |
68 STD_LIB_DIRS = [ | 68 STD_LIB_DIRS = { |
69 get_python_lib(standard_lib=True, prefix=sys.prefix), | 69 get_python_lib(standard_lib=True, prefix=sys.prefix), |
70 get_python_lib(standard_lib=True)] | 70 # Take care of installations where exec_prefix != prefix. |
| 71 get_python_lib(standard_lib=True, prefix=sys.exec_prefix), |
| 72 get_python_lib(standard_lib=True)} |
71 if os.name == 'nt': | 73 if os.name == 'nt': |
72 STD_LIB_DIRS.append(os.path.join(sys.prefix, 'dlls')) | 74 STD_LIB_DIRS.add(os.path.join(sys.prefix, 'dlls')) |
73 try: | 75 try: |
74 # real_prefix is defined when running inside virtualenv. | 76 # real_prefix is defined when running inside virtualenv. |
75 STD_LIB_DIRS.append(os.path.join(sys.real_prefix, 'dlls')) | 77 STD_LIB_DIRS.add(os.path.join(sys.real_prefix, 'dlls')) |
76 except AttributeError: | 78 except AttributeError: |
77 pass | 79 pass |
78 # get_python_lib(standard_lib=1) is not available on pypy, set STD_LIB_DIR to | 80 # get_python_lib(standard_lib=1) is not available on pypy, set STD_LIB_DIR to |
79 # non-valid path, see https://bugs.pypy.org/issue1164 | 81 # non-valid path, see https://bugs.pypy.org/issue1164 |
80 except DistutilsPlatformError: | 82 except DistutilsPlatformError: |
81 STD_LIB_DIRS = [] | 83 STD_LIB_DIRS = set() |
82 | 84 |
83 EXT_LIB_DIR = get_python_lib() | 85 EXT_LIB_DIR = get_python_lib() |
84 | 86 |
85 BUILTIN_MODULES = dict(zip(sys.builtin_module_names, | 87 BUILTIN_MODULES = dict(zip(sys.builtin_module_names, |
86 [1]*len(sys.builtin_module_names))) | 88 [1]*len(sys.builtin_module_names))) |
87 | 89 |
88 | 90 |
89 class NoSourceFile(Exception): | 91 class NoSourceFile(Exception): |
90 """exception raised when we are not able to get a python | 92 """exception raised when we are not able to get a python |
91 source file for a precompiled file | 93 source file for a precompiled file |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 | 661 |
660 def _has_init(directory): | 662 def _has_init(directory): |
661 """if the given directory has a valid __init__ file, return its path, | 663 """if the given directory has a valid __init__ file, return its path, |
662 else return None | 664 else return None |
663 """ | 665 """ |
664 mod_or_pack = os.path.join(directory, '__init__') | 666 mod_or_pack = os.path.join(directory, '__init__') |
665 for ext in PY_SOURCE_EXTS + ('pyc', 'pyo'): | 667 for ext in PY_SOURCE_EXTS + ('pyc', 'pyo'): |
666 if os.path.exists(mod_or_pack + '.' + ext): | 668 if os.path.exists(mod_or_pack + '.' + ext): |
667 return mod_or_pack + '.' + ext | 669 return mod_or_pack + '.' + ext |
668 return None | 670 return None |
OLD | NEW |