snowmobile.core.markup

Calling script.doc() returns a Markup containing a Section for each statement or marker within the script.

Note

A Markup instance, m, returned by script.doc(), makes no modifications to the sql file read by script

Instead, m will generate and export the following two files:

  • A sql file stripped of all untagged comments, limited to statements within the context of script at the time m was created

  • A markdown representation of the code and markup associated with the same set of statements

By default, these files are exported to a .snowmobile directory alongside the sql file that was read by the script; the directory name to use for generated exports can be configured in [script.export-dir-name]

If the target directory does not yet exist, it will be created as part of the export process invoked by m.save()

The default markdown configuration yields a .md file with the below structure:

# Script Name.sql         [script name gets an 'h1' header]

- **Key1**: *Value1*      [keys are bolded, values are italicized]
- **Key2**: *Value2*      [same for all tags/attributes found]
- ...

**Description**           [except for the 'Description' section]
                          [this is just a blank canvas of markdown..]
                          [..but this is configurable]

## (1) create-table~dummy_name [contents get 'h2' level headers]

- **Key1**: *Value1*      [identical formatting for st/markers]

**Description**           [statement descriptions get one of these too]

**SQL**                   [as does their rendered sql]
    ...sql
        ...
        ...
    ...


## (2) update-table~dummy_name2

...                       [structure repeats for all contents in the script]

Module Contents

Classes

Markup

Contains all sections within the context of a Script.

class snowmobile.core.markup.Markup(sn: snowmobile.core.connection.Snowmobile, path: pathlib.Path, contents: Dict[int, Union[Statement, Marker]], nm: Optional[str] = None, prefix: Optional[str] = None, suffix: Optional[str] = None, root_dir: Optional[Union[str, Path]] = None, sub_dir: Optional[str] = None, incl_sql: bool = True, incl_markers: bool = True, incl_sql_tag: bool = False, incl_exp_ctx: bool = True, result_wrap: Optional[str] = None)

Bases: snowmobile.core.Generic

Contains all sections within the context of a Script.

Parameters
  • sn (Snowmobile) – A Snowmobile instance.

  • path (Path) – A full path to the sql file that script was instantiated from.

  • contents (Dict[int, Union[Statement, Marker]]) – A dictionary of the script’s contents (st and markers) by index position.

  • nm (Optional[str]) – Alternate file name to use; defaults to path.name.

  • prefix (Optional[str]) – Prefix to prepend to original file name when exporting.

  • suffix (Optional[str]) – Suffix to append to original file name when exporting.

  • root_dir (Optional[Union[str, Path]]) – Alternate target directory for exports; defaults to ./.snowmobile where . is the directory containing the sql file that the script was created from.

  • sub_dir (Optional[str]) – Alternate sub-directory name; defaults to path.name where path is a full Path to the sql file that the script was created from.

  • incl_sql (bool) – Include statements in export.

  • incl_markers (bool) – Include markers in export.

  • incl_sql_tag (bool) – Include the raw wrap in the sql that is rendered in the md export.

  • incl_exp_ctx (bool) – Include (configurable) disclaimer at the top of exported sql file.

exported

List of file paths that current instance has exported to.

Type

List[Path]

created

List of directory paths that current instance has created (should mostly apply for initial scaffolding build on first run only).

Type

List[Path]

property export_dir(self)pathlib.Path

Documentation sub-directory; .snowmobile by default.

property sections(self)Dict[int, Section]

Dictionary of all sections by index position.

property markdown(self)str

Full markdown file as a string.

property sql(self)

SQL for save.

save(self, md: bool = True, sql: bool = True)None

Save files to disk.

Parameters
  • md (bool) – Export a generated markdown file.

  • sql (bool) – Export a generated sql file.