Commit d71210d4 authored by Matthieu Boileau's avatar Matthieu Boileau
Browse files

Some code cleaning

parent 91b8a0f2
......@@ -7,7 +7,6 @@ from .nbcourse import NbCourse, DEFAULT_CONFIG_FILE
from .quickstart import initialize
from pathlib import Path
from .mydoit import MyDoit, ClassTaskLoader
import sys
def main():
......@@ -2,7 +2,7 @@
from doit.cmd_help import Help
from doit.doit_cmd import DoitMain
from doit.cmd_base import TaskLoader, ModuleTaskLoader
from doit.cmd_base import ModuleTaskLoader
import inspect
......@@ -13,7 +13,8 @@ class MyDoitMain(DoitMain):
class MyHelp(Help):
"""Extend doit Help class to add a get_usage() function"""
def get_usage(self, cmds):
def get_usage(cmds):
"""return doit "usage" (basic help) instructions"""
msg = "\n"
for cmd_name in sorted(cmds.keys()):
......@@ -37,10 +38,10 @@ class MyDoit(DoitMain):
# get list of available commands
sub_cmds = self.get_cmds()
help = MyHelp(config=self.config,
return help.get_usage(sub_cmds.to_dict())
doit_help = MyHelp(config=self.config,
return doit_help.get_usage(sub_cmds.to_dict())
class ClassTaskLoader(ModuleTaskLoader):
......@@ -5,15 +5,12 @@ Define a NbCourse object containing:
- Doit tasks defined in task_*() functions
import os
from pathlib import Path
import yaml
from pprint import pformat
import re
import sys
from import result_dep, create_folder, config_changed
from import create_folder, config_changed
from .utils import update_material, clean_tree, get_file_list, update_dict, \
zip_files, clean_file
from .pages import HomePage, MarkdownPage
from .book import Book
import nbformat
......@@ -57,8 +54,8 @@ class NbCourse:
for key in 'nb', 'theme':
self.conf[key]['path'] = Path(self.conf[key]['dir'])
self.conf[key]['material_paths'] = [
self.conf[key]['path'] / Path(dir)
for dir in self.conf[key]['material']
self.conf[key]['path'] / Path(d)
for d in self.conf[key]['material']
self.conf['pages']['path'] = Path(self.conf['pages']['dir'])
self.conf['output_path'] = Path(self.conf['output_dir'])
......@@ -225,9 +222,9 @@ class NbCourse:
def convert_notebook(self, notebook: Path,
output_file: Path,
"""Convert notebook to output_file"""
if format == 'slide':
if to == 'slide':
exporter = self.slide_exporter
exporter = self.html_exporter
......@@ -25,7 +25,8 @@ class HomePage:
self.template_path = conf['template_path']
self.chapters = {}
def _get_chapter(self, path: Path):
def _get_chapter(path: Path):
"""Get chapter from notebook file (source: bookbook)"""
chapter_no = int(re.match(r'(\d+)\-', path.stem).group(1))
......@@ -12,9 +12,9 @@ def update_material(src: Path, dst: Path):
shutil.copytree(src, dst, ignore=shutil.ignore_patterns(IGNORED))
def get_file_list(path: Path, relative: bool = True, ignore: list = []):
def get_file_list(path: Path, relative: bool = True, ignore: list = None):
"""Return a list of file paths relative to path"""
ignored = set([IGNORED]) | set(ignore)
ignored = {[IGNORED]} | {ignore}
def get_path(obj):
"""return a relative or absolute path"""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment