Skip to content
Snippets Groups Projects
Commit 8044145d authored by AxelCarayon's avatar AxelCarayon
Browse files

vérification que seul des inputs/outputs ont été générés

parent 8a5e08e5
Branches verifiChangements
No related tags found
1 merge request!14Verifi changements
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)
...@@ -130,15 +131,21 @@ def runExperiment() -> None: ...@@ -130,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})
...@@ -149,7 +156,7 @@ def writeInYaml() -> None: ...@@ -149,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) -> Boolean : def successfullyCreatedNewBranch(name) -> bool :
try: try:
repository.git.checkout('-b',name) repository.git.checkout('-b',name)
return True return True
...@@ -180,11 +187,9 @@ def genChecksum(file) -> str : ...@@ -180,11 +187,9 @@ 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 :
init(folder) init(folder)
repository.active_branch.checkout() repository.active_branch.checkout()
...@@ -199,5 +204,6 @@ def run(folder) -> None : ...@@ -199,5 +204,6 @@ def run(folder) -> None :
captureExperiment() captureExperiment()
scanInputFiles() scanInputFiles()
scanOutputsGenerated() scanOutputsGenerated()
checkGeneratedFiles()
writeInYaml() writeInYaml()
pushBranch() pushBranch()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment