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

Handle single files as material

parent e9f401e2
Pipeline #6008 passed with stage
in 53 seconds
......@@ -213,7 +213,8 @@ class NbCourse:
dst_files = [dst_path / file for file in files]
else: # dealing with single file, preserve directory tree
src_files = [src_path]
dst_path = self.conf['output_path'] / src_path.name
rpath = src_path.relative_to(self.conf['nb']['dir'])
dst_path = self.conf['output_path'] / rpath
dst_files = [dst_path]
return src_files, dst_path, dst_files
......
......@@ -2,6 +2,7 @@ import shutil
from pathlib import Path
from zipfile import ZipFile
import inspect
import os
import re
IGNORED = '__pycache__'
......@@ -20,7 +21,6 @@ def update_material(src: Path, dst: Path):
shutil.copy(src, dst)
def get_file_list(path: Path, relative=True, ignore: list = None):
"""Return a list of file paths relative to path"""
ignored = set([IGNORED]) | {ignore}
......@@ -33,9 +33,22 @@ def get_file_list(path: Path, relative=True, ignore: list = None):
if (obj.is_file() and ignored.isdisjoint(obj.parts))]
def clean_tree(target):
def clean_tree(target: Path):
"""Clean tree ignoring errors"""
shutil.rmtree(target, ignore_errors=True)
def remove_parent(path: Path):
"""Remove parent directory recursively if empty"""
parent = path.parent
if str(parent) != '.' and not os.listdir(parent):
parent.rmdir()
remove_parent(parent)
if target.is_file():
target.unlink()
remove_parent(target)
else:
shutil.rmtree(target, ignore_errors=True)
def update_dict(current: dict, new: dict):
......
sample/nbcourse.yml
\ No newline at end of file
......@@ -40,4 +40,5 @@ nb:
dir: 'sample'
material:
- fig
- exos
\ No newline at end of file
- exos
- a_dir/a_file.txt
\ No newline at end of file
......@@ -56,3 +56,11 @@ def test_nbcourse_build(create_project):
course = NbCourse(Path('nbcourse.yml'))
course.conf['book']
assert course.build(["-n 4"]) == 0
def test_nbcourse_clean(create_project):
"""Test sample build then clean with nbcourse.yml sample file"""
course = NbCourse(Path('nbcourse.yml'))
course.conf['book']
course.build(["-n 4"])
course.build(["clean"])
......@@ -53,7 +53,7 @@ def temporary_directory(tmpdir):
def test_update_material(temporary_directory):
"""Check that a directory tree is updated"""
"""Check that a directory tree is updated"""
src = TESTS_PATH / Path("sample/fig")
dst = Path("build/fig")
update_material(src, dst)
......@@ -62,7 +62,7 @@ def test_update_material(temporary_directory):
def test_update_material_file(temporary_directory):
"""Check that a single file is updated"""
"""Check that a single file is updated"""
src = TESTS_PATH / Path("sample/exos/helloworld.py")
dst = Path("build/exos/helloworld.py")
update_material(src, dst)
......
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