Revision 1227
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/pylint/epylint.py | ||
---|---|---|
53 | 53 |
import sys |
54 | 54 |
from subprocess import Popen, PIPE |
55 | 55 |
|
56 |
def sys_path(): |
|
57 |
if sys.getClassLoader()!=None: |
|
58 |
path = getattr(sys.getClassLoader(),"path",None) |
|
59 |
if path != None: |
|
60 |
return path(sys.path) |
|
61 |
path = [ folder for folder in sys.path if not folder.startswith("__") ] |
|
62 |
return path |
|
63 |
|
|
56 | 64 |
def _get_env(): |
57 | 65 |
'''Extracts the environment PYTHONPATH and appends the current sys.path to |
58 | 66 |
those.''' |
59 | 67 |
env = dict(os.environ) |
60 |
env['PYTHONPATH'] = os.pathsep.join(sys.path)
|
|
68 |
env['PYTHONPATH'] = os.pathsep.join(sys_path()))
|
|
61 | 69 |
return env |
62 | 70 |
|
63 | 71 |
def lint(filename, options=None): |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/pylint/utils.py | ||
---|---|---|
945 | 945 |
|
946 | 946 |
PY_EXTS = ('.py', '.pyc', '.pyo', '.pyw', '.so', '.dll') |
947 | 947 |
|
948 |
def listdir(directory): |
|
949 |
#print "@@@ listdir ", repr(directory) |
|
950 |
if directory!=u'__pyclasspath__/': |
|
951 |
return os.listdir(directory) |
|
952 |
files = list() |
|
953 |
urls = sys.getClassLoader().getURLs() |
|
954 |
for url in urls: |
|
955 |
f = unicode(url) |
|
956 |
if f.startswith("file:") and f.endswith("/"): |
|
957 |
f = f[5:] |
|
958 |
for filename in os.listdir(f): |
|
959 |
files.append(filename) |
|
960 |
return files |
|
961 |
|
|
962 |
def join_ex(directory,filename): |
|
963 |
#print("### join_ex: ", repr(directory), repr(filename)) |
|
964 |
if directory!=u'__pyclasspath__/': |
|
965 |
return join(directory,filename) |
|
966 |
return sys.getClassLoader().getResourcePath(join(directory,filename)) |
|
967 |
|
|
968 | 948 |
def register_plugins(linter, directory): |
969 | 949 |
"""load all module and package in the given directory, looking for a |
970 | 950 |
'register' function in each one, used to register pylint checkers |
971 | 951 |
""" |
972 | 952 |
imported = {} |
973 |
for filename in listdir_ex(directory):
|
|
953 |
for filename in os.listdir(directory):
|
|
974 | 954 |
base, extension = splitext(filename) |
975 | 955 |
if base in imported or base == '__pycache__': |
976 | 956 |
continue |
977 | 957 |
if extension in PY_EXTS and base != '__init__' or ( |
978 |
not extension and isdir(join_ex(directory, base))):
|
|
958 |
not extension and isdir(join(directory, base))): |
|
979 | 959 |
try: |
980 |
module = load_module_from_file(join_ex(directory, filename))
|
|
960 |
module = load_module_from_file(join(directory, filename)) |
|
981 | 961 |
except ValueError: |
982 | 962 |
# empty module name (usually emacs auto-save files) |
983 | 963 |
continue |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/pylint/lint.py | ||
---|---|---|
59 | 59 |
SYMBOLS_HELP = ("Deprecated. It was used to include symbolic ids of " |
60 | 60 |
"messages in output. Use --msg-template instead.") |
61 | 61 |
|
62 |
def sys_path(): |
|
63 |
if sys.getClassLoader()!=None: |
|
64 |
path = getattr(sys.getClassLoader(),"path",None) |
|
65 |
if path != None: |
|
66 |
return path(sys.path) |
|
67 |
path = [ folder for folder in sys.path if not folder.startswith("__") ] |
|
68 |
return path |
|
69 |
|
|
62 | 70 |
def _get_new_args(message): |
63 | 71 |
location = ( |
64 | 72 |
message.abspath, |
... | ... | |
1121 | 1129 |
We avoid adding duplicate directories to sys.path. |
1122 | 1130 |
`sys.path` is reset to its original value upon exitign this context. |
1123 | 1131 |
""" |
1124 |
orig = list(sys.path)
|
|
1132 |
orig = list(sys_path())
|
|
1125 | 1133 |
changes = [] |
1126 | 1134 |
for arg in args: |
1127 | 1135 |
path = _get_python_path(arg) |
... | ... | |
1129 | 1137 |
continue |
1130 | 1138 |
else: |
1131 | 1139 |
changes.append(path) |
1132 |
sys.path[:] = changes + sys.path
|
|
1140 |
sys.path[:] = changes + sys_path()
|
|
1133 | 1141 |
try: |
1134 | 1142 |
yield |
1135 | 1143 |
finally: |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/astroid/__init__.py | ||
---|---|---|
123 | 123 |
manager.register_transform(Module, transform, lambda n: n.name == module_name) |
124 | 124 |
|
125 | 125 |
|
126 |
def sys_path(): |
|
127 |
if sys.getClassLoader()==None: |
|
128 |
return sys.path |
|
129 |
path = getattr(sys.getClassLoader(),"path",None) |
|
130 |
if path == None: |
|
131 |
return sys.path |
|
132 |
return path(sys.path) |
|
133 |
|
|
126 | 134 |
# load brain plugins |
127 | 135 |
from os import listdir |
128 | 136 |
from os.path import join, dirname |
... | ... | |
132 | 140 |
if getResourcePath!=None: |
133 | 141 |
_file_ = getResourcePath(_file_) |
134 | 142 |
BRAIN_MODULES_DIR = join(dirname(_file_), 'brain') |
135 |
if BRAIN_MODULES_DIR not in sys.path:
|
|
143 |
if BRAIN_MODULES_DIR not in sys_path():
|
|
136 | 144 |
# add it to the end of the list so user path take precedence |
137 | 145 |
sys.path.append(BRAIN_MODULES_DIR) |
138 | 146 |
# load modules in this directory |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/astroid/modutils.py | ||
---|---|---|
110 | 110 |
IS_JYTHON = platform.python_implementation() == 'Jython' |
111 | 111 |
BUILTIN_MODULES = dict.fromkeys(sys.builtin_module_names, True) |
112 | 112 |
|
113 |
def sys_path(): |
|
114 |
if sys.getClassLoader()!=None: |
|
115 |
path = getattr(sys.getClassLoader(),"path",None) |
|
116 |
if path != None: |
|
117 |
return path(sys.path) |
|
118 |
path = [ folder for folder in sys.path if not folder.startswith("__") ] |
|
119 |
return path |
|
113 | 120 |
|
114 | 121 |
class NoSourceFile(Exception): |
115 | 122 |
"""exception raised when we are not able to get a python |
... | ... | |
310 | 317 |
if pkg] |
311 | 318 |
if _check_init(path, submodpath[:-1]): |
312 | 319 |
return extrapath[path_].split('.') + submodpath |
313 |
for path in sys.path:
|
|
320 |
for path in sys_path():
|
|
314 | 321 |
path = _cache_normalize_path(path) |
315 | 322 |
if path and os.path.normcase(base).startswith(path): |
316 | 323 |
modpath = [pkg for pkg in base[len(path):].split(os.sep) if pkg] |
317 | 324 |
if _check_init(path, modpath[:-1]): |
318 | 325 |
return modpath |
319 | 326 |
raise ImportError('Unable to find module for %s in %s' % ( |
320 |
filename, ', \n'.join(sys.path)))
|
|
327 |
filename, ', \n'.join(sys_path())))
|
|
321 | 328 |
|
322 | 329 |
|
323 | 330 |
def file_from_modpath(modpath, path=None, context_file=None): |
... | ... | |
553 | 560 |
""" |
554 | 561 |
if not os.path.isdir(from_file): |
555 | 562 |
from_file = os.path.dirname(from_file) |
556 |
if from_file in sys.path:
|
|
563 |
if from_file in sys_path():
|
|
557 | 564 |
return False |
558 | 565 |
try: |
559 | 566 |
stream, _, _ = imp.find_module(modname.split('.')[0], [from_file]) |
... | ... | |
639 | 646 |
# egg support compat |
640 | 647 |
try: |
641 | 648 |
pic = sys.path_importer_cache |
642 |
_path = (path is None and sys.path or path)
|
|
649 |
_path = (path is None and sys_path() or path)
|
|
643 | 650 |
for __path in _path: |
644 | 651 |
if not __path in pic: |
645 | 652 |
try: |
... | ... | |
716 | 723 |
if extend_path or declare_namespace: |
717 | 724 |
# extend_path is called, search sys.path for module/packages |
718 | 725 |
# of this name see pkgutil.extend_path documentation |
719 |
path = [os.path.join(p, *imported) for p in sys.path
|
|
726 |
path = [os.path.join(p, *imported) for p in sys_path()
|
|
720 | 727 |
if os.path.isdir(os.path.join(p, *imported))] |
721 | 728 |
else: |
722 | 729 |
path = [mp_filename] |
Also available in: Unified diff