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
e22e9295
Commit
e22e9295
authored
1 year ago
by
Ronald Jäpel
Browse files
Options
Downloads
Patches
Plain Diff
Add functionality to print overview of output repo contents
parent
b71d2f18
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cadetrdm/cli_integration.py
+8
-0
8 additions, 0 deletions
cadetrdm/cli_integration.py
cadetrdm/repositories.py
+38
-0
38 additions, 0 deletions
cadetrdm/repositories.py
setup.cfg
+2
-0
2 additions, 0 deletions
setup.cfg
tests/test_git_adapter.py
+9
-1
9 additions, 1 deletion
tests/test_git_adapter.py
with
57 additions
and
1 deletion
cadetrdm/cli_integration.py
+
8
−
0
View file @
e22e9295
import
click
import
click
from
.repositories
import
ProjectRepo
from
.initialize_repo
import
initialize_git_repo
as
initialize_git_repo_implementation
from
.initialize_repo
import
initialize_git_repo
as
initialize_git_repo_implementation
from
.initialize_repo
import
initialize_from_remote
as
initialize_from_remote_implementation
from
.initialize_repo
import
initialize_from_remote
as
initialize_from_remote_implementation
from
.conda_env_utils
import
prepare_conda_env
as
prepare_conda_env_implementation
from
.conda_env_utils
import
prepare_conda_env
as
prepare_conda_env_implementation
...
@@ -43,3 +44,10 @@ def initialize_git_repo(path_to_repo: str, output_repo_name: (str | bool) = "out
...
@@ -43,3 +44,10 @@ def initialize_git_repo(path_to_repo: str, output_repo_name: (str | bool) = "out
help
=
'
Url to the environment.yml file.
'
)
help
=
'
Url to the environment.yml file.
'
)
def
prepare_conda_env
(
url
):
def
prepare_conda_env
(
url
):
prepare_conda_env_implementation
(
url
)
prepare_conda_env_implementation
(
url
)
@cli.command
()
@click.argument
(
'
path_to_repo
'
)
def
print_output_log
(
path_to_repo
):
repo
=
ProjectRepo
(
path_to_repo
)
repo
.
print_output_log
()
This diff is collapsed.
Click to expand it.
cadetrdm/repositories.py
+
38
−
0
View file @
e22e9295
...
@@ -4,6 +4,9 @@ from datetime import datetime
...
@@ -4,6 +4,9 @@ from datetime import datetime
import
shutil
import
shutil
import
contextlib
import
contextlib
from
tabulate
import
tabulate
import
pandas
as
pd
try
:
try
:
import
git
import
git
except
ImportError
:
except
ImportError
:
...
@@ -80,6 +83,10 @@ class BaseRepo:
...
@@ -80,6 +83,10 @@ class BaseRepo:
"""
"""
self
.
_git_repo
.
create_remote
(
remote_name
,
url
=
remote_url
)
self
.
_git_repo
.
create_remote
(
remote_name
,
url
=
remote_url
)
def
checkout
(
self
,
*
args
,
**
kwargs
):
self
.
_most_recent_branch
=
self
.
active_branch
self
.
_git
.
checkout
(
*
args
,
**
kwargs
)
def
push
(
self
,
remote
=
None
,
local_branch
=
None
,
remote_branch
=
None
):
def
push
(
self
,
remote
=
None
,
local_branch
=
None
,
remote_branch
=
None
):
"""
"""
Push local branch to remote.
Push local branch to remote.
...
@@ -345,6 +352,36 @@ class ProjectRepo(BaseRepo):
...
@@ -345,6 +352,36 @@ class ProjectRepo(BaseRepo):
"""
"""
self
.
_output_repo
.
_git
.
checkout
(
self
.
_most_recent_branch
)
self
.
_output_repo
.
_git
.
checkout
(
self
.
_most_recent_branch
)
def
print_output_log
(
self
):
def
insert_newlines
(
string
,
every
=
30
):
lines
=
[]
for
i
in
range
(
0
,
len
(
string
),
every
):
lines
.
append
(
string
[
i
:
i
+
every
])
return
'
\n
'
.
join
(
lines
)
self
.
output_repo
.
checkout
(
"
master
"
)
csv_filepath
=
os
.
path
.
join
(
self
.
working_dir
,
self
.
output_folder
,
"
logs
"
,
"
log.csv
"
)
df
=
pd
.
read_csv
(
csv_filepath
,
sep
=
"
,
"
,
header
=
0
)
# Clean up the headers
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
df
=
df
.
loc
[:,
[
"
Output commit message
"
,
"
Output hash
"
,
"
Output branch
"
]]
# Print
print
(
tabulate
(
df
,
headers
=
df
.
columns
,
showindex
=
False
))
self
.
output_repo
.
checkout
(
self
.
output_repo
.
_most_recent_branch
)
def
update_output_master_logs
(
self
,
):
def
update_output_master_logs
(
self
,
):
"""
"""
Dumps all the metadata information about the project repositories state and
Dumps all the metadata information about the project repositories state and
...
@@ -355,6 +392,7 @@ class ProjectRepo(BaseRepo):
...
@@ -355,6 +392,7 @@ class ProjectRepo(BaseRepo):
output_repo_hash
=
str
(
self
.
_output_repo
.
head
.
commit
)
output_repo_hash
=
str
(
self
.
_output_repo
.
head
.
commit
)
output_commit_message
=
self
.
_output_repo
.
active_branch
.
commit
.
message
output_commit_message
=
self
.
_output_repo
.
active_branch
.
commit
.
message
output_commit_message
=
output_commit_message
.
replace
(
"
\n
"
,
"
;
"
)
self
.
_output_repo
.
_git
.
checkout
(
"
master
"
)
self
.
_output_repo
.
_git
.
checkout
(
"
master
"
)
...
...
This diff is collapsed.
Click to expand it.
setup.cfg
+
2
−
0
View file @
e22e9295
...
@@ -21,6 +21,8 @@ install_requires =
...
@@ -21,6 +21,8 @@ install_requires =
gitpython>=3.1
gitpython>=3.1
git-lfs
git-lfs
click
click
tabulate
pandas
include_package_data
=
True
include_package_data
=
True
...
...
This diff is collapsed.
Click to expand it.
tests/test_git_adapter.py
+
9
−
1
View file @
e22e9295
...
@@ -107,10 +107,15 @@ def try_commit_results_data(path_to_repo):
...
@@ -107,10 +107,15 @@ def try_commit_results_data(path_to_repo):
with
repo
.
track_results
(
results_commit_message
=
"
Add array
"
):
with
repo
.
track_results
(
results_commit_message
=
"
Add array
"
):
example_generate_results_array
(
path_to_repo
,
output_folder
=
repo
.
output_folder
)
example_generate_results_array
(
path_to_repo
,
output_folder
=
repo
.
output_folder
)
updated_commit_number
=
count_commit_number
(
repo
.
output_repo
)
updated_commit_number
=
count_commit_number
(
repo
.
output_repo
)
assert
current_commit_number
+
1
=
=
updated_commit_number
assert
current_commit_number
<
=
updated_commit_number
return
str
(
repo
.
output_repo
.
active_branch
)
return
str
(
repo
.
output_repo
.
active_branch
)
def
try_print_log
(
path_to_repo
):
repo
=
ProjectRepo
(
path_to_repo
)
repo
.
print_output_log
()
def
try_commit_results_with_uncommitted_code_changes
(
path_to_repo
):
def
try_commit_results_with_uncommitted_code_changes
(
path_to_repo
):
repo
=
ProjectRepo
(
path_to_repo
)
repo
=
ProjectRepo
(
path_to_repo
)
modify_code
(
path_to_repo
)
modify_code
(
path_to_repo
)
...
@@ -162,4 +167,7 @@ def test_cadet_rdm(path_to_repo):
...
@@ -162,4 +167,7 @@ def test_cadet_rdm(path_to_repo):
try_commit_results_with_uncommitted_code_changes
(
path_to_repo
)
try_commit_results_with_uncommitted_code_changes
(
path_to_repo
)
results_branch_name
=
try_commit_results_data
(
path_to_repo
)
results_branch_name
=
try_commit_results_data
(
path_to_repo
)
results_branch_name
=
try_commit_results_data
(
path_to_repo
)
try_print_log
(
path_to_repo
)
try_load_previous_output
(
path_to_repo
,
results_branch_name
)
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