##// END OF EJS Templates
Improves detection of whether tab-completion is in a string and supresses Jedi....
Improves detection of whether tab-completion is in a string and supresses Jedi. Refs #10926 and #11530 Jedi results swamp file_matches and dict_key_matches in tab-completion, which is a real nuisance. The logic in the jedi completor tried to catch cases where it was "in a string", but that logic only looked at the previous character, and was a little fragile, breaking in lots of cases such as: './<tab> "mypath/<tab> etc. This seems a bit more robust in that it searchs for the first token in the current parser tree and checks if its value starts with ' or ". This detection of "in a string" then turns of jedi and returns some sanity to the set of matches.

File last commit:

r23701:bf225856
r25487:fb0abc20
Show More
tempdir.py
57 lines | 1.7 KiB | text/x-python | PythonLexer
Srinivas Reddy Thatiparthy
Add docstring
r23288 """ This module contains classes - NamedFileInTemporaryDirectory, TemporaryWorkingDirectory.
Srinivas Reddy Thatiparthy
remove unused imports
r23701 These classes add extra features such as creating a named file in temporary directory and
Srinivas Reddy Thatiparthy
Add docstring
r23288 creating a context manager for the working directory which is also temporary.
"""
Min RK
Revert "use testpath.tempdir for utils.tempdir"
r21102 import os as _os
Srinivas Reddy Thatiparthy
Remove TemporaryDirectory class...
r23287 from tempfile import TemporaryDirectory
Min RK
Revert "use testpath.tempdir for utils.tempdir"
r21102
Srinivas Reddy Thatiparthy
remove unused imports
r23701
Min RK
Revert "use testpath.tempdir for utils.tempdir"
r21102 class NamedFileInTemporaryDirectory(object):
def __init__(self, filename, mode='w+b', bufsize=-1, **kwds):
"""
Open a file named `filename` in a temporary directory.
This context manager is preferred over `NamedTemporaryFile` in
stdlib `tempfile` when one needs to reopen the file.
Arguments `mode` and `bufsize` are passed to `open`.
Rest of the arguments are passed to `TemporaryDirectory`.
"""
self._tmpdir = TemporaryDirectory(**kwds)
path = _os.path.join(self._tmpdir.name, filename)
self.file = open(path, mode, bufsize)
def cleanup(self):
self.file.close()
self._tmpdir.cleanup()
__del__ = cleanup
def __enter__(self):
return self.file
def __exit__(self, type, value, traceback):
self.cleanup()
class TemporaryWorkingDirectory(TemporaryDirectory):
"""
Creates a temporary directory and sets the cwd to that directory.
Automatically reverts to previous cwd upon cleanup.
Usage example:
with TemporaryWorkingDirectory() as tmpdir:
...
"""
def __enter__(self):
self.old_wd = _os.getcwd()
_os.chdir(self.name)
return super(TemporaryWorkingDirectory, self).__enter__()
def __exit__(self, exc, value, tb):
_os.chdir(self.old_wd)
return super(TemporaryWorkingDirectory, self).__exit__(exc, value, tb)