commit 4e496fe47aed4ce39a9f0d455c87104a2a8a3f89 Author: Damian Johnson atagar@torproject.org Date: Sat Oct 29 15:06:48 2016 -0700
Make module_exists() private
Lets not vend this helper to Stem users just yet. Also fixing pycodestyle regressions that were introduced as part of the prior changes. :P --- stem/util/test_tools.py | 45 +++++++++++++++++++++++---------------------- test/util.py | 16 ++-------------- 2 files changed, 25 insertions(+), 36 deletions(-)
diff --git a/stem/util/test_tools.py b/stem/util/test_tools.py index 450e18a..82c0d0b 100644 --- a/stem/util/test_tools.py +++ b/stem/util/test_tools.py @@ -86,18 +86,6 @@ def clean_orphaned_pyc(paths):
return orphaned_pyc
-def module_exists(module_name): - """ - Checks if a module exists - - :returns: **True** if module exists and **False** otherwise - """ - try: - mod = __import__(module_name) - except ImportError: - return False - else: - return True
def is_pyflakes_available(): """ @@ -106,12 +94,7 @@ def is_pyflakes_available(): :returns: **True** if we can use pyflakes and **False** otherwise """
- try: - import pyflakes.api - import pyflakes.reporter - return True - except ImportError: - return False + return _module_exists('pyflakes.api') and _module_exists('pyflakes.reporter')
def is_pycodestyle_available(): @@ -121,9 +104,9 @@ def is_pycodestyle_available(): :returns: **True** if we can use pycodestyle and **False** otherwise """
- if module_exists('pycodestyle'): + if _module_exists('pycodestyle'): import pycodestyle - elif module_exists('pep8'): + elif _module_exists('pep8'): import pep8 as pycodestyle else: return False @@ -133,6 +116,7 @@ def is_pycodestyle_available(): else: return True
+ def stylistic_issues(paths, check_newlines = False, check_exception_keyword = False, prefer_single_quotes = False): """ Checks for stylistic issues that are an issue according to the parts of @@ -213,9 +197,9 @@ def stylistic_issues(paths, check_newlines = False, check_exception_keyword = Fa return False
if is_pycodestyle_available(): - if module_exists('pycodestyle'): + if _module_exists('pycodestyle'): import pycodestyle - elif module_exists('pep8'): + elif _module_exists('pep8'): import pep8 as pycodestyle
class StyleReport(pycodestyle.BaseReport): @@ -351,6 +335,23 @@ def pyflakes_issues(paths): return issues
+def _module_exists(module_name): + """ + Checks if a module exists. + + :param str module_name: module to check existance of + + :returns: **True** if module exists and **False** otherwise + """ + + try: + __import__(module_name) + except ImportError: + return False + else: + return True + + def _python_files(paths): for path in paths: for file_path in stem.util.system.files_with_suffix(path, '.py'): diff --git a/test/util.py b/test/util.py index 6812898..1cb59eb 100644 --- a/test/util.py +++ b/test/util.py @@ -84,18 +84,6 @@ STEM_BASE = os.path.sep.join(__file__.split(os.path.sep)[:-2])
NEW_CAPABILITIES = []
-def module_exists(module_name): - """ - Checks if a module exists - - :returns: **True** if module exists and **False** otherwise - """ - try: - mod = __import__(module_name) - except ImportError: - return False - else: - return True
def get_unit_tests(module_prefix = None): """ @@ -239,9 +227,9 @@ def check_pyflakes_version():
def check_pycodestyle_version(): - if module_exists('pycodestyle'): + if stem.util.test_tools._module_exists('pycodestyle'): import pycodestyle - elif module_exists('pep8'): + elif stem.util.test_tools._module_exists('pep8'): import pep8 as pycodestyle else: return 'missing'