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
GitLab 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
9ad5a8bb
Commit
9ad5a8bb
authored
Oct 24, 2023
by
Ronald Jäpel
Browse files
Options
Downloads
Patches
Plain Diff
Add full cache of output
parent
3fab1dcb
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
cadetrdm/repositories.py
+30
-7
30 additions, 7 deletions
cadetrdm/repositories.py
tests/test_git_adapter.py
+3
-1
3 additions, 1 deletion
tests/test_git_adapter.py
with
33 additions
and
8 deletions
cadetrdm/repositories.py
+
30
−
7
View file @
9ad5a8bb
import
os
import
json
import
sys
from
datetime
import
datetime
import
shutil
import
contextlib
import
glob
from
stat
import
S_IREAD
,
S_IWRITE
from
tabulate
import
tabulate
import
pandas
as
pd
...
...
@@ -336,7 +339,7 @@ class ProjectRepo(BaseRepo):
if
output_folder
is
not
None
:
self
.
output_folder
=
output_folder
el
if
output_folder
is
Non
e
:
el
s
e
:
self
.
output_folder
=
"
output
"
self
.
_output_repo
=
ResultsRepo
(
os
.
path
.
join
(
self
.
working_dir
,
self
.
output_folder
))
...
...
@@ -432,6 +435,7 @@ class ProjectRepo(BaseRepo):
"
Project repo commit hash
"
:
str
(
self
.
head
.
commit
),
"
Project repo folder name
"
:
os
.
path
.
split
(
self
.
working_dir
)[
-
1
],
"
Project repo remotes
"
:
[
str
(
remote
.
url
)
for
remote
in
self
.
remotes
],
"
Python sys args
"
:
str
(
sys
.
argv
)
}
csv_header
=
"
,
"
.
join
(
meta_info_dict
.
keys
())
csv_data
=
"
,
"
.
join
([
str
(
x
)
for
x
in
meta_info_dict
.
values
()])
...
...
@@ -557,13 +561,15 @@ class ProjectRepo(BaseRepo):
source_filepath
=
os
.
path
.
join
(
self
.
output_repo
.
working_dir
,
file_path
)
# target_folder = os.path.join(self._output_folder + "_cached", branch_name)
target_folder
=
os
.
path
.
join
(
self
.
output_repo
.
working_dir
,
"
cached
"
,
branch_name
)
target_folder
=
os
.
path
.
join
(
self
.
output_repo
.
working_dir
+
"
_cached
"
,
branch_name
)
os
.
makedirs
(
target_folder
,
exist_ok
=
True
)
target_filepath
=
os
.
path
.
join
(
target_folder
,
file_path
)
if
os
.
path
.
exists
(
target_filepath
):
os
.
chmod
(
target_filepath
,
S_IWRITE
)
os
.
remove
(
target_filepath
)
shutil
.
copyfile
(
source_filepath
,
target_filepath
)
os
.
chmod
(
target_filepath
,
S_IREAD
)
self
.
output_repo
.
_git
.
checkout
(
previous_branch
)
if
has_stashed_changes
:
...
...
@@ -575,8 +581,8 @@ class ProjectRepo(BaseRepo):
"""
Delete all previously cached results.
"""
if
os
.
path
.
exists
(
self
.
output_
folde
r
+
"
_cached
"
):
shutil
.
rmtree
(
self
.
output_
folde
r
+
"
_cached
"
)
if
os
.
path
.
exists
(
self
.
output_
repo
.
working_di
r
+
"
_cached
"
):
shutil
.
rmtree
(
self
.
output_
repo
.
working_di
r
+
"
_cached
"
)
def
enter_context
(
self
,
):
"""
...
...
@@ -610,6 +616,22 @@ class ProjectRepo(BaseRepo):
output_repo
.
prepare_new_branch
(
new_branch_name
)
return
new_branch_name
def
copy_data_to_cache
(
self
):
"""
Copy all existing output results into a cached folder and make it read-only.
:return:
"""
source_filepath
=
self
.
output_repo
.
working_dir
branch_name
=
self
.
output_repo
.
active_branch
.
name
target_folder
=
os
.
path
.
join
(
self
.
output_repo
.
working_dir
+
"
_cached
"
,
branch_name
)
shutil
.
copytree
(
source_filepath
,
target_folder
)
for
filename
in
glob
.
iglob
(
f
"
{
target_folder
}
/**/*
"
,
recursive
=
True
):
os
.
chmod
(
os
.
path
.
abspath
(
filename
),
S_IREAD
)
def
exit_context
(
self
,
message
):
"""
After running all project code, this prepares the commit of the results to the output repository. This includes
...
...
@@ -629,13 +651,14 @@ class ProjectRepo(BaseRepo):
try
:
# This has to be using ._git.commit to raise an error if no results have been written.
commit_return
=
self
.
output_repo
.
_git
.
commit
(
"
-m
"
,
message
)
self
.
copy_data_to_cache
()
self
.
update_output_master_logs
()
print
(
"
\n
"
+
commit_return
+
"
\n
"
)
except
git
.
exc
.
GitCommandError
as
e
:
self
.
output_repo
.
delete_active_branch_if_branch_is_empty
()
raise
e
finally
:
self
.
remove_cached_files
()
#
self.remove_cached_files()
self
.
_is_in_context_manager
=
False
self
.
_on_context_enter_commit_hash
=
None
...
...
This diff is collapsed.
Click to expand it.
tests/test_git_adapter.py
+
3
−
1
View file @
9ad5a8bb
...
...
@@ -158,7 +158,7 @@ def test_cadet_rdm(path_to_repo):
# because these depend on one-another and there is no native support afaik for sequential tests
# these tests are called sequentially here as try_ functions.
try_initialize_git_repo
(
path_to_repo
)
try_initialize_from_remote
()
#
try_initialize_from_remote()
try_add_remote
(
path_to_repo
)
# try_add_submodule(path_to_repo)
...
...
@@ -170,4 +170,6 @@ def test_cadet_rdm(path_to_repo):
results_branch_name
=
try_commit_results_data
(
path_to_repo
)
try_print_log
(
path_to_repo
)
try_commit_code
(
path_to_repo
)
try_load_previous_output
(
path_to_repo
,
results_branch_name
)
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