Source documentation

Warning

Python API is far from being “frozen”, use it with zero backwards-compatibility in mind. You are welcome to report suggestions to bug tracker.

mrbobby – Main package

mrbobby.configurator – Machinery to figure out configuration

class mrbobby.configurator.Configurator(template, target_directory, bobbyconfig=None, variables=None, defaults=None)[source]

Bases: object

Controller that figures out settings, asks questions and renders the directory structure.

Parameters:
  • template – Template name
  • target_directory – Filesystem path to a output directory
  • bobbyconfig – Configuration for mr.bobby behaviour
  • variables – Given variables to questions
  • defaults – Overriden defaults of the questions

Additional to above settings, Configurator exposes following attributes:

  • template_dir is root directory of the template
  • is_tempdir if template directory is temporary (when using

zipfile) - templateconfig dictionary parsed from template section - questions ordered list of Question instances to be asked - bobbyconfig dictionary parsed from mrbobbyx section of the config

ask_questions()[source]

Loops through questions and asks for input if variable is not yet set.

render()[source]

Render file structure given instance configuration. Basically calls mrbobby.rendering.render_structure().

class mrbobby.configurator.Question(name, question, default=None, required=False, command_prompt=<built-in function raw_input>, pre_ask_question='', post_ask_question='', help='', **extra)[source]

Bases: object

Question configuration. Parameters are used to configure questioning and possible validation of the answer.

Parameters:
  • name – Unique, namespaced name of the question
  • question – Question to be asked
  • default – Default value of the question
  • required (bool) – Is question required?
  • command_prompt – Function to executed to ask the question given

question text :param help: Optional help message :param pre_ask_question: Space limited functions in dotted notation to ask before the question is asked :param post_ask_question: Space limited functions in dotted notation to ask aster the question is asked :param **extra: Any extra parameters stored for possible extending of Question functionality

Any of above parameters can be accessed as an attribute of Question instance.

ask(configurator)[source]

Eventually, ask the question.

Parameters:configuratormrbobby.configurator.Configurator

instance

mrbobby.configurator.parse_template(template_name)[source]

Resolve template name into absolute path to the template and boolean if absolute path is temporary directory.

mrbobby.cli – Command line interface

Command line interface to mr.bobby

mrbobby.cli.main(args=['-E', '-b', 'readthedocs', '-D', 'language=en', '.', '_build/html'])[source]

Main function called by mrbobby command.

mrbobby.bobbyexceptions – Exceptions

mr.bobby exceptions module.

exception mrbobby.bobbyexceptions.ConfigurationError[source]

Bases: mrbobby.bobbyexceptions.MrBobbyError

Raised during configuration phase

exception mrbobby.bobbyexceptions.MrBobbyError[source]

Bases: exceptions.Exception

Base class for errors

exception mrbobby.bobbyexceptions.SkipQuestion[source]

Bases: mrbobby.bobbyexceptions.MrBobbyError

Raised during pre_ask_question if we should skip it

exception mrbobby.bobbyexceptions.TemplateConfigurationError[source]

Bases: mrbobby.bobbyexceptions.ConfigurationError

Raised reading template configuration

exception mrbobby.bobbyexceptions.ValidationError[source]

Bases: mrbobby.bobbyexceptions.MrBobbyError

Raised during question validation

mrbobby.parsing – Parsing .ini files

mrbobby.rendering – Everything related to rendering templates and directory structure

mrbobby.rendering.render_filename(filename, variables)[source]

Overridable (via entry_points) rendering.

Now plugguable, see Writing your own plugin to modify your replacements or other variables substitutions.

This is a useful option to generate templates or conditionnal rendering.

mrbobby.rendering.render_structure(fs_source_root, fs_target_root, variables, verbose, renderer, ignored_files)[source]

Recursively copies the given filesystem path fs_source_root_ to a target directory fs_target_root.

Any files ending in .bobby are rendered as templates using the given renderer using the variables dictionary, thereby losing the .bobby suffix.

strings wrapped in + signs in file- or directory names will be replaced with values from the variables, i.e. a file named +name+.py.bobby given a dictionary {‘name’: ‘bar’} would be rendered as bar.py.

mrbobby.hooks – Included hooks

Use any of hooks below or write your own. You are welcome to contribute them !

mrbobby.hooks.show_message(configurator)[source]

If you want to display a message to the user when rendering is complete, you can use this function as Post render hook:

[template]
post_render = mrbobby.hooks:show_message
message = Well done, %(author.name)s, your code is ready!

As shown above, you can use standard Python formatting in post_render_msg.

mrbobby.hooks.to_boolean(configurator, question, answer)[source]

If you want to convert an answer to Python boolean, you can use this function as Post question hook:

[questions]
idiot.question = Are you young?
idiot.post_ask_question = mrbobby.hooks:to_boolean

Following variables can be converted to a boolean: y, n, yes, no, true, false, 1, 0

mrbobby.plugins – Included plugins

Plugins loader.

You can register your own plugins with entry_points.

Code a class in your egg and register it within your setup.py file

entry_points='''
# -*- Entry points: -*-
[mr.bobby.plugins]
render_filename=bobbyplugins.pkg.module:FooRenderFilename
''',

If there are multiples plugins with same name, you could push yours with different order attributes.

If you don’t specify an order target -r, –rdr-fname-plugin-target the plugin with max order attribute is prefered, otherwise alphabetic sort on namespace returns the last entry.

If you specify a bad plugin target an error is raised

AttributeError: No plugin target 15 ! Registered are [10, 20]

Note

Please notice that just mrbobby.rendering.render_filename is actually plugguable, but code infra is here.

mrbobby.plugins.load_plugin(plugin, entries=[], target=None)[source]

Load and sort possibles plugins from pkg.