10 Commits

Author SHA1 Message Date
Dave Halter
0bf8a69024 v13.3 release notes 2019-02-24 18:45:07 +01:00
Dave Halter
9bb8f335c9 A small improvement for environments
see comment in 8d313e014f
2019-02-22 01:04:01 +01:00
Dave Halter
8d313e014f Check for specific Python versions first on unix, see davidhalter/jedi-vim#870 2019-02-22 00:34:03 +01:00
Dave Halter
a79d386eba Cleanup SameEnvironment and use the same logic for creation in virtualenvs 2019-02-22 00:24:55 +01:00
Dave Halter
48b137a7f5 Revert "Remove an used function"
This reverts commit efd8861d62.
2019-02-21 17:54:01 +01:00
Dave Halter
b4a4dacebd Fix embedded Python with Jedi (see comments in source code), fixes davidhalter/jedi-vim#870 2019-02-21 10:19:28 +01:00
Dave Halter
efd8861d62 Remove an used function 2019-02-21 10:16:17 +01:00
Dave Halter
2f86f549f5 Improve an error message, see #1279 2019-02-16 04:32:03 +01:00
Marc Zimmermann
cc0c4cc308 fixing permission denied errors with project.json 2019-02-16 04:28:26 +01:00
Dave Halter
9617d4527d setup.py was not executable in Python3.7 2018-12-15 22:18:42 +01:00
8 changed files with 72 additions and 10 deletions

View File

@@ -3,6 +3,11 @@
Changelog
---------
0.13.3 (2019-02-24)
+++++++++++++++++++
- Fixed an issue with embedded Pytho, see https://github.com/davidhalter/jedi-vim/issues/870
0.13.2 (2018-12-15)
+++++++++++++++++++

View File

@@ -36,7 +36,7 @@ As you see Jedi is pretty simple and allows you to concentrate on writing a
good text editor, while still having very good IDE features for Python.
"""
__version__ = '0.13.2'
__version__ = '0.13.3'
from jedi.api import Script, Interpreter, set_debug_function, \
preload_module, names

View File

@@ -348,6 +348,11 @@ try:
except NameError:
NotADirectoryError = IOError
try:
PermissionError = PermissionError
except NameError:
PermissionError = IOError
def no_unicode_pprint(dct):
"""

View File

@@ -153,9 +153,9 @@ def _get_virtual_env_from_var():
variable is considered to be safe / controlled by the user solely.
"""
var = os.environ.get('VIRTUAL_ENV')
if var is not None:
if var:
if var == sys.prefix:
return SameEnvironment()
return _try_get_same_env()
try:
return create_environment(var, safe=False)
@@ -184,9 +184,47 @@ def get_default_environment():
if virtual_env is not None:
return virtual_env
# If no VirtualEnv is found, use the environment we're already
return _try_get_same_env()
def _try_get_same_env():
env = SameEnvironment()
if not os.path.basename(env.executable).lower().startswith('python'):
# This tries to counter issues with embedding. In some cases (e.g.
# VIM's Python Mac/Windows, sys.executable is /foo/bar/vim. This
# happens, because for Mac a function called `_NSGetExecutablePath` is
# used and for Windows `GetModuleFileNameW`. These are both platform
# specific functions. For all other systems sys.executable should be
# alright. However here we try to generalize:
#
# 1. Check if the executable looks like python (heuristic)
# 2. In case it's not try to find the executable
# 3. In case we don't find it use an interpreter environment.
#
# The last option will always work, but leads to potential crashes of
# Jedi - which is ok, because it happens very rarely and even less,
# because the code below should work for most cases.
if os.name == 'nt':
# The first case would be a virtualenv and the second a normal
# Python installation.
checks = (r'Scripts\python.exe', 'python.exe')
else:
# For unix it looks like Python is always in a bin folder.
checks = (
'bin/python%s.%s' % (sys.version_info[0], sys.version[1]),
'bin/python%s' % (sys.version_info[0]),
'bin/python',
)
for check in checks:
guess = os.path.join(sys.exec_prefix, check)
if os.path.isfile(guess):
# Bingo - We think we have our Python.
return Environment(guess)
# It looks like there is no reasonable Python to be found.
return InterpreterEnvironment()
# If no virtualenv is found, use the environment we're already
# using.
return SameEnvironment()
return env
def get_cached_default_environment():

View File

@@ -130,7 +130,10 @@ def get_stack_at_position(grammar, code_lines, module_node, pos):
p.parse(tokens=tokenize_without_endmarker(code))
except EndMarkerReached:
return p.stack
raise SystemError("This really shouldn't happen. There's a bug in Jedi.")
raise SystemError(
"This really shouldn't happen. There's a bug in Jedi:\n%s"
% list(tokenize_without_endmarker(code))
)
def evaluate_goto_definition(evaluator, context, leaf):

View File

@@ -1,7 +1,7 @@
import os
import json
from jedi._compatibility import FileNotFoundError, NotADirectoryError
from jedi._compatibility import FileNotFoundError, NotADirectoryError, PermissionError
from jedi.api.environment import SameEnvironment, \
get_cached_default_environment
from jedi.api.exceptions import WrongVersion
@@ -151,7 +151,7 @@ def _is_django_path(directory):
try:
with open(os.path.join(directory, 'manage.py'), 'rb') as f:
return b"DJANGO_SETTINGS_MODULE" in f.read()
except (FileNotFoundError, NotADirectoryError):
except (FileNotFoundError, NotADirectoryError, PermissionError):
return False
return False
@@ -167,7 +167,7 @@ def get_default_project(path=None):
for dir in traverse_parents(check, include_current=True):
try:
return Project.load(dir)
except (FileNotFoundError, NotADirectoryError):
except (FileNotFoundError, NotADirectoryError, PermissionError):
pass
if first_no_init_file is None:

View File

@@ -10,7 +10,7 @@ __AUTHOR_EMAIL__ = 'davidhalter88@gmail.com'
# Get the version from within jedi. It's defined in exactly one place now.
with open('jedi/__init__.py') as f:
tree = ast.parse(f.read())
version = tree.body[1].value.s
version = tree.body[int(not hasattr(tree, 'docstring'))].value.s
readme = open('README.rst').read() + '\n\n' + open('CHANGELOG.rst').read()
with open('requirements.txt') as f:

View File

@@ -131,6 +131,17 @@ def test_get_default_environment_from_env_does_not_use_safe(tmpdir, monkeypatch)
assert env.path == 'fake'
@pytest.mark.parametrize('virtualenv', ['', 'fufuuuuu', sys.prefix])
def test_get_default_environment_when_embedded(monkeypatch, virtualenv):
# When using Python embedded, sometimes the executable is not a Python
# executable.
executable_name = 'RANDOM_EXE'
monkeypatch.setattr(sys, 'executable', executable_name)
monkeypatch.setenv('VIRTUAL_ENV', virtualenv)
env = get_default_environment()
assert env.executable != executable_name
def test_changing_venv(venv_path, monkeypatch):
monkeypatch.setitem(os.environ, 'VIRTUAL_ENV', venv_path)
get_cached_default_environment()