Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CADET-RDM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IBG-1
ModSim
CADET
CADET-RDM
Commits
6025b3d9
Commit
6025b3d9
authored
1 year ago
by
Ronald Jäpel
Browse files
Options
Downloads
Patches
Plain Diff
Incorporate jupyter functionality
parent
7c8ac579
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cadetrdm/jupyter_functionality.py
+15
-18
15 additions, 18 deletions
cadetrdm/jupyter_functionality.py
cadetrdm/repositories.py
+15
-0
15 additions, 0 deletions
cadetrdm/repositories.py
with
30 additions
and
18 deletions
cadetrdm/jupyter_functionality.py
+
15
−
18
View file @
6025b3d9
...
...
@@ -14,6 +14,10 @@ class Notebook:
def
__init__
(
self
,
notebook_path
):
self
.
notebook_path
=
Path
(
notebook_path
)
@property
def
notebook_name
(
self
):
return
str
(
self
.
notebook_path
.
name
).
replace
(
"
.
"
,
"
_
"
)
def
check_execution_order
(
self
,
check_all_executed
=
False
,
check_top_to_bottom
=
False
,
...
...
@@ -96,21 +100,15 @@ class Notebook:
app
=
JupyterFrontEnd
()
app
.
commands
.
execute
(
'
docmanager:reload
'
)
def
wait_for_user
(
self
,
message
):
proceed
=
input
(
message
+
"
Y/n
"
)
if
proceed
.
lower
()
==
"
y
"
or
proceed
==
""
:
return
True
else
:
return
False
def
clear_and_rerun_notebook
(
self
,
force_rerun
=
False
,
timeout
=
600
):
def
check_and_rerun_notebook
(
self
,
force_rerun
=
False
,
timeout
=
600
):
if
"
nbconvert_call
"
in
sys
.
argv
:
return
self
.
save_ipynb
()
# wait a second for the save process to finish.
time
.
sleep
(
1
)
is_in_order
=
self
.
check_execution_order
(
self
.
notebook_filename
,
exclude_last_cell
=
False
)
is_in_order
=
self
.
check_execution_order
(
exclude_last_cell
=
False
)
if
is_in_order
and
not
force_rerun
:
print
(
"
Notebook was already executed in order.
"
)
...
...
@@ -122,27 +120,26 @@ class Notebook:
return
print
(
"
Rerunning.
"
)
with
open
(
self
.
notebook_
filename
)
as
f
:
with
open
(
self
.
notebook_
path
)
as
f
:
nb
=
nbf
.
read
(
f
,
as_version
=
4
)
ep
=
ExecutePreprocessor
(
timeout
=
timeout
,
kernel_name
=
'
python3
'
,
extra_arguments
=
[
"
nbconvert_call
"
])
ep
.
preprocess
(
nb
,
)
with
open
(
self
.
notebook_
filename
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
f
:
with
open
(
self
.
notebook_
path
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
f
:
nbf
.
write
(
nb
,
f
)
self
.
reload_notebook
()
def
convert_ipynb
(
self
,
formats
:
list
=
None
):
def
convert_ipynb
(
self
,
output_dir
,
formats
:
list
=
None
):
if
formats
is
None
:
formats
=
[
"
pdf
"
,
"
python
"
]
app
=
NbConvertApp
()
app
.
initialize
()
output_root_directory
=
os
.
path
.
join
(
r
"
C:\Users\ronal\PycharmProjects\git_lfs_test_2
"
,
"
results
"
,
self
.
notebook_path
.
name
.
replace
(
'
.
'
,
'
_
'
))
output_root_directory
=
os
.
path
.
join
(
output_dir
,
self
.
notebook_name
)
for
export_format
in
formats
:
app
.
export_format
=
export_format
app
.
notebooks
=
[
self
.
notebook_path
]
app
.
notebooks
=
[
str
(
self
.
notebook_path
)
]
app
.
output_base
=
os
.
path
.
join
(
output_root_directory
,
self
.
notebook_path
.
name
.
replace
(
'
.ipynb
'
,
''
))
if
not
os
.
path
.
exists
(
output_root_directory
):
...
...
@@ -151,7 +148,7 @@ class Notebook:
def
export_all_figures
(
self
,
output_dir
):
file_without_extension
=
self
.
notebook_path
.
stem
images
=
junix
.
export_images
(
filepath
=
self
.
notebook_path
,
output_dir
=
os
.
path
.
join
(
output_dir
,
str
(
self
.
notebook_path
.
name
).
replace
(
"
.
"
,
"
_
"
)),
images
=
junix
.
export_images
(
filepath
=
str
(
self
.
notebook_path
),
output_dir
=
os
.
path
.
join
(
output_dir
,
self
.
notebook_name
),
prefix
=
file_without_extension
)
This diff is collapsed.
Click to expand it.
cadetrdm/repositories.py
+
15
−
0
View file @
6025b3d9
...
...
@@ -1015,6 +1015,21 @@ class ProjectRepo(BaseRepo):
else
:
self
.
exit_context
(
message
=
results_commit_message
)
def
commit_notebook
(
self
,
notebook_path
:
str
,
results_commit_message
:
str
,
force_rerun
=
False
,
timeout
=
600
,
conversion_formats
:
list
=
None
):
if
not
Path
(
notebook_path
).
is_absolute
():
notebook_path
=
self
.
working_dir
/
notebook_path
self
.
enter_context
()
notebook
=
Notebook
(
notebook_path
)
notebook
.
check_and_rerun_notebook
(
force_rerun
=
force_rerun
,
timeout
=
timeout
)
notebook
.
convert_ipynb
(
self
.
output_path
,
formats
=
conversion_formats
)
notebook
.
export_all_figures
(
self
.
output_path
)
self
.
exit_context
(
results_commit_message
)
class
OutputRepo
(
BaseRepo
):
pass
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment