def test_get_pairwise_compatibility(self): pkg_list = ['pkg1', 'pkg2', 'pkg3'] python_version = 3 mock_config = mock.Mock() mock_config.PKG_LIST = pkg_list patch_config = mock.patch( 'compatibility_lib.compatibility_checker.configs', mock_config) patch_executor = mock.patch( 'compatibility_lib.compatibility_checker.concurrent.futures.ThreadPoolExecutor', FakeExecutor) patch_retrying_check = mock.patch.object( compatibility_checker.CompatibilityChecker, 'retrying_check', self._mock_retrying_check) res = [] with patch_config, patch_executor, patch_retrying_check: checker = compatibility_checker.CompatibilityChecker() result = checker.get_pairwise_compatibility(python_version) for item in result: res.append(item) self.assertEqual(res, [((['pkg1', 'pkg2'], 3, 'SUCCESS'), ), ((['pkg1', 'pkg3'], 3, 'SUCCESS'), ), ((['pkg2', 'pkg3'], 3, 'SUCCESS'), )])
def test_check(self): checker = compatibility_checker.CompatibilityChecker() packages = ['opencensus'] python_version = 3 expected_server_url = 'http://34.68.40.69/' data = { 'python-version': python_version, 'package': packages, } mock_requests = mock.Mock() mock_response = mock.Mock(content=b'{}') mock_requests.get.return_value = mock_response patch_request = mock.patch( 'compatibility_lib.compatibility_checker.requests', mock_requests) with patch_request: checker.check(packages, python_version) mock_requests.get.assert_called_with( compatibility_checker.SERVER_URL, params=data, timeout=299) self.assertEqual(compatibility_checker.SERVER_URL, expected_server_url)
def test_check(self): import json checker = compatibility_checker.CompatibilityChecker() packages = 'test_pkg' python_version = 3 data = {'python-version': python_version, 'packages': packages} request = mock.Mock() mock_request = mock.Mock() mock_request.Request.return_value = request urlopen_res = mock.Mock() mock_request.urlopen.return_value = urlopen_res json_mock = mock.Mock() json_mock.read.return_value = b'{}' urlopen_res.__enter__ = mock.Mock(return_value=json_mock) urlopen_res.__exit__ = mock.Mock(return_value=None) patch_request = mock.patch( 'compatibility_lib.compatibility_checker.urllib.request', mock_request) with patch_request: checker.check(packages, python_version) mock_request.Request.assert_called_with( compatibility_checker.SERVER_URL, json.dumps(data).encode('utf-8')) mock_request.urlopen.assert_called_with(request)
def main(): parser = argparse.ArgumentParser( description='Display a grid show the dependency compatibility ' + 'between Python packages') parser.add_argument('--packages', nargs='+', default=_DEFAULT_INSTALL_NAMES, help='the packages to display compatibility ' + 'information for') parser.add_argument('--browser', action='store_true', default=False, help='display the grid in a browser tab') args = parser.parse_args() checker = compatibility_checker.CompatibilityChecker() store = compatibility_store.CompatibilityStore() packages = [ package.Package(install_name) for install_name in args.packages ] logging.info("Getting self compatibility results...") package_to_results = store.get_self_compatibilities(packages) logging.info("Getting pairwise compatibility results...") pairwise_to_results = store.get_compatibility_combinations(packages) package_with_dependency_info = {} for pkg in configs.PKG_LIST: dep_info = store.get_dependency_info(pkg) package_with_dependency_info[pkg] = dep_info results = _ResultHolder(package_to_results, pairwise_to_results, package_with_dependency_info, checker, store) dashboard_builder = DashboardBuilder(packages, results) # Build the pairwise grid dashboard logging.info('Starting build the grid...') grid_html = dashboard_builder.build_dashboard( 'dashboard/grid-template.html') grid_path = os.path.dirname(os.path.abspath(__file__)) + '/grid.html' with open(grid_path, 'wt') as f: f.write(grid_html) # Build the dashboard main page logging.info('Starting build the main dashboard...') main_html = dashboard_builder.build_dashboard( 'dashboard/main-template.html') main_path = os.path.dirname(os.path.abspath(__file__)) + '/index.html' with open(main_path, 'wt') as f: f.write(main_html) if args.browser: webbrowser.open_new_tab('file://' + main_path)
def __init__(self, py_version=None, checker=None, store=None): if py_version is None: py_version = '3' if checker is None: checker = compatibility_checker.CompatibilityChecker() self.py_version = py_version self.checker = checker self.store = store
def __init__(self, py_version=None, checker=None, store=None): if py_version is None: py_version = '3' if checker is None: checker = compatibility_checker.CompatibilityChecker() self.py_version = py_version self._checker = checker self._store = store self._dependency_info_getter = utils.DependencyInfo( py_version, self._checker, self._store)
def test_get_compatibility(self): checker = compatibility_checker.CompatibilityChecker() pkg_list = ['pkg1', 'pkg2', 'pkg3'] pkg_py_version_not_supported = { 2: ['tensorflow', ], 3: ['apache-beam[gcp]', 'gsutil', ], } mock_config = mock.Mock() mock_config.PKG_LIST = pkg_list mock_config.PKG_PY_VERSION_NOT_SUPPORTED = pkg_py_version_not_supported patch_config = mock.patch( 'compatibility_lib.compatibility_checker.configs', mock_config) patch_executor = mock.patch( 'compatibility_lib.compatibility_checker.concurrent.futures.ThreadPoolExecutor', FakeExecutor) patch_retrying_check = mock.patch.object( compatibility_checker.CompatibilityChecker, 'retrying_check', self._mock_retrying_check) res = [] with patch_config, patch_executor, patch_retrying_check: result = checker.get_compatibility() for item in result: res.append(item) expected = sorted([ ((['pkg1'], '2', 'SUCCESS'),), ((['pkg2'], '2', 'SUCCESS'),), ((['pkg3'], '2', 'SUCCESS'),), ((['pkg1'], '3', 'SUCCESS'),), ((['pkg2'], '3', 'SUCCESS'),), ((['pkg3'], '3', 'SUCCESS'),), ((['pkg1', 'pkg2'], '2', 'SUCCESS'),), ((['pkg1', 'pkg3'], '2', 'SUCCESS'),), ((['pkg2', 'pkg3'], '2', 'SUCCESS'),), ((['pkg1', 'pkg2'], '3', 'SUCCESS'),), ((['pkg1', 'pkg3'], '3', 'SUCCESS'),), ((['pkg2', 'pkg3'], '3', 'SUCCESS'),)]) self.assertEqual(sorted(res), expected)
def __init__(self, py_version=None, checker=None, store=None, max_workers=50): if py_version is None: py_version = '3' if checker is None: checker = compatibility_checker.CompatibilityChecker() self.max_workers = max_workers self.py_version = py_version self._checker = checker self._store = store self._dependency_info_getter = utils.DependencyInfo( py_version, self._checker, self._store) # Share a common pool for PyPI requests to avoid creating too many # threads. self._pypi_thread_pool = concurrent.futures.ThreadPoolExecutor( max_workers=self.max_workers)
def test_check(self): import json checker = compatibility_checker.CompatibilityChecker() packages = 'test_pkg' python_version = 3 data = {'python-version': python_version, 'package': packages} mock_requests = mock.Mock() mock_response = mock.Mock(content=b'{}') mock_requests.get.return_value = mock_response patch_request = mock.patch( 'compatibility_lib.compatibility_checker.requests', mock_requests) with patch_request: checker.check(packages, python_version) mock_requests.get.assert_called_with(compatibility_checker.SERVER_URL, params=data)
def main(): parser = argparse.ArgumentParser( description='Display a grid show the dependency compatibility ' + 'between Python packages') parser.add_argument('--packages', nargs='+', default=_DEFAULT_INSTALL_NAMES, help='the packages to display compatibility ' + 'information for') parser.add_argument('--browser', action='store_true', default=False, help='display the grid in a browser tab') args = parser.parse_args() checker = compatibility_checker.CompatibilityChecker() store = compatibility_store.CompatibilityStore() instance_flag = '-instances={}=tcp:{}'.format(INSTANCE_CONNECTION_NAME, PORT) cloud_sql_proxy_path = './cloud_sql_proxy' try: # Run cloud_sql_proxy process = popen_spawn.PopenSpawn([cloud_sql_proxy_path, instance_flag]) process.expect('Ready for new connection', timeout=5) packages = [ package.Package(install_name) for install_name in args.packages ] logging.info('Getting self compatibility results...') package_to_results = store.get_self_compatibilities(packages) logging.info('Getting pairwise compatibility results...') pairwise_to_results = store.get_compatibility_combinations(packages) package_with_dependency_info = {} for pkg in configs.PKG_LIST: dep_info = store.get_dependency_info(pkg) package_with_dependency_info[pkg] = dep_info results = _ResultHolder(package_to_results, pairwise_to_results, package_with_dependency_info, checker, store) dashboard_builder = DashboardBuilder(packages, results) # Build the pairwise grid dashboard logging.info('Starting build the grid...') grid_html = dashboard_builder.build_dashboard( 'dashboard/grid-template.html') grid_path = os.path.dirname(os.path.abspath(__file__)) + '/grid.html' with open(grid_path, 'wt') as f: f.write(grid_html) # Build the dashboard main page logging.info('Starting build the main dashboard...') main_html = dashboard_builder.build_dashboard( 'dashboard/main-template.html') main_path = os.path.dirname(os.path.abspath(__file__)) + '/index.html' with open(main_path, 'wt') as f: f.write(main_html) except Exception: raise DashboardBuilderError('Error occurs when building dashboard.' 'Output: {}'.format(process.before)) finally: process.kill(signal.SIGTERM) if args.browser: webbrowser.open_new_tab('file://' + main_path)
import argparse import contextlib import datetime import itertools import signal import pexpect from pexpect import popen_spawn from compatibility_lib import compatibility_checker from compatibility_lib import compatibility_store from compatibility_lib import configs from compatibility_lib import package checker = compatibility_checker.CompatibilityChecker(max_workers=800) store = compatibility_store.CompatibilityStore() PY2 = '2' PY3 = '3' INSTANCE_CONNECTION_NAME = 'python-compatibility-tools:us-central1:' \ 'compatibility-data' PORT = '3306' class ConnectionError(Exception): pass
from typing import Optional import pybadges from compatibility_lib import compatibility_checker from compatibility_lib import compatibility_store from compatibility_lib import configs from compatibility_lib import dependency_highlighter from compatibility_lib import deprecated_dep_finder # Initializations DB_CONNECTION_NAME = 'python-compatibility-tools:us-central1:' \ 'compatibility-data' UNIX_SOCKET = '/cloudsql/{}'.format(DB_CONNECTION_NAME) checker = compatibility_checker.CompatibilityChecker() store = compatibility_store.CompatibilityStore(mysql_unix_socket=UNIX_SOCKET) highlighter = dependency_highlighter.DependencyHighlighter( checker=checker, store=store) finder = deprecated_dep_finder.DeprecatedDepFinder( checker=checker, store=store) priority_level = dependency_highlighter.PriorityLevel TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%S" URL_PREFIX = 'https://img.shields.io/badge/' GITHUB_HEAD_NAME = 'github head' GITHUB_API = 'https://api.github.com/repos' GITHUB_CACHE_TIME = 1800 # seconds SVG_CONTENT_TYPE = 'image/svg+xml' EMPTY_DETAILS = 'NO DETAILS'
def __init__(self, py_version='3'): self.py_version = py_version self._store = compatibility_store.CompatibilityStore() self._checker = compatibility_checker.CompatibilityChecker()