这是indexloc提供的服务,不要输入任何密码
Skip to content

Fix infinite load attempts when direnv is not found on PATH #1

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions direnv.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@


ANSI_ESCAPE_RE = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')

DIRENV_CMD = 'direnv'

def get_output(cmd, cwd, env=None):
process = subprocess.Popen(
cmd,
cwd=cwd,
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
returncode = process.wait()
return (
returncode,
process.stdout.read().decode(),
ANSI_ESCAPE_RE.sub('', process.stderr.read().decode()),
)
try:
process = subprocess.Popen(
cmd,
cwd=cwd,
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
returncode = process.wait()
return (returncode,
process.stdout.read().decode(),
ANSI_ESCAPE_RE.sub('', process.stderr.read().decode()),)
except (OSError, subprocess.CalledProcessError) as e:
return (e.errno, '', str(e))


class Direnv(object):
Expand Down Expand Up @@ -67,15 +68,14 @@ def _update_environment(self, file_path):
env = {}
env.update(os.environ)
env.update({k: v for k, v in environment.items() if v is not None})
with progressbar(
sublime.status_message,
"direnv: loading " + direnv_path + " %s"):
with progressbar(sublime.status_message,
"direnv: loading " + direnv_path + " %s"):
returncode, stdout, stderr = get_output(
['direnv', 'export', 'json'],
[DIRENV_CMD, 'export', 'json'],
direnv_path,
env)
if returncode != 0:
sublime.status_message(stderr)
sublime.status_message("direnv load error: %s" % stderr)
self._current_direnv_path = None
return

Expand Down Expand Up @@ -114,7 +114,7 @@ def on_post_save(self):
class DirenvAllow(sublime_plugin.TextCommand):
def run(self, edit):
returncode, stdout, stderr = get_output(
['direnv', 'allow'],
[DIRENV_CMD, 'allow'],
os.path.dirname(self.view.file_name()))
if returncode != 0:
sublime.status_message(stderr)
Expand All @@ -125,7 +125,7 @@ def run(self, edit):
class DirenvDeny(sublime_plugin.TextCommand):
def run(self, edit):
returncode, stdout, stderr = get_output(
['direnv', 'deny'],
[DIRENV_CMD, 'deny'],
os.path.dirname(self.view.file_name()))
if returncode != 0:
sublime.status_message(stderr)
Expand Down