Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cb-util
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
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Christoph Alt
cb-util
Commits
a725149b
Commit
a725149b
authored
2 years ago
by
Christoph Alt
Browse files
Options
Downloads
Patches
Plain Diff
added git utility to util
parent
883fe6f8
No related branches found
No related tags found
No related merge requests found
Pipeline
#41924
passed
2 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cbutil/util.py
+40
-0
40 additions, 0 deletions
cbutil/util.py
setup.py
+2
-1
2 additions, 1 deletion
setup.py
with
42 additions
and
1 deletion
cbutil/util.py
+
40
−
0
View file @
a725149b
import
git
from
typing
import
Union
,
Tuple
from
pathlib
import
Path
def
remove_newline
(
string
:
str
)
->
str
:
return
string
.
replace
(
"
\n
"
,
"
"
).
strip
()
def
read_file_line_wise
(
path
):
def
read_file_line_wise
(
path
):
"""
Linewise generator of a file
"""
"""
Linewise generator of a file
"""
with
open
(
path
,
"
r
"
)
as
file_to_read
:
with
open
(
path
,
"
r
"
)
as
file_to_read
:
for
line
in
file_to_read
.
readlines
():
for
line
in
file_to_read
.
readlines
():
yield
line
.
strip
(
"
\n
"
)
yield
line
.
strip
(
"
\n
"
)
def
get_repo
(
repo_path
:
Union
[
Path
,
str
])
->
git
.
Repo
:
return
git
.
Repo
(
repo_path
)
def
get_current_head
(
repo
:
git
.
Repo
)
->
git
.
Commit
:
return
repo
.
head
.
commit
def
get_commit_infos
(
commit
)
->
Tuple
[
str
,
str
]:
return
commit
.
hexsha
,
commit
.
message
def
get_head_info
(
repo_path
:
Path
):
return
get_commit_infos
(
get_current_head
(
get_repo
(
repo_path
)))
def
get_submodule
(
submodule_name
:
str
,
repo
:
git
.
Repo
)
->
git
.
Submodule
:
return
repo
.
submodule
(
submodule_name
)
def
get_submodule_path
(
submodule_name
:
str
,
repo_path
:
Union
[
Path
,
str
]
=
"
.
"
)
->
Path
:
submodule_path
=
get_submodule
(
submodule_name
,
get_repo
(
repo_path
)).
path
return
Path
(
repo_path
,
submodule_path
)
def
get_git_infos
(
repo_path
:
Union
[
Path
,
str
],
*
,
commit_key
=
"
commit
"
,
commit_msg_key
=
"
commit_message
"
):
commit
,
commit_msg
=
get_commit_infos
(
get_current_head
(
get_repo
(
repo_path
)))
commit_msg
=
remove_newline
(
commit_msg
)
return
{
commit_key
:
commit
,
commit_msg_key
:
commit_msg
}
This diff is collapsed.
Click to expand it.
setup.py
+
2
−
1
View file @
a725149b
...
@@ -9,7 +9,8 @@ setup(name="cb-util",
...
@@ -9,7 +9,8 @@ setup(name="cb-util",
packages
=
find_packages
(
include
=
[
"
cbutil
"
]),
packages
=
find_packages
(
include
=
[
"
cbutil
"
]),
install_requires
=
[
install_requires
=
[
"
python-dotenv
"
,
"
python-dotenv
"
,
"
influxdb
"
"
influxdb
"
,
"
gitpython
"
,
],
],
setup_requires
=
[
'
pytest-runner
'
],
setup_requires
=
[
'
pytest-runner
'
],
tests_require
=
[
'
pytest
'
]
tests_require
=
[
'
pytest
'
]
...
...
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