def app_bootstrap(settings: Settings) -> ServiceRegistry: # Make the registry registry = ServiceRegistry() # Store the settings in the registry so things later can # get to them. registry.register_singleton(settings, Settings) # Scan for registrations scanner = venusian.Scanner(registry=registry, settings=settings) from . import models scanner.scan(models) # Grab the datastore singleton to pass into setup container: ServiceContainer = registry.create_container() datastore: Datastore = container.get(Datastore) # Do setup for the core application features setup(registry, datastore) # Import the add-on and initialize it from . import custom scanner.scan(custom) custom.setup(registry, datastore) return registry
def parse_options(cls, options): # We implement our own line-length checker because it's not possible to # customize how another checker does its checking. options.ignore += 'E501', cls.options = options # This vastly speeds up the test suite, since parse_options is called # on every test now, and venusian does a lot of work. if cls.collected_checkers is not None: return collected_checkers = [] _, grammar, _ = current_python_grammar() def register_checker(pattern, checker, extra): if ('python_minimum_version' in extra and sys.version_info < extra['python_minimum_version']): return if ('python_disabled_version' in extra and sys.version_info > extra['python_disabled_version']): return pattern, tree = patcomp.compile_pattern(grammar, pattern, with_tree=True) collected_checkers.append((pattern, tree, checker, extra)) scanner = venusian.Scanner(register=register_checker) scanner.scan(checkers) matcher = BottomMatcher(grammar) for e, (_, tree, _, _) in enumerate(collected_checkers): matcher.add_pattern_by_key(tree, e) cls.collected_checkers = collected_checkers cls.matcher = matcher
def __init__(self, loader=None, registry=None, swagger_config=None, flavor=None, debug=False, debug_config=False): self._directives = {} self.flavor = flavor self.resolver = DottedNameResolver() self.asset_resolver = AssetResolver() self.action_state = ActionState() self.scanner = venusian.Scanner(config=self) self.packages = set() self.debug = debug self.debug_config = debug_config self.swagger_config = swagger_config # set registry if registry is None: registry = Registry(flavor=flavor) self.registry = registry # loader loader = self.maybe_dotted(loader) if callable(loader): loader = loader() self.loader = loader if self.loader: self.loader.configure(self, swagger_config)
def __init__(self, celery_app): self.celery_app = celery_app self.error_handling_strateies = {} self.mappers = {} self.reducers = {} self.scanner = venusian.Scanner(registry=defaultdict(dict), celery_app=celery_app)
def parse_options(cls, options): # We implement our own line-length checker because it's not possible to # customize how another checker does its checking. options.ignore += 'E501', cls.options = options # This vastly speeds up the test suite, since parse_options is called # on every test now, and venusian does a lot of work. if cls.collected_checkers is not None: return collected_checkers = [] def register_checker(pattern, checker, extra): if ('python_minimum_version' in extra and sys.version_info < extra['python_minimum_version']): return if ('python_disabled_version' in extra and sys.version_info > extra['python_disabled_version']): return pattern = patcomp.compile_pattern(pattern) collected_checkers.append((pattern, checker, extra)) scanner = venusian.Scanner(register=register_checker) scanner.scan(checkers) cls.collected_checkers = collected_checkers
def main(_, **settings): """ This function returns a Pyramid WSGI application. """ config = Configurator(settings=settings) config.add_route('alerter', '/{config}') config.scan(views) venusian.Scanner().scan(alerters, categories=['alerters']) return config.make_wsgi_app()
def scan_custers(): task_registry = registry.Components() project_custer = get_project_custer() scanner = venusian.Scanner(registry=task_registry) for plugin in get_plugins(): scanner.scan(plugin) scanner.scan(project_custer) return task_registry
def _collect_custom_views(package, view_registry): """ Collect all the custom views marked with the register_custom_view decorator and add them to the view_registry :param package: package to look for decorated views into :param view_registry: dictionary containing the path-view function pairs """ scanner = venusian.Scanner(view_registry=view_registry) scanner.scan(package, categories=('pyramid_mock_server', ))
def scan(self): for name in self.pending: if name in self.seen: continue module = import_module(name) scanner = venusian.Scanner(testfixtures=self) scanner.scan(module, categories=('testfixture', )) self.seen.add(name) self.pending = []
def __init__(self, pretty_print=True): current_module = sys.modules[__name__] scanner = venusian.Scanner(adapters=[]) scanner.scan(current_module, categories=(JSONIFY_CATEGORY, )) kwargs = dict(adapters=scanner.adapters) if pretty_print: kwargs.update( dict(sort_keys=True, indent=4, separators=(',', ': ')), ) super().__init__(**kwargs)
def scan(self, package, ignore=None): """Scan packages for finding consumers """ scanner = venusian.Scanner(add_consumer=self.add_consumer) scanner.scan( package, categories=('balog.consumers', ), ignore=ignore, )
def http_serve(port=8348): ioloop = tornado.ioloop.IOLoop.instance() scanner = venusian.Scanner() scanner.scan(duckheader.handlers, ignore=None) app.finish_route() http_server = tornado.httpserver.HTTPServer(app) http_server.listen(port) ioloop.start()
def read_package(self, package, require=None): if package in self._scanned_list: return # TODO (br) Make 'entrypoints' global scanner = venusian.Scanner(entrypoints=[], modifiers=[]) scanner.scan(package, categories=["plugnparse"], onerror=self.scan_error_handler) self._add_entrypoints(scanner.entrypoints) self._add_modifiers(scanner.modifiers) self._scanned_list.append(package)
def scan_models(module): """ Scan a models module to force Model registration. Argument `module` can be a models module or a Python dotted string. """ resolver = DottedNameResolver() module = resolver.maybe_resolve(module) scanner = venusian.Scanner() scanner.scan(module)
def scan(cls, package): """Scan a package for tags. :param str package: the name of the package to scan. :return: a new :class:`Tagger` containing all the tags that were found. """ scanner = venusian.Scanner(taggers=[]) scanner.scan(__import__(package), categories=["serverstf.taggers"]) return cls(*scanner.taggers) # pylint: disable=no-member
def make_app(): resources = [] venusian.Scanner(routes=resources).scan(api) settings = dict( template_path=os.path.join(os.path.dirname(__file__), "templates"), static_path=os.path.join(os.path.dirname(__file__), "static"), xsrf_cookies=True, cookie_secret="SOME_SECRET_KEY", debug=True, ) return Application(resources, **settings)
def discover_subcommands(parser, scope=None): """Discover registered subcommands. The side-effect of running this function is that it adds the subcommands to the given parser. If given, `scope` can be used to scope the discovery to a specifc module or package. """ if scope is None: from .. import cli as scope sub_parsers = parser.add_subparsers() scanner = venusian.Scanner(sub_parsers=sub_parsers) scanner.scan(scope, categories=(SUBCOMMAND_CATEGORY, ))
def main(global_config, **settings): import dev_common config = Configurator(settings=settings) config.include('dev_app') config.include('dev_common') config.add_route('hello', '/') scanner = venusian.Scanner(settings=settings) scanner.scan(dev_common) return config.make_wsgi_app()
def run(): app = web.Application(middlewares=[ submissions_middleware, response_middleware, error_middleware ]) app.on_startup.append(on_startup) app.on_cleanup.append(on_cleanup) scanner = venusian.Scanner(router=app.router) scanner.scan(playlog.web) if config.DEBUG: import aioreloader aioreloader.start() web.run_app(app, host=config.SERVER_HOST, port=config.SERVER_PORT)
def main(self): # entry point of the script self.loop = asyncio.get_event_loop() if self.config["to_scan"] == True: # get App calling module path to let venusian scanner know where to check for decoraters and functions frm = inspect.stack()[1] mod = inspect.getmodule(frm[0]) scanner = venusian.Scanner(registry=self.registry) scanner.scan(mod) self.loop.create_task(self.__initiate_tasks()) self.loop.run_forever() self.loop.close()
def collect(self): """Collect all registered. Returns a dictionary mapping names to registered elements. """ registry = {} def ignore_import_error(_unused): if not issubclass(sys.exc_info()[0], ImportError): raise # pragma: no cover scanner = venusian.Scanner(registry=registry, tag=self) for module in _get_modules(): scanner.scan(module, onerror=ignore_import_error) return registry
def __init__(self, packages=None, extra_categories=None): """ If ``packages``, run a `venusian scan`_. .. _`venusian scan`: http://docs.repoze.org/venusian/ """ self.__required_settings__ = {} self._items = {} if packages: categories = [_CATEGORY] if extra_categories is not None: categories.extend(extra_categories) scanner = venusian.Scanner(settings=self) for item in packages: scanner.scan(item, categories=categories)
def app_factory(global_config, **config): logger.setLevel(config.get("log_level", "INFO")) logger.debug("Start app building") config_ = global_config config_.update(config) app = init_app(config_) app.on_startup.append(init_db) app.on_cleanup.append(close_db) venusian.Scanner().scan(api) app.add_routes(routes) return app
def scan(package): """Scan a package for subcommands. :param package: a module or package to scan for subcommands. :raise CLIError: if a subcommand name was used multiple times or there was an attempt to add arguments to a non-subcommand function. :return: a dictionary mapping subcommand names to :class:`Subcommand`s. """ scanner = venusian.Scanner() scanner.scan( package, categories=[ __package__ + ":subcommand", # first so that _SUBCOMMANDS is set __package__ + ":arguments", ]) return scanner.subcommands # pylint: disable=no-member
def __init__(self, decision_function, decision_object=None): self._decision_object = decision_object self._decision_function = decision_function registry = Registry() self._scanner = venusian.Scanner(registry=registry, mode='local', caller='decision_worker') self._scanner.parent_decision_worker = decision_function # Some trickery here -- scan the module that the activity worker method is found in self._scanner.scan(sys.modules[decision_function.orig.__module__], categories=('pyswfaws.activity_task', 'pyswfaws.decision_task')) # More trickery -- make sure that timers know that we're in a remote mode PTimer.is_remote_mode = False PMarker.is_remote_mode = False
def scan(*modules): scanner = venusian.Scanner() for mod in modules: log.info('Scanning {}'.format(mod)) scanner.scan(importlib.import_module(mod)) for dbname, db in meta.list_all_tables().items(): for table in db: # Populate column descriptors columns = [getattr(table, attr).name for attr in dir(table) if isinstance(getattr(table, attr), (Column, ForeignKey))] table.__meta__['columns'] = sorted(columns) fields = {getattr(table, attr).name: attr for attr in dir(table) if isinstance(getattr(table, attr), (Column, ForeignKey))} table.__meta__['attributes'] = fields
def venusianscan(file_or_module, context, testing=False, force=False): """Process a venusian scan""" # Set default i18n_domain if getattr(context, 'package', None): context.i18n_domain = context.package.__name__ if isinstance(file_or_module, types.ModuleType): # Use the given module directly module = file_or_module else: # Import the given file as a module of context.package: name = os.path.splitext(os.path.basename(file_or_module.name))[0] module = importlib.import_module('{0:s}.{1:s}'.format( context.package.__name__, name)) # Initialize scanner scanner = venusian.Scanner(context=context, testing=testing) # Scan the package _scan(scanner, module, force=force)
def collect(self): """ Collect all registered functions or classes. Returns a dictionary mapping names to registered elements. """ def ignore_import_error(_unused): """ Ignore ImportError during collection. Some modules raise import errors for various reasons, and should be just treated as missing. """ if not issubclass(sys.exc_info()[0], ImportError): raise # pragma: no cover registry = collections.defaultdict(set) scanner = venusian.Scanner(registry=registry, tag=self) for module in _get_modules(): # Venusian is using a newly-deprecated method to scan modules with _ignore_deprecation(): scanner.scan(module, onerror=ignore_import_error) return registry
def _scan_subcommands(self): subcommands = {} scanner = venusian.Scanner(subcommands=subcommands) scanner.scan(scripts, categories=('subcommands', )) return subcommands
def scan(self, module=pyborg.commands): self.scanner = venusian.Scanner(registry=self.registry) self.scanner.scan(module)