Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
auto_git_info
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maxence Ferrari
auto_git_info
Commits
378d7190
Commit
378d7190
authored
1 year ago
by
ferrari
Browse files
Options
Downloads
Patches
Plain Diff
Add kwargs arguments
parent
b56c1f82
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+5
-2
5 additions, 2 deletions
README.md
setup.py
+1
-1
1 addition, 1 deletion
setup.py
src/__init__.py
+1
-1
1 addition, 1 deletion
src/__init__.py
src/auto_git_info.py
+10
-5
10 additions, 5 deletions
src/auto_git_info.py
with
17 additions
and
9 deletions
README.md
+
5
−
2
View file @
378d7190
...
...
@@ -32,6 +32,7 @@ The json file created will be:
```
json
{
"script"
:
"/home/xxx/Documents/Python/auto_git_info/test_auto_git.py"
,
"commit"
:
"7ce86099e62e7ffdfe77fbbcafbe48b862c269b9"
,
"branch"
:
"master"
,
"parameters"
:
{
"input"
:
"rnd_input"
,
"output"
:
null
},
"time"
:
"2023-06-23T18:04:30.894271"
}
...
...
@@ -45,6 +46,8 @@ Instead of passing the `Namespace` object from the `ArgumentParser` parser, you
Alternatively, you can pass a dictionary or any serializable object.
You can also use
`None`
if you don't have any arguments.
Additional kwargs can be passed. The kwargs names will be the keys in the json, and their values will be the associated values.
#### path
If you don't want the default path you can use the
`path`
named argument to specify the path to save the info.
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
378d7190
from
setuptools
import
setup
,
find_packages
setup
(
name
=
'
auto_git_info
'
,
version
=
'
1.0
'
,
version
=
'
1.0
.1
'
,
description
=
'
Automatically log your command line arguments and commit sha
'
,
author
=
'
Maxence Ferrari
'
,
py_modules
=
[
'
auto_git_info
'
],
...
...
This diff is collapsed.
Click to expand it.
src/__init__.py
+
1
−
1
View file @
378d7190
__version__
=
1.0
\ No newline at end of file
__version__
=
"
1.0.1
"
This diff is collapsed.
Click to expand it.
src/auto_git_info.py
+
10
−
5
View file @
378d7190
...
...
@@ -7,13 +7,14 @@ import warnings
import
__main__
def
log_info
(
args
,
*
,
path
=
None
):
def
log_info
(
args
,
*
,
path
=
None
,
**
kwargs
):
"""
Create a json file with script, commit, parameters, and time keys.
The commit is the commit sha and script is the main script executed
args: An argparse object, None or any serializable objet
path: Path to the json file. default to
'
run_log/current_time.json
'
**kwargs: Add serializable objet to the json with its kwargs as a key
"""
time
=
datetime
.
datetime
.
now
().
isoformat
()
...
...
@@ -31,13 +32,17 @@ def log_info(args, *, path=None):
with
open
(
path
,
'
w
'
)
as
logfile
:
repo
=
git
.
Repo
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__main__
.
__file__
)),
search_parent_directories
=
True
)
sha
=
repo
.
head
.
object
.
hexsha
branch
=
repo
.
head
.
ref
.
name
changes
=
repo
.
index
.
diff
(
None
)
if
len
(
changes
):
warnings
.
simplefilter
(
'
always
'
,
DeprecationWarning
)
warnings
.
warn
(
f
'
{
[
c
.
a_path
for
c
in
changes
]
}
have differences with current commit
'
,
DeprecationWarning
,
stacklevel
=
2
)
warnings
.
simplefilter
(
'
default
'
,
DeprecationWarning
)
json
.
dump
(
{
'
script
'
:
__main__
.
__file__
,
out
=
{
'
script
'
:
__main__
.
__file__
,
'
commit
'
:
sha
,
'
branch
'
:
branch
,
'
parameters
'
:
args
,
'
time
'
:
time
},
logfile
)
'
time
'
:
time
}
out
.
update
({
k
:
v
for
k
,
v
in
kwargs
.
items
()
if
k
not
in
out
})
json
.
dump
(
out
,
logfile
)
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