Skip to content

Commit

Permalink
Make compiler.{get|require}_executable public
Browse files Browse the repository at this point in the history
Some internal functions in thrift.compiler are reusable in unit tests.
Explicitly expose them and use them.
  • Loading branch information
fmoo committed Sep 17, 2015
1 parent f52d73a commit 46804af
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
17 changes: 10 additions & 7 deletions sparts/thrift/compiler.py
Expand Up @@ -32,21 +32,24 @@ def compile(path, root='.', debug=False, **kwargs):
return comp.importThrift(path, **kwargs)


def _require_executable(name, fallback):
"""Given `name`, assert on and return the path to that binary."""
path = distutils.spawn.find_executable(name)
def get_executable():
"""Returns the thrift compiler path if found in the PATH, else None"""
path = distutils.spawn.find_executable('thrift1')
if path is None:
path = distutils.spawn.find_executable(fallback)
path = distutils.spawn.find_executable('thrift')
return path

assert path is not None, \
'Unable to find %s or %s in PATH' % (name, fallback)
def require_executable():
"""Assert that the thrift compiler is in the PATH. Returns the path"""
path = get_executable()
assert path is not None, 'Unable to find thrift compiler in PATH'
return path


class CompileContext(object):
def __init__(self, root='.', debug=False):
self.root = root
self.thrift_bin = _require_executable('thrift1', 'thrift')
self.thrift_bin = require_executable()
self.include_dirs = OrderedDict()
self.dep_files = {}
self.dep_contents = {}
Expand Down
4 changes: 1 addition & 3 deletions tests/tasks/thrift/test_multiplexed.py
Expand Up @@ -18,9 +18,7 @@
raise Skip("Need thrift language bindings to run this test")

# Make sure we have the thrift compiler
try:
compiler._require_executable('thrift1', 'thrift')
except AssertionError:
if compiler.get_executable() is None:
raise Skip("Need thrift compiler to run this test")

# String containing .thrift file contents for some example services
Expand Down
7 changes: 1 addition & 6 deletions tests/thrift/test_compiler.py
Expand Up @@ -7,14 +7,9 @@
from sparts.tests.base import BaseSpartsTestCase, Skip
from sparts.thrift import compiler

import distutils.spawn
import sys

# Only run thrift compiler test if the thrift compiler was found.
if distutils.spawn.find_executable('thrift') is None:
if compiler.get_executable() is None:
raise Skip("Unable to find thrift binary on this system")
if sys.version >= '3':
raise Skip("Thrift compiler is currently incompatible with py3k")


class ContextTests(BaseSpartsTestCase):
Expand Down

0 comments on commit 46804af

Please sign in to comment.