Commit 1c266038 authored by Matthieu Boileau's avatar Matthieu Boileau
Browse files

Handle single files as material

parent ce2b66f8
......@@ -33,6 +33,7 @@ class NbCourse:
},
'nb': {
'dir': '.',
'timeout': 60,
'material': ()
},
'pages': {
......@@ -205,10 +206,15 @@ class NbCourse:
def get_src_dst_paths(self, src_path: Path):
"""Return a tuple of file paths for source and destination"""
files = get_file_list(src_path)
src_files = [src_path / file for file in files]
dst_path = self.conf['output_path'] / Path(src_path.name)
dst_files = [dst_path / file for file in files]
if src_path.is_dir():
files = get_file_list(src_path)
src_files = [src_path / file for file in files]
dst_path = self.conf['output_path'] / Path(src_path.name)
dst_files = [dst_path / file for file in files]
else: # dealing with single file
src_files = [src_path]
dst_path = self.conf['output_path'] / src_path.name
dst_files = [dst_path]
return src_files, dst_path, dst_files
def task_copy_material(self):
......@@ -248,8 +254,7 @@ class NbCourse:
with open(notebook) as f:
nb = nbformat.read(f, as_version=4)
ep = ExecutePreprocessor(timeout=60,
kernel_name='python3',
ep = ExecutePreprocessor(timeout=self.conf['nb']['timeout'],
allow_errors=True)
ep.preprocess(nb, {'metadata': {'path': self.conf['nb']['path']}})
......
......@@ -10,10 +10,13 @@ IGNORED = '__pycache__'
def update_material(src: Path, dst: Path):
"""Remove dst tree then update with src"""
shutil.rmtree(dst, ignore_errors=True)
shutil.copytree(src, dst, ignore=shutil.ignore_patterns(IGNORED))
try:
shutil.copytree(src, dst, ignore=shutil.ignore_patterns(IGNORED))
except NotADirectoryError:
shutil.copy(src, dst)
def get_file_list(path: Path, relative: bool = True, ignore: list = None):
def get_file_list(path: Path, relative=True, ignore: list = None):
"""Return a list of file paths relative to path"""
ignored = set([IGNORED]) | {ignore}
......
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