From 8a5e08e56846e5b0d4980a2a6c655f2252d5535b Mon Sep 17 00:00:00 2001 From: AxelCarayon <axel.carayon@gmail.com> Date: Wed, 19 Jan 2022 14:55:43 +0100 Subject: [PATCH 1/2] =?UTF-8?q?ajout=20v=C3=A9rif=20si=20changements=20?= =?UTF-8?q?=C3=A0=20l'initialisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- registerExperiment.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/registerExperiment.py b/registerExperiment.py index 9b6cf87..ab38a0d 100644 --- a/registerExperiment.py +++ b/registerExperiment.py @@ -33,6 +33,14 @@ def isGitRepo(path) -> bool: except git.exc.InvalidGitRepositoryError: 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 : global repository,path,experimentName,tags, currentTag if isGitRepo(pathInput): @@ -44,6 +52,7 @@ def init(pathInput) -> None : os.chdir(path) else : raise Exception(f"{pathInput} is not a git repository") + checkForChanges() tags = repository.tags currentTag = repository.git.describe('--tags') if not(currentVersionIsTagged()): @@ -174,6 +183,8 @@ def genChecksums() -> list[dict]: checksums.append({file : genChecksum(outputFolder+file)}) return checksums + + def run(folder) -> None : init(folder) repository.active_branch.checkout() -- GitLab From 8044145d169d2de7e86cbd7e00716020caeed17c Mon Sep 17 00:00:00 2001 From: AxelCarayon <axel.carayon@gmail.com> Date: Wed, 19 Jan 2022 17:46:03 +0100 Subject: [PATCH 2/2] =?UTF-8?q?v=C3=A9rification=20que=20seul=20des=20inpu?= =?UTF-8?q?ts/outputs=20ont=20=C3=A9t=C3=A9=20g=C3=A9n=C3=A9r=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- registerExperiment.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/registerExperiment.py b/registerExperiment.py index ab38a0d..398769d 100644 --- a/registerExperiment.py +++ b/registerExperiment.py @@ -1,11 +1,11 @@ -from cmath import e import os -import re -from xmlrpc.client import Boolean import git import subprocess import yaml import hashlib +import collections + +EXPERIMENT_RESUME = "experimentResume.yaml" path = "./" @@ -26,6 +26,7 @@ outputFiles = [] currentTag = None tags = None + def isGitRepo(path) -> bool: try: git.Repo(path) @@ -130,15 +131,21 @@ def runExperiment() -> None: def scanInputFiles() -> None: for file in os.listdir(inputFolder): if not file.endswith(".gitkeep"): - inputFiles.append(file) + inputFiles.append(f"{inputFolder}{file}") def scanOutputsGenerated() -> None: for file in os.listdir(outputFolder): 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: - with open("experimentResume.yaml", "r") as yamlFile: + with open(EXPERIMENT_RESUME, "r") as yamlFile: cur_yaml = yaml.safe_load(yamlFile) cur_yaml.update({"name":experimentName}) cur_yaml.update({"commands":commandsFile}) @@ -149,7 +156,7 @@ def writeInYaml() -> None: with open('experimentResume.yaml', 'w') as yamlFile: yaml.safe_dump(cur_yaml, yamlFile) -def successfullyCreatedNewBranch(name) -> Boolean : +def successfullyCreatedNewBranch(name) -> bool : try: repository.git.checkout('-b',name) return True @@ -180,11 +187,9 @@ def genChecksum(file) -> str : def genChecksums() -> list[dict]: checksums = [] for file in outputFiles: - checksums.append({file : genChecksum(outputFolder+file)}) + checksums.append({file : genChecksum(file)}) return checksums - - def run(folder) -> None : init(folder) repository.active_branch.checkout() @@ -199,5 +204,6 @@ def run(folder) -> None : captureExperiment() scanInputFiles() scanOutputsGenerated() + checkGeneratedFiles() writeInYaml() pushBranch() \ No newline at end of file -- GitLab