Skip to content

Commit

Permalink
* reflect default Popen behavior by inheriting os.environ
Browse files Browse the repository at this point in the history
* without passing env_vars to create_environment, GeneralizedPopen behavior is same as before fix to issue #1540 (803c3cb)
* env_vars allows explicit environment variables, per PR #1619 (f9183bb)
  • Loading branch information
Ryan Clary committed Jul 17, 2020
1 parent 9957374 commit b0f664e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
6 changes: 3 additions & 3 deletions jedi/api/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Environment(_BaseEnvironment):
"""
_subprocess = None

def __init__(self, executable, env_vars={}):
def __init__(self, executable, env_vars=None):
self._start_executable = executable
self._env_vars = env_vars
# Initialize the environment
Expand Down Expand Up @@ -136,7 +136,7 @@ def __init__(self):
self._start_executable = self.executable = sys.executable
self.path = sys.prefix
self.version_info = _VersionInfo(*sys.version_info[:3])
self._env_vars = {}
self._env_vars = None


class SameEnvironment(_SameEnvironmentMixin, Environment):
Expand Down Expand Up @@ -379,7 +379,7 @@ def create_environment(path, safe=True, **kwargs):
return _create_environment(path, safe, **kwargs)


def _create_environment(path, safe=True, env_vars={}):
def _create_environment(path, safe=True, env_vars=None):
if os.path.isfile(path):
_assert_safe(path, safe)
return Environment(path, env_vars=env_vars)
Expand Down
13 changes: 2 additions & 11 deletions jedi/inference/compiled/subprocess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,12 @@ class CompiledSubprocess(object):
# Start with 2, gets set after _get_info.
_pickle_protocol = 2

def __init__(self, executable, env_vars={}):
def __init__(self, executable, env_vars=None):
self._executable = executable
self._env_vars = dict(env_vars)
self._env_vars = env_vars
self._inference_state_deletion_queue = queue.deque()
self._cleanup_callable = lambda: None

# Use explicit envionment to ensure reliable results (#1540)
if os.name == 'nt':
# if SYSTEMROOT (or case variant) exists in environment,
# ensure it goes to subprocess
for k, v in os.environ.items():
if 'SYSTEMROOT' == k.upper():
self._env_vars.update({k: os.environ[k]})
break # don't risk multiple entries

def __repr__(self):
pid = os.getpid()
return '<%s _executable=%r, _pickle_protocol=%r, is_crashed=%r, pid=%r>' % (
Expand Down

0 comments on commit b0f664e

Please sign in to comment.