def get_environment(use_cache=True): global current_environment vim_force_python_version = vim_eval("g:jedi#force_py_version") if use_cache and vim_force_python_version == current_environment[0]: return current_environment[1] environment = None if vim_force_python_version == "auto": environment = jedi.api.environment.get_cached_default_environment() else: force_python_version = vim_force_python_version if '0000' in force_python_version or '9999' in force_python_version: # It's probably a float that wasn't shortened. try: force_python_version = "{:.1f}".format(float(force_python_version)) except ValueError: pass elif isinstance(force_python_version, float): force_python_version = "{:.1f}".format(force_python_version) try: environment = jedi.get_system_environment(force_python_version) except jedi.InvalidPythonEnvironment as exc: environment = jedi.api.environment.get_cached_default_environment() echo_highlight( "force_python_version=%s is not supported: %s - using %s." % ( vim_force_python_version, str(exc), str(environment))) current_environment = (vim_force_python_version, environment) return environment
def venv_path(tmpdir_factory, environment): if environment.version_info.major < 3: pytest.skip("python -m venv does not exist in Python 2") elif isinstance(environment, InterpreterEnvironment): # The environment can be a tox virtualenv environment which we don't # want, so use the system environment. environment = get_system_environment('.'.join( str(x) for x in environment.version_info[:2])) tmpdir = tmpdir_factory.mktemp('venv_path') dirname = os.path.join(tmpdir.strpath, 'venv') # We cannot use the Python from tox because tox creates virtualenvs and # they have different site.py files that work differently than the default # ones. Instead, we find the real Python executable by printing the value # of sys.base_prefix or sys.real_prefix if we are in a virtualenv. output = subprocess.check_output([ environment.executable, "-c", "import sys; " "print(sys.real_prefix if hasattr(sys, 'real_prefix') else sys.base_prefix)" ]) prefix = output.rstrip().decode('utf8') if os.name == 'nt': executable_path = os.path.join(prefix, 'python') else: executable_name = os.path.basename(environment.executable) executable_path = os.path.join(prefix, 'bin', executable_name) return_code = subprocess.call([executable_path, '-m', 'venv', dirname]) assert return_code == 0, return_code return dirname
def get_environment(use_cache=True): global current_environment vim_force_python_version = vim_eval("g:jedi#force_py_version") if use_cache and vim_force_python_version == current_environment[0]: return current_environment[1] environment = None if vim_force_python_version == "auto": environment = jedi.api.environment.get_cached_default_environment() else: force_python_version = vim_force_python_version if '0000' in force_python_version or '9999' in force_python_version: # It's probably a float that wasn't shortened. try: force_python_version = "{:.1f}".format(float(force_python_version)) except ValueError: pass elif isinstance(force_python_version, float): force_python_version = "{:.1f}".format(force_python_version) try: environment = jedi.get_system_environment(force_python_version) except jedi.InvalidPythonEnvironment as exc: environment = jedi.api.environment.get_cached_default_environment() echo_highlight( "force_python_version=%s is not supported: %s - using %s." % ( vim_force_python_version, str(exc), str(environment))) current_environment = (vim_force_python_version, environment) return environment
def _get_environment(self, force_to_use): if force_to_use == 'auto': return self._get_auto_env() force_python_version = force_to_use if self._using_jedi_env['force_version'] is not None \ and self._using_jedi_env['force'] == force_to_use: # cached return self._using_jedi_env['force_version'] # reflesh self._using_jedi_env['force'] = force_to_use if '0000' in force_python_version or '9999' in force_python_version: # It's probably a float that wasn't shortened. try: force_python_version = "{:.1f}".format( float(force_python_version)) except ValueError: pass elif isinstance(force_python_version, float): force_python_version = "{:.1f}".format(force_python_version) try: environment = jedi.get_system_environment(force_python_version) self._using_jedi_env['force_version'] = environment except jedi.InvalidPythonEnvironment: self._using_jedi_env['force_version'] = None return self._get_auto_env()
def get_environment(use_cache=True): if use_cache: return jedi.api.environment.get_cached_default_environment() else: try: return jedi.get_system_environment() except jedi.InvalidPythonEnvironment as exc: traceback.format_exc(exc) raise