def do_check(vext_files): """ Attempt to import everything in the 'test-imports' section of specified vext_files :param: list of vext filenames (without paths), '*' matches all. :return: True if test_imports was successful from all files """ from vext.gatekeeper import spec_dir, spec_files_flat, test_imports # not efficient ... but then there shouldn't be many of these all_specs = set(spec_files_flat()) if vext_files == ['*']: vext_files = all_specs unknown_specs = set(vext_files) - all_specs for fn in unknown_specs: print("%s is not an installed vext file." % fn, file=sys.stderr) if unknown_specs: return False check_passed = True for fn in [join(spec_dir(), fn) for fn in vext_files]: f = open_spec(open(fn)) modules = f.get('test_import', []) for success, module in test_imports(modules): if not success: check_passed = False line = "import %s: %s" % (module, '[success]' if success else '[failed]') print(line) print('') return check_passed
def check_sysdeps(vext_files): """ Check that imports in 'test_imports' succeed otherwise display message in 'install_hints' """ @run_in_syspy def run(*modules): result = {} for m in modules: if m: try: __import__(m) result[m] = True except ImportError: result[m] = False return result success = True for vext_file in vext_files: with open(vext_file) as f: vext = open_spec(f) install_hint = " ".join(vext.get('install_hints', ['System dependencies not found'])) modules = vext.get('test_import', '') logger.debug("%s test imports of: %s", vext_file, modules) result = run(*modules) if logging.getLogger().getEffectiveLevel() == logging.DEBUG: for k, v in result.items(): logger.debug("%s: %s", k, v) if not all(result.values()): success = False print(install_hint) return success
def load_specs(): bad_specs = set() last_error = None for fn in spec_files(): logger.debug("load spec: %s", fn) if fn in bad_specs: # Don't try and load the same bad spec twice continue try: spec = open_spec(open(fn)) for module in spec['modules']: logger.debug("allow module: %s", module) allowed_modules.add(module) for path_name in spec.get('extra_paths', []): extra_path = get_extra_path(path_name) if isdir(extra_path): os.environ['PATH'] += env_t(os.pathsep + extra_path) sys.path.append(extra_path) added_dirs.add(extra_path) else: logger.warn("Skipped adding nonexistant path: {0}".format( extra_path)) sys_sitedirs = getsyssitepackages() for sys_sitedir in sys_sitedirs: with fixup_paths(): for pth in [pth for pth in spec['pths'] or [] if pth]: try: logger.debug("open pth: %s", pth) pth_file = join(sys_sitedir, pth) addpackage(sys_sitedir, pth_file, added_dirs) init_path() # TODO except IOError as e: # Path files are optional.. logging.debug('No pth found at %s', pth_file) pass except Exception as e: bad_specs.add(fn) err_msg = 'error loading spec %s: %s' % (fn, e) if last_error != err_msg: logging.error(err_msg) last_error = err_msg if bad_specs: raise VextError('Error loading spec files: %s' % ', '.join(bad_specs))