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
567c5451
Commit
567c5451
authored
1 year ago
by
ferrari
Browse files
Options
Downloads
Patches
Plain Diff
Add documentation
parent
39534503
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
READLE.md
+51
-0
51 additions, 0 deletions
READLE.md
src/auto_git_info.py
+9
-1
9 additions, 1 deletion
src/auto_git_info.py
with
60 additions
and
1 deletion
READLE.md
0 → 100644
+
51
−
0
View file @
567c5451
Auto Git info
==============
`auto_git_info.py`
is a python module made to save a run parameters and git versions.
It will create a json file with those information.
Installation
------------
To install
`auto_git_info.py`
```
pip install git+https://gitlab.lis-lab.fr/maxence.ferrari/auto_git_info.git
```
To uninstall, just type
`pip uninstall auto_git_info`
Basic usage
-----
```
python
from
auto_git_info
import
log_info
import
argparse
if
__name__
==
'
__main__
'
:
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
input
"
,
type
=
str
,
help
=
"
Input file
"
)
parser
.
add_argument
(
"
--output
"
,
type
=
str
,
default
=
None
,
help
=
"
Output file
"
)
args
=
parser
.
parse_args
()
log_info
(
args
)
```
This will create a json file in
`run_log/`
by default, with the current time as a name.
The json file created will be:
```
json
{
"script"
:
"/home/xxx/Documents/Python/auto_git_info/test_auto_git.py"
,
"commit"
:
"7ce86099e62e7ffdfe77fbbcafbe48b862c269b9"
,
"parameters"
:
{
"input"
:
"rnd_input"
,
"output"
:
null
},
"time"
:
"2023-06-23T18:04:30.894271"
}
```
Advance usage
-------------
#### args
Instead of passing the
`Namespace`
object from the
`ArgumentParser`
parser, you can also directly pass the parser itself.
Alternatively, you can pass a dictionary or any serializable object.
You can also use
`None`
if you don't have any arguments.
#### path
If you don't want the default path you can use the
`path`
named argument to specify the path to save the info.
Any intermediate directories will be created.
This diff is collapsed.
Click to expand it.
src/auto_git_info.py
+
9
−
1
View file @
567c5451
...
@@ -7,7 +7,15 @@ import warnings
...
@@ -7,7 +7,15 @@ import warnings
import
__main__
import
__main__
def
log_info
(
args
,
path
=
None
):
def
log_info
(
args
,
*
,
path
=
None
):
"""
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
'
"""
time
=
datetime
.
datetime
.
now
().
isoformat
()
time
=
datetime
.
datetime
.
now
().
isoformat
()
if
isinstance
(
args
,
argparse
.
Namespace
):
if
isinstance
(
args
,
argparse
.
Namespace
):
args
=
args
.
__dict__
args
=
args
.
__dict__
...
...
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