pyprec package

Subpackages

Submodules

pyprec.export module

This module

pyprec.export.create_folder_tree(prefix_folder: Path, source_folder: Path)[source]

Creates the source directory tree.

Directory tree is:

root
|-- source_folder # ``src/<pkgname>``
|       |-- scripts
|       |-- utils
Parameters
  • prefix_folder (Path) – The package root folder.

  • source_folder (Path) – The folder to create the package source files to.

Raises

FileExistsError – If the source directory already exists.

pyprec.export.create_package_light(setup: dict)[source]

Light wrapper function to copy template in package destination folder.

Parameters

setup (dict) – The key-value pairs to be inserted in the template fields.

pyprec.pyexporter module

class pyprec.pyexporter.PyExporter(input_path: Path)[source]

Bases: object

Class providing templating utilities.

Example

Loading a template from a .inc file:

>>> from pyprec.pyexporter import PyExporter
>>> exporter = PyExporter("foo.inc")
>>> exporter.fill(replace_dict)
>>> exporter.write("foo.py")
substitute(setup: dict)[source]

Fills the input template with dictionary key-value pair substitution.

Parameters

setup (dict) – The key-value pairs to be inserted in the template fields.

Raises

KeyError – If not all the fields in the template file are filled.

write(output_path: Path)[source]

Dumps template to file.

Parameters

output_path (Path) – The output file path.

pyprec.pyexporter.load_fill_and_export(template_path: Path, setup: dict, output_path: Path)[source]

Wrapper function that loads a template file, fills and writes it to file.

Parameters
  • template_path (Path) – The input template file path.

  • setup (dict) – The key-value pairs to be inserted in the template fields.

  • output_path (Path) – The output file path.

pyprec.ui module

This module implements the pyprec user interface.

pyprec.ui.ask_question_list(logger: Logger, questions: list[Tuple[str, str, Any]], timeout: float) dict[source]

Asks interactively to edit the runcard.

Receives the input from the user and opens an editor in the terminal as a subprocess. Default editor is nano, otherwise the QUAKE_EDITOR environment variable allows for custom choice.

Parameters
  • logger (logging.Logger) – The logger instance.

  • questions (list[Tuple[str, str, Any]) – List of tuples containing (key, question, default answer).

  • timeout (float) – Time limit to answer in seconds.

Returns

setup – The key-value pairs to be inserted in the template fields.

Return type

dict

pyprec.ui.get_question_list() list[Tuple[str, str, Any]][source]

Returns the list of questions to be asked to the user with default values.

Returns

questions – List of tuples containing (key, question, default answer).

Return type

list[Tuple[str, str, Any]]

pyprec.ui.load_setup_from_runcard(runcard_file: Path) dict[source]

Load runcard from yaml file.

Parameters

runcard_file (Path) – The yaml to load the dictionary from.

Returns

runcard – The loaded settings dictionary.

Return type

dict

pyprec.ui.refine_setup_dict(setup)[source]

Refine some dictionary keys to work with code.

Parameters

setup (dict) – The key-value pairs to be inserted in the template fields.

pyprec.ui.ui() dict[source]

PyPReC user interface implementation.

Returns

setup – The key-value pairs to be inserted in the template fields.

Return type

dict

Module contents

Package source root directory.