repocribro.extending

Extension

class repocribro.extending.Extension(master, app, db)

Bases: object

Generic repocribro extension class

It serves as base extension which does nothing but has prepared all the attributes and methods needed. Particular real extensions can override those attributes and methods to make so behavior and extend repocribro. It also provides some useful methods to those subclasses.

Todo

Consider loading/asking order not by priority but by dependencies

ADMIN_URL = None

Administration URL within site (best via url_for)

AUTHOR = ''

Author(s) of extension

CATEGORY = ''

Category of extension (basic, security, data, ...)

GH_URL = None

GitHub url of extension project

HOME_URL = None

Homepage url of extension (rtd, pocoo, ...)

NAME = 'unknown'

Name of extension

PRIORITY = 1000

Priority (lower will be loaded/asked sooner)

__init__(master, app, db)

Inits the basic two parts of repocribro - flask app and DB

Parameters:
  • master (ExtensionsMaster) – Master for this extension
  • app (flask.Flask) – Flask application of repocribro
  • db (flask_sqlalchemy.SQLAlchemy) – SQLAlchemy database of repocribro
  • args – not used
  • kwargs – not used
call(hook_name, default, *args, **kwargs)

Call the operation via hook name

Parameters:
  • hook_name (str) – Name of hook to be called
  • default – Default return value if hook operation not found
  • args – Positional args to be passed to the hook operation
  • kwargs – Keywords args to be passed to the hook operation
Returns:

Result of the operation on the requested hook

init_blueprints()

Hook operation for initiating the blueprints and registering them within repocribro Flask app

init_filters()

Hook operation for initiating the Jinja filters and registering them within Jinja env of repocribro Flask app

init_models()

Hook operation for initiating the models and registering them within db

introduce()

Hook operation for getting short introduction of extension (mostly for debug/log purpose)

Returns:Name of the extension
Return type:str
static provide_blueprints()

Extension can provide Flask blueprints to the app by this method

Returns:List of Flask blueprints provided by extension
Return type:list of flask.blueprint
static provide_filters()

Extension can provide Jinja filters to the app by this method

Returns:Dictionary with name + function/filter pairs
Return type:dict of str: function
static provide_models()

Extension can provide (DB) models to the app by this method

Returns:List of models provided by extension
Return type:list of db.Model
register_blueprints_from_list(blueprints)

Registering Flask blueprints to the app

Parameters:blueprints (list of flask.blueprint) – List of Flask blueprints to be registered
register_filters_from_dict(filters)

Registering functions as Jinja filters

Parameters:filters (dict of str: function) – Dictionary where key is name of filter and value is the function serving as filter
view_admin_extensions()

Hook operation for getting view model of the extension in order to show it in the administration of app

Returns:Extensions view for this extension
Return type:repocribro.extending.helpers.ExtensionView

ExtensionsMaster

class repocribro.extending.ExtensionsMaster(*args, **kwargs)

Bases: object

Collector & master of Extensions

Extension master finds and holds all the repocribro extensions and is used for calling operations on them and collecting the results.

ENTRYPOINT_GROUP = 'repocribro.ext'

String used for looking up the extensions

LOAD_ERROR_MSG = 'Extension "{}" ({}) is not making an Extension (sub)class instance. It will be ignored!'

Error message mask for extension load error

__init__(*args, **kwargs)

Collects all the extensions to be mantained by this object

Parameters:
  • args – positional args to be passed to extensions
  • kwargs – keywords args to be passed to extensions

Todo

There might be some problem with ordering of extensions

classmethod _collect_extensions(name=None)

Method for selecting extensions within ENTRYPOINT_GROUP

Parameters:name (str) – Can be used to select single entrypoint/extension
Returns:Generator of selected entry points
Return type:pkg_resources.WorkingSet.iter_entry_points
call(hook_name, default=None, *args, **kwargs)

Call the hook on all extensions registered

Parameters:
  • hook_name (str) – Name of hook to be called
  • default – Default return value if hook operation not found
  • args – Positional args to be passed to the hook operation
  • kwargs – Keywords args to be passed to the hook operation
Returns:

Result of the operation on the requested hook

repocribro.extending.helpers.views

repocribro.extending.helpers.views.ViewTab

class repocribro.extending.helpers.views.ViewTab(id, name, priority=100, content='', octicon=None, badge=None)

Bases: object

Tab for the tabbed view at pages

__init__(id, name, priority=100, content='', octicon=None, badge=None)
__lt__(other)

repocribro.extending.helpers.views.Badge

class repocribro.extending.helpers.views.Badge(content)

Bases: object

Simple Twitter Bootstrap badge representation

__init__(content)

repocribro.extending.helpers.views.ExtensionView

class repocribro.extending.helpers.views.ExtensionView(name, category, author, admin_url=None, home_url=None, gh_url=None)

Bases: object

View object for extensions

__init__(name, category, author, admin_url=None, home_url=None, gh_url=None)
static from_class()

Make view from Extension class