Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
reproductionTool
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMAC
Reproductibilité des recherches dans SMAC
reproductionTool
Commits
38a3c7da
Unverified
Commit
38a3c7da
authored
3 years ago
by
AxelCarayon
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #14 from AxelCarayon/verifiChangements
Verifi changements
parents
6e420166
8044145d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
registerExperiment.py
+25
-8
25 additions, 8 deletions
registerExperiment.py
with
25 additions
and
8 deletions
registerExperiment.py
+
25
−
8
View file @
38a3c7da
from
cmath
import
e
import
os
import
os
import
re
from
xmlrpc.client
import
Boolean
import
git
import
git
import
subprocess
import
subprocess
import
yaml
import
yaml
import
hashlib
import
hashlib
import
collections
EXPERIMENT_RESUME
=
"
experimentResume.yaml
"
path
=
"
./
"
path
=
"
./
"
...
@@ -26,6 +26,7 @@ outputFiles = []
...
@@ -26,6 +26,7 @@ outputFiles = []
currentTag
=
None
currentTag
=
None
tags
=
None
tags
=
None
def
isGitRepo
(
path
)
->
bool
:
def
isGitRepo
(
path
)
->
bool
:
try
:
try
:
git
.
Repo
(
path
)
git
.
Repo
(
path
)
...
@@ -33,6 +34,14 @@ def isGitRepo(path) -> bool:
...
@@ -33,6 +34,14 @@ def isGitRepo(path) -> bool:
except
git
.
exc
.
InvalidGitRepositoryError
:
except
git
.
exc
.
InvalidGitRepositoryError
:
return
False
return
False
def
checkForChanges
()
->
None
:
changesNotAdded
=
[
item
.
a_path
for
item
in
repository
.
index
.
diff
(
None
)
]
changesAdded
=
[
item
.
a_path
for
item
in
repository
.
index
.
diff
(
repository
.
head
.
name
)
]
untrackedFiles
=
repository
.
untracked_files
if
((
len
(
changesNotAdded
)
+
len
(
changesAdded
)
+
len
(
untrackedFiles
))
>
0
):
raise
Exception
(
"
There are changes in the repository since the last commit, you can only register an experiment from a clean repository.
"
)
def
init
(
pathInput
)
->
None
:
def
init
(
pathInput
)
->
None
:
global
repository
,
path
,
experimentName
,
tags
,
currentTag
global
repository
,
path
,
experimentName
,
tags
,
currentTag
if
isGitRepo
(
pathInput
):
if
isGitRepo
(
pathInput
):
...
@@ -44,6 +53,7 @@ def init(pathInput) -> None :
...
@@ -44,6 +53,7 @@ def init(pathInput) -> None :
os
.
chdir
(
path
)
os
.
chdir
(
path
)
else
:
else
:
raise
Exception
(
f
"
{
pathInput
}
is not a git repository
"
)
raise
Exception
(
f
"
{
pathInput
}
is not a git repository
"
)
checkForChanges
()
tags
=
repository
.
tags
tags
=
repository
.
tags
currentTag
=
repository
.
git
.
describe
(
'
--tags
'
)
currentTag
=
repository
.
git
.
describe
(
'
--tags
'
)
if
not
(
currentVersionIsTagged
()):
if
not
(
currentVersionIsTagged
()):
...
@@ -121,15 +131,21 @@ def runExperiment() -> None:
...
@@ -121,15 +131,21 @@ def runExperiment() -> None:
def
scanInputFiles
()
->
None
:
def
scanInputFiles
()
->
None
:
for
file
in
os
.
listdir
(
inputFolder
):
for
file
in
os
.
listdir
(
inputFolder
):
if
not
file
.
endswith
(
"
.gitkeep
"
):
if
not
file
.
endswith
(
"
.gitkeep
"
):
inputFiles
.
append
(
file
)
inputFiles
.
append
(
f
"
{
inputFolder
}{
file
}
"
)
def
scanOutputsGenerated
()
->
None
:
def
scanOutputsGenerated
()
->
None
:
for
file
in
os
.
listdir
(
outputFolder
):
for
file
in
os
.
listdir
(
outputFolder
):
if
not
file
.
endswith
(
"
.gitkeep
"
):
if
not
file
.
endswith
(
"
.gitkeep
"
):
outputFiles
.
append
(
file
)
outputFiles
.
append
(
f
"
{
outputFolder
}{
file
}
"
)
def
checkGeneratedFiles
()
->
None
:
changesNotAdded
=
[
item
.
a_path
for
item
in
repository
.
index
.
diff
(
None
)
]
untrackedFiles
=
repository
.
untracked_files
if
collections
.
Counter
(
outputFiles
+
inputFiles
)
!=
collections
.
Counter
(
untrackedFiles
+
changesNotAdded
):
raise
Exception
(
"
There were files generated or modified outside the input and output folders
"
)
def
writeInYaml
()
->
None
:
def
writeInYaml
()
->
None
:
with
open
(
"
experimentResume.yaml
"
,
"
r
"
)
as
yamlFile
:
with
open
(
EXPERIMENT_RESUME
,
"
r
"
)
as
yamlFile
:
cur_yaml
=
yaml
.
safe_load
(
yamlFile
)
cur_yaml
=
yaml
.
safe_load
(
yamlFile
)
cur_yaml
.
update
({
"
name
"
:
experimentName
})
cur_yaml
.
update
({
"
name
"
:
experimentName
})
cur_yaml
.
update
({
"
commands
"
:
commandsFile
})
cur_yaml
.
update
({
"
commands
"
:
commandsFile
})
...
@@ -140,7 +156,7 @@ def writeInYaml() -> None:
...
@@ -140,7 +156,7 @@ def writeInYaml() -> None:
with
open
(
'
experimentResume.yaml
'
,
'
w
'
)
as
yamlFile
:
with
open
(
'
experimentResume.yaml
'
,
'
w
'
)
as
yamlFile
:
yaml
.
safe_dump
(
cur_yaml
,
yamlFile
)
yaml
.
safe_dump
(
cur_yaml
,
yamlFile
)
def
successfullyCreatedNewBranch
(
name
)
->
B
ool
ean
:
def
successfullyCreatedNewBranch
(
name
)
->
b
ool
:
try
:
try
:
repository
.
git
.
checkout
(
'
-b
'
,
name
)
repository
.
git
.
checkout
(
'
-b
'
,
name
)
return
True
return
True
...
@@ -171,7 +187,7 @@ def genChecksum(file) -> str :
...
@@ -171,7 +187,7 @@ def genChecksum(file) -> str :
def
genChecksums
()
->
list
[
dict
]:
def
genChecksums
()
->
list
[
dict
]:
checksums
=
[]
checksums
=
[]
for
file
in
outputFiles
:
for
file
in
outputFiles
:
checksums
.
append
({
file
:
genChecksum
(
outputFolder
+
file
)})
checksums
.
append
({
file
:
genChecksum
(
file
)})
return
checksums
return
checksums
def
run
(
folder
)
->
None
:
def
run
(
folder
)
->
None
:
...
@@ -188,5 +204,6 @@ def run(folder) -> None :
...
@@ -188,5 +204,6 @@ def run(folder) -> None :
captureExperiment
()
captureExperiment
()
scanInputFiles
()
scanInputFiles
()
scanOutputsGenerated
()
scanOutputsGenerated
()
checkGeneratedFiles
()
writeInYaml
()
writeInYaml
()
pushBranch
()
pushBranch
()
\ No newline at end of file
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