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
770523e9
Commit
770523e9
authored
1 year ago
by
Ronald Jäpel
Browse files
Options
Downloads
Patches
Plain Diff
Reduce dependencies
parent
41170a8b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cadetrdm/jupyter_functionality.py
+23
-19
23 additions, 19 deletions
cadetrdm/jupyter_functionality.py
cadetrdm/repositories.py
+4
-14
4 additions, 14 deletions
cadetrdm/repositories.py
setup.cfg
+7
-6
7 additions, 6 deletions
setup.cfg
with
34 additions
and
39 deletions
cadetrdm/jupyter_functionality.py
+
23
−
19
View file @
770523e9
...
@@ -2,24 +2,25 @@ import sys
...
@@ -2,24 +2,25 @@ import sys
import
time
import
time
import
os
import
os
from
pathlib
import
Path
from
pathlib
import
Path
import
traceback
from
cadetrdm.io_utils
import
wait_for_user
from
cadetrdm.io_utils
import
wait_for_user
from
ipylab
import
JupyterFrontEnd
import
junix
import
nbformat
as
nbf
try
:
from
nbconvert.preprocessors
import
ExecutePreprocessor
from
nbconvert.nbconvertapp
import
NbConvertApp
except
ModuleNotFoundError
as
e
:
# traceback.print_exc()
print
(
"
No working nbconvert installation found OR a conflict in your packages found.
"
)
print
(
"
For more information, import nbconvert and check the error.
"
)
class
Notebook
:
class
Notebook
:
def
__init__
(
self
,
notebook_path
):
def
__init__
(
self
,
notebook_path
):
import
nbformat
as
nbf
self
.
nbf
=
nbf
try
:
from
nbconvert.preprocessors
import
ExecutePreprocessor
from
nbconvert.nbconvertapp
import
NbConvertApp
self
.
ExecutePreprocessor
=
ExecutePreprocessor
self
.
NbConvertApp
=
NbConvertApp
except
ModuleNotFoundError
as
e
:
# traceback.print_exc()
print
(
"
No working nbconvert installation found OR a conflict in your packages found.
"
)
print
(
"
For more information, import nbconvert and check the error.
"
)
self
.
notebook_path
=
Path
(
notebook_path
)
self
.
notebook_path
=
Path
(
notebook_path
)
@property
@property
...
@@ -31,7 +32,7 @@ class Notebook:
...
@@ -31,7 +32,7 @@ class Notebook:
check_top_to_bottom
=
False
,
check_top_to_bottom
=
False
,
check_in_order
=
True
,
check_in_order
=
True
,
exclude_last_cell
=
False
):
exclude_last_cell
=
False
):
notebook
=
nbf
.
read
(
self
.
notebook_path
,
nbf
.
NO_CONVERT
)
notebook
=
self
.
nbf
.
read
(
self
.
notebook_path
,
self
.
nbf
.
NO_CONVERT
)
# extract all code cells (disregard markdown, raw and others), then extract the execution order
# extract all code cells (disregard markdown, raw and others), then extract the execution order
output_cells
=
[
cell
for
cell
in
notebook
.
cells
if
cell
[
"
cell_type
"
]
==
"
code
"
]
output_cells
=
[
cell
for
cell
in
notebook
.
cells
if
cell
[
"
cell_type
"
]
==
"
code
"
]
...
@@ -96,6 +97,7 @@ class Notebook:
...
@@ -96,6 +97,7 @@ class Notebook:
@staticmethod
@staticmethod
def
save_ipynb
():
def
save_ipynb
():
from
ipylab
import
JupyterFrontEnd
app
=
JupyterFrontEnd
()
app
=
JupyterFrontEnd
()
print
(
"
Saving
"
,
end
=
""
)
print
(
"
Saving
"
,
end
=
""
)
# note: docmanager:save doesn't lock the python thread until saving is completed.
# note: docmanager:save doesn't lock the python thread until saving is completed.
...
@@ -106,6 +108,7 @@ class Notebook:
...
@@ -106,6 +108,7 @@ class Notebook:
print
(
""
)
print
(
""
)
def
reload_notebook
(
self
):
def
reload_notebook
(
self
):
from
ipylab
import
JupyterFrontEnd
app
=
JupyterFrontEnd
()
app
=
JupyterFrontEnd
()
app
.
commands
.
execute
(
'
docmanager:reload
'
)
app
.
commands
.
execute
(
'
docmanager:reload
'
)
...
@@ -131,20 +134,20 @@ class Notebook:
...
@@ -131,20 +134,20 @@ class Notebook:
print
(
"
Rerunning.
"
)
print
(
"
Rerunning.
"
)
with
open
(
self
.
notebook_path
)
as
f
:
with
open
(
self
.
notebook_path
)
as
f
:
nb
=
nbf
.
read
(
f
,
as_version
=
4
)
nb
=
self
.
nbf
.
read
(
f
,
as_version
=
4
)
ep
=
ExecutePreprocessor
(
timeout
=
timeout
,
kernel_name
=
'
python3
'
,
extra_arguments
=
[
"
nbconvert_call
"
])
ep
=
self
.
ExecutePreprocessor
(
timeout
=
timeout
,
kernel_name
=
'
python3
'
,
extra_arguments
=
[
"
nbconvert_call
"
])
ep
.
preprocess
(
nb
,
)
ep
.
preprocess
(
nb
,
)
with
open
(
self
.
notebook_path
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
f
:
with
open
(
self
.
notebook_path
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
f
:
nbf
.
write
(
nb
,
f
)
self
.
nbf
.
write
(
nb
,
f
)
self
.
reload_notebook
()
self
.
reload_notebook
()
def
convert_ipynb
(
self
,
output_dir
,
formats
:
list
=
None
):
def
convert_ipynb
(
self
,
output_dir
,
formats
:
list
=
None
):
if
formats
is
None
:
if
formats
is
None
:
formats
=
[
"
html
"
,
]
formats
=
[
"
html
"
,
]
app
=
NbConvertApp
()
app
=
self
.
NbConvertApp
()
app
.
initialize
()
app
.
initialize
()
output_root_directory
=
os
.
path
.
join
(
output_dir
,
self
.
notebook_name
)
output_root_directory
=
os
.
path
.
join
(
output_dir
,
self
.
notebook_name
)
for
export_format
in
formats
:
for
export_format
in
formats
:
...
@@ -157,8 +160,9 @@ class Notebook:
...
@@ -157,8 +160,9 @@ class Notebook:
app
.
start
()
app
.
start
()
def
export_all_figures
(
self
,
output_dir
):
def
export_all_figures
(
self
,
output_dir
):
import
junix
file_without_extension
=
self
.
notebook_path
.
stem
file_without_extension
=
self
.
notebook_path
.
stem
images
=
junix
.
export_images
(
filepath
=
str
(
self
.
notebook_path
),
images
=
junix
.
export_images
(
filepath
=
str
(
self
.
notebook_path
),
output_dir
=
os
.
path
.
join
(
output_dir
,
self
.
notebook_name
),
output_dir
=
os
.
path
.
join
(
output_dir
,
self
.
notebook_name
),
prefix
=
file_without_extension
)
prefix
=
file_without_extension
)
This diff is collapsed.
Click to expand it.
cadetrdm/repositories.py
+
4
−
14
View file @
770523e9
...
@@ -13,7 +13,6 @@ from urllib.request import urlretrieve
...
@@ -13,7 +13,6 @@ from urllib.request import urlretrieve
from
ipylab
import
JupyterFrontEnd
from
ipylab
import
JupyterFrontEnd
from
tabulate
import
tabulate
from
tabulate
import
tabulate
import
pandas
as
pd
from
cadetrdm.io_utils
import
recursive_chmod
,
write_lines_to_file
,
wait_for_user
,
init_lfs
from
cadetrdm.io_utils
import
recursive_chmod
,
write_lines_to_file
,
wait_for_user
,
init_lfs
from
cadetrdm.jupyter_functionality
import
Notebook
from
cadetrdm.jupyter_functionality
import
Notebook
...
@@ -696,22 +695,13 @@ class ProjectRepo(BaseRepo):
...
@@ -696,22 +695,13 @@ class ProjectRepo(BaseRepo):
tsv_filepath
=
self
.
working_dir
/
self
.
_output_folder
/
"
log.tsv
"
tsv_filepath
=
self
.
working_dir
/
self
.
_output_folder
/
"
log.tsv
"
df
=
pd
.
read_csv
(
tsv_filepath
,
sep
=
"
\t
"
,
header
=
0
)
with
open
(
tsv_filepath
,
"
r
"
)
as
filehandle
:
# Clean up the headers
lines
=
filehandle
.
readlines
()
df
=
df
.
rename
(
columns
=
{
"
Output repo commit message
"
:
'
Output commit message
'
,
"
Output repo branch
"
:
"
Output branch
"
,
"
Output repo commit hash
"
:
"
Output hash
"
,
"
Project repo commit hash
"
:
"
Project hash
"
})
# Shorten the commit hashes
df
.
loc
[:,
"
Output hash
"
]
=
df
.
loc
[:,
"
Output hash
"
].
apply
(
lambda
x
:
x
[:
8
])
# Shorten commit messages
df
.
loc
[:,
"
Output commit message
"
]
=
df
.
loc
[:,
"
Output commit message
"
].
apply
(
lambda
x
:
x
[:
55
])
df
.
loc
[:,
"
Output commit message
"
]
=
df
.
loc
[:,
"
Output commit message
"
].
apply
(
insert_newlines
)
# Select only columns of interest
line_array
=
[
line
.
replace
(
"
\n
"
,
""
).
split
(
"
\t
"
)
for
line
in
lines
]
df
=
df
.
loc
[:,
[
"
Output commit message
"
,
"
Output hash
"
,
"
Output branch
"
]]
# Print
# Print
print
(
tabulate
(
df
,
headers
=
df
.
columns
,
showindex
=
False
))
print
(
tabulate
(
line_array
[
1
:],
headers
=
line_array
[
0
]
))
self
.
output_repo
.
checkout
(
self
.
output_repo
.
_most_recent_branch
)
self
.
output_repo
.
checkout
(
self
.
output_repo
.
_most_recent_branch
)
...
...
This diff is collapsed.
Click to expand it.
setup.cfg
+
7
−
6
View file @
770523e9
...
@@ -24,12 +24,6 @@ install_requires =
...
@@ -24,12 +24,6 @@ install_requires =
git-lfs
git-lfs
click
click
tabulate
tabulate
pandas
nbformat
nbconvert
ipylab
junix
jupytext
include_package_data
=
True
include_package_data
=
True
...
@@ -48,6 +42,13 @@ testing =
...
@@ -48,6 +42,13 @@ testing =
numpy
numpy
build
build
jupyter
=
nbformat
nbconvert
ipylab
junix
jupytext
docs
=
docs
=
sphinx>=5.3.0
sphinx>=5.3.0
sphinxcontrib-bibtex>=2.5.0
sphinxcontrib-bibtex>=2.5.0
...
...
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