Skip to content
This repository has been archived by the owner on Jan 1, 2021. It is now read-only.

Commit

Permalink
Sort output of --print-runtime-available by priority
Browse files Browse the repository at this point in the history
  • Loading branch information
doloopwhile committed May 8, 2016
1 parent ce6c4d3 commit 074dad5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
1 change: 0 additions & 1 deletion execjs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
register = execjs._runtimes.register
get = execjs._runtimes.get
runtimes = execjs._runtimes.runtimes
available_runtimes = execjs._runtimes.available_runtimes
get_from_environment = execjs._runtimes.get_from_environment


Expand Down
7 changes: 2 additions & 5 deletions execjs/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ def __init__(self, option_strings, dest=SUPPRESS, default=SUPPRESS, help=None):
)

def __call__(self, parser, namespace, values, option_string=None):
buffer = io.StringIO()
for name, runtime in sorted(execjs.runtimes().items()):
if runtime.is_available():
buffer.write(name + "\n")
parser.exit(message=buffer.getvalue())
message = "".join(name + "\n" for name, runtime in execjs.runtimes().items() if runtime.is_available())
parser.exit(message=message)


def main():
Expand Down
8 changes: 2 additions & 6 deletions execjs/_runtimes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os.path
from collections import OrderedDict

import execjs.runtime_names as runtime_names
import execjs._external_runtime as external_runtime
Expand All @@ -23,12 +24,7 @@ def get(name=None):

def runtimes():
"""return a dictionary of all supported JavaScript runtimes."""
return dict(_runtimes)


def available_runtimes():
"""return a dictionary of all supported JavaScript runtimes which is usable"""
return dict((name, runtime) for name, runtime in _runtimes if runtime.is_available())
return OrderedDict(_runtimes)


def get_from_environment():
Expand Down
4 changes: 3 additions & 1 deletion test_execjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def setUp(self):
self.runtime = execjs


for name, runtime in execjs.available_runtimes().items():
for name, runtime in execjs.runtimes().items():
if not runtime.is_available():
continue
class_name = name.capitalize() + "RuntimeTest"

def f(runtime=runtime):
Expand Down

0 comments on commit 074dad5

Please sign in to comment.