Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Matthieu Boileau
nbcourse
Commits
1c266038
Commit
1c266038
authored
Feb 05, 2020
by
Matthieu Boileau
Browse files
Handle single files as material
parent
ce2b66f8
Changes
2
Hide whitespace changes
Inline
Side-by-side
nbcourse/nbcourse.py
View file @
1c266038
...
...
@@ -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'
]}})
...
...
nbcourse/utils.py
View file @
1c266038
...
...
@@ -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
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment