Advanced Reference
Note
La référence de l'API est générée à partir de Python Docstring, donc elle n'est disponible qu'en anglais.
Tip
Dans cette page, vous pouvez trouver des références pour les modules Python qui sont utilisés dans CLI ou pas fréquemment utilisés. Les modules Python fréquemment utilisés peuvent être trouvés dans Python API.
mmg.base_item
FileItem
dataclass
A dataclass for the file item.
Attributes:
Name | Type | Description |
---|---|---|
norm_path |
str
|
The normalized path of the base file. |
abs_path |
str
|
The absolute path of the base file. |
extension |
str
|
The extension of the base file. |
base_file_to_item
base_file_to_item(path: str, file_name: str) -> FileItem
Convert the base file name to the base file item.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The path of the base file. |
required |
file_name |
str
|
The file name to convert. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the file name is not a base file. |
Returns:
Name | Type | Description |
---|---|---|
FileItem |
FileItem
|
The base file item. |
collect_bases_from_dir
collect_bases_from_dir(
dir: str, recursive: bool
) -> Set[FileItem]
Collect all base files from the given directory and the recursive flag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dir |
str
|
The directory to collect. |
required |
recursive |
bool
|
The recursive flag. |
required |
Returns:
Type | Description |
---|---|
Set[FileItem]
|
Set[FileItem]: The set of the base file items. |
collect_bases_from_files
collect_bases_from_files(
file_names: List[str],
) -> Set[FileItem]
Collect all base files from the given file names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_names |
List[str]
|
The list of file names to collect. |
required |
Returns:
Type | Description |
---|---|
Set[FileItem]
|
Set[FileItem]: The set of the base file items. |
is_base_file
is_base_file(file_name: str) -> bool
Return true if the file is *.base.md
or *.base.ipynb
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name |
str
|
The file name to check. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the file is |
shorten_path
shorten_path(path: str, max_length: int = 50) -> str
Shorten the path to a given length. https://stackoverflow.com/questions/74300488/pretty-printing-of-paths-in-python
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The path to shorten. |
required |
max_length |
int
|
The maximum length of the path. Defaults to 20. |
50
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The shortened path. |
walk_base_file
walk_base_file(
path: str, recursive: bool
) -> Iterator[FileItem]
Walk the given path and find all base files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The path to walk. |
required |
recursive |
bool
|
The recursive flag. |
required |
Returns:
Type | Description |
---|---|
Iterator[FileItem]
|
Iterator[FileItem]: The iterator of the base file items. |
mmg.classifier
JupyterClassifier
init_targets
init_targets(base_jn: Dict)
Initialize the target notebooks and copy metadata.
push
push(cell: Dict)
Divide the cell into each language and push to the target notebooks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cell |
Dict
|
The cell to push. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
Cannot push to the classifier after freezing. |
mmg.cli_log
mmg.cli_process
query_yes_no
query_yes_no(question)
Ask a yes/no question via raw_input() and return their answer. https://stackoverflow.com/questions/3041986/apt-command-line-interface-like-yes-no-input
"question" is a string that is presented to the user.
"default" is the presumed answer if the user just hits
The "answer" return value is True for "yes" or False for "no".
mmg.cli
mmgcli
mmgcli(
file_names: List[str],
recursive: bool,
batch: str,
output_format: str,
css: str,
yes: bool,
skip_validation: bool,
validation_only: bool,
verbose: int,
)
FILE_NAMES: Base file names to convert. *.base.md
or *.base.ipynb
are available.
Here are some examples:
mmg *.base.md
mmg *.base.ipynb
mmg *.base.md *.base.ipynb -o pdf --css github-dark
mmg --recursive
mmg --recursive --validation-only
mmg --batch mmg.yml
mmg.exceptions
BadConfigError
Bases: Exception
Raised when the configuration is invalid.
mmg.output
handle_html_or_pdf
handle_html_or_pdf(
target_item: FileItem,
input_format: str,
css: str,
content: any,
)
Saves the provided content into a HTML file or a PDF file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_item |
FileItem
|
Holds the file information of the target file. |
required |
input_format |
str
|
The format of the input content - either "md" or "ipynb". |
required |
css |
str
|
This parameter indicates the styling used for the HTML conversion. It can be a path to a CSS file, or one of the two preset values: "github-light" or "github-dark". This option is mandatory, regardless of the output format. This is because, even for PDF output, the content is first converted to HTML, then to PDF. |
required |
content |
any
|
This can be a List[str] for markdown content, or a Dict for a jupyter notebook. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
Raised when an unsupported output format is specified. |