-
-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment: improve/fix getting sys.prefix #1108
Conversation
I like the idea of fixing all of this. I just think we should probably do it right. We should probably just start the subprocess and work with it instead of trying stuff with |
Let's move it into EvaluatorSubprocess then? |
I guess, yes. Probably to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another unsubmitted pending review.
@@ -55,40 +55,53 @@ class Environment(_BaseEnvironment): | |||
should not create it directly. Please use create_environment or the other | |||
functions instead. It is then returned by that function. | |||
""" | |||
def __init__(self, path, executable): | |||
self.path = os.path.abspath(path) | |||
def __init__(self, executable): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change the signature to def __init__(self, exe, executable=None, prefix=None, version_info=None):
and then make executable
, prefix
and version_info
lazy-evaluated and memoized properties?
Would allow to specify some of the properties directly, and get others once on demand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, what's the advantage of specifying all those things? I would probably prefer simplicity. If we have to check it anyway for some cases, checking it for all cases probably makes sense. (It doesn't take a lot of time, what takes a lot of time is to start a Python interpreter).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everythings gets retrieved in one go now.
jedi/api/environment.py
Outdated
def __init__(self, path, executable): | ||
self.path = os.path.abspath(path) | ||
def __init__(self, executable): | ||
self.path = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path
might get renamed to prefix
for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree. The only problem is that the API is alrady out there. But we can probably just deprecate self.path
.
Just a side-note: for jedi-vim it would be beneficial to get an Environment based on the exe only. I will now look into addressing your comments / improve this. |
I agree. It's probably generally better for a lot of use cases to just specify an executable. For virtualenvs it's sometimes more practical to specify a prefix, but that could just try to locate the exe and then progress like the exe mechanism. |
Refactored, please review. |
That already looks way better. I'll have a closer look in the next few days. |
@@ -246,23 +242,6 @@ def find_system_environments(): | |||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_get_version was deleted in the super class, so we can remove it here safely as well. However SameEnvironment shouldn't execute anything (It's mostly there for REPL completions).
I think we should probably be doing something like this:
class Environment(object):
def __init__(self, executable):
self.executable = executable
self._load_attributes()
def _load_attributes(self):
... # subprocess stuff
class SameEnvironment():
def __init__(self):
super(SameEnvironment, self).__init__(sys.executable)
def _load_attributes(self):
self.version_info = sys.version_info
self.path = sys.prefix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it can be simpler - pushed 2bb32e5.
|
@davidhalter
|
Oh, tests - I have not looked into fixing them yet. |
""" | ||
self.executable = os.path.abspath(executable) | ||
self.path = info[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidhalter
Should we keep path
here, or remove, or deprecate it instead of self.prefix
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep path for now. I think we should have a discussion about prefix in a separate PR or issue. I probably think we should deprecate it.
I see the problem. I would suggest to either revert PR #1152 or print |
@micbou The internal protocol is not really clear to me, i.e could the instance be made available in the callback? |
If it's too much of a hassle we can also just revert #1152. It's still possible to reintroduce it at a later stage. I think this PR is way more important. Generally if you want to make the pickle version 4 work in certain cases don't create too much complexity for it. It's really not worth it. IMO it's almost too much code for the effect it has at the moment. Please don't add way more code to pick a pickle version than it uses now. |
Except that the server also needs the version of the client. How are you going to pass that version from the client to the server? |
@micbou |
@blueyed So the plan is to send |
I have tried to implement restarting in case `g:deoplete#sources#jedi#python_path` gets changed, and figured that it is way easier when using only Jedi. There are likely previous features missing, and it needs cleaning up / deleting still. It uses the Jedi branch to improve handling of Environments: davidhalter/jedi#1108
Any idea about the |
I have tried to implement restarting in case `g:deoplete#sources#jedi#python_path` gets changed, and figured that it is way easier when using only Jedi. There are likely previous features missing, and it needs cleaning up / deleting still. It uses the Jedi branch to improve handling of Environments: davidhalter/jedi#1108
Are there plans to clean old environments already? Then maybe by default only the last X recently used should be kept running? (to be checked when a new environment is created) |
I have tried to implement restarting in case `g:deoplete#sources#jedi#python_path` gets changed, and figured that it is way easier when using only Jedi. There are likely previous features missing, and it needs cleaning up / deleting still. It uses the Jedi branch to improve handling of Environments: davidhalter/jedi#1108
No we currently don't do that. I would just wait until this one is merged (or just do it in another branch), so this doesn't get too big. |
I'm trying to pin down the remaining error. Have been searching for 2 hours, no luck so far. Will continue tomorrow while commuting. |
I fixed it in d06e55a it's on master, please rebase. |
You are probably finished, right? Everything else could go into a different PR? |
It only takes `executable` and gets all the information from the subprocess directly. Fixes davidhalter#1107.
Thanks! |
I have tried to implement restarting in case `g:deoplete#sources#jedi#python_path` gets changed, and figured that it is way easier when using only Jedi. There are likely previous features missing, and it needs cleaning up / deleting still. It uses the Jedi branch to improve handling of Environments: davidhalter/jedi#1108
I agree we should do that. I however have no idea why the tests still fail :-/ I cannot reproduce it locally anymore. I'll try to debug it on travis with debug mode. |
Ok. I can actually reproduce it, but only like this: |
It is caused by jedi/test/test_api/test_environment.py Lines 108 to 110 in 71f62c2
|
This fixes it: diff --git i/jedi/api/environment.py w/jedi/api/environment.py
index 06eb90ec..f6f47511 100644
--- i/jedi/api/environment.py
+++ w/jedi/api/environment.py
@@ -116,6 +116,12 @@ def get_sys_path(self):
# site.py gets executed.
return self._get_subprocess().get_sys_path()
+ def __del__(self):
+ try:
+ self._subprocess.kill()
+ except AttributeError:
+ pass
+
class SameEnvironment(Environment):
def __init__(self): The AttributeError might come from It makes sense in general I would say, but there is likely still an issue here that needs to be tracked down. |
The problem is that
I will push the |
This kills the subprocess when the Environment instance is about to be destroyed. This works around an internal test failure [1]. 1: davidhalter#1108 (comment)
Only a temporary failure on Travis: https://travis-ci.org/davidhalter/jedi/jobs/402926601 - cannot restart it myself. |
@@ -32,7 +32,8 @@ class InvalidPythonEnvironment(Exception): | |||
class _BaseEnvironment(object): | |||
@memoize_method | |||
def get_grammar(self): | |||
version_string = '%s.%s' % (self.version_info.major, self.version_info.minor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW: I didn't mention this previously (now I do), but I think it's ok to have a line length of 100 characters occasionally (PEP8 thinks so too), I think these two examples are more readable if they are longer, especially the second one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, please add it to the config then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To which config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setup.cfg
:
[flake8]
max-line-length = 100
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Now the tests fail because of appveyor. I have removed the Python 3.3 tests for now. Planning to drop it anyway. I will try to find a good solution for the |
Please comment on #1176. |
Ok, let's close this in favor of #1176. |
I have tried to implement restarting in case `g:deoplete#sources#jedi#python_path` gets changed, and figured that it is way easier when using only Jedi. There are likely previous features missing, and it needs cleaning up / deleting still. It uses the Jedi branch to improve handling of Environments: davidhalter/jedi#1108
Fixes #1107.
Used with jedi-vim: davidhalter/jedi-vim#836
Used with deoplete-jedi: deoplete-plugins/deoplete-jedi#184