From 726c01050f32231adf647d84d537be8ad77be1d4 Mon Sep 17 00:00:00 2001 From: "anton.achhammer" Date: Tue, 28 Nov 2023 10:59:02 +0100 Subject: [PATCH 1/3] feat: remove "scripts." in snakefile --- Snakefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Snakefile b/Snakefile index 24899f6b6..0cd9d698b 100644 --- a/Snakefile +++ b/Snakefile @@ -11,9 +11,9 @@ from shutil import copyfile, move from snakemake.remote.HTTP import RemoteProvider as HTTPRemoteProvider -from scripts._helpers import create_country_list, get_last_commit_message -from scripts.build_demand_profiles import get_load_paths_gegis -from scripts.retrieve_databundle_light import datafiles_retrivedatabundle +from _helpers import create_country_list, get_last_commit_message +from build_demand_profiles import get_load_paths_gegis +from retrieve_databundle_light import datafiles_retrivedatabundle from pathlib import Path HTTP = HTTPRemoteProvider() From bec488ee254f2c7aca09ab0c887c56f2407a1f87 Mon Sep 17 00:00:00 2001 From: "anton.achhammer" Date: Wed, 29 Nov 2023 10:16:01 +0100 Subject: [PATCH 2/3] feat: adjust get_last_commit_message() --- Snakefile | 4 ++-- scripts/_helpers.py | 29 ++++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Snakefile b/Snakefile index 0cd9d698b..e2b0b27c9 100644 --- a/Snakefile +++ b/Snakefile @@ -28,7 +28,7 @@ if "config" not in globals() or not config: # skip when used as sub-workflow configfile: "configs/bundle_config.yaml" -config.update({"git_commit": get_last_commit_message()}) +config.update({"git_commit": get_last_commit_message(".")}) # convert country list according to the desired region config["countries"] = create_country_list(config["countries"]) @@ -1043,7 +1043,7 @@ rule run_scenario: resources: mem_mb=5000, run: - from scripts.build_test_configs import create_test_config + from build_test_configs import create_test_config import yaml # get base configuration file from diff config diff --git a/scripts/_helpers.py b/scripts/_helpers.py index ea98d629b..b6b3ad821 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -816,21 +816,28 @@ def filter_codes(c_list, iso_coding=True): return full_codes_list -def get_last_commit_message(): +def get_last_commit_message(path): """ - Function to get the last Git commit message. - + Function to get the last PyPSA-Earth Git commit message Returns ------- result : string """ + _logger = logging.getLogger(__name__) + last_commit_message = None + backup_cwd = os.getcwd() try: - result = subprocess.run( - ["git", "log", "-1", "--pretty=format:%H %s"], - capture_output=True, - text=True, + os.chdir(path) + last_commit_message = ( + subprocess.check_output( + ["git", "log", "-n", "1", "--pretty=format:%H %s"], + stderr=subprocess.STDOUT, + ) + .decode() + .strip() ) - return result.stdout.strip() - except Exception as e: - logger.warning(f"Error getting the last commit message: {e}") - return "" + except subprocess.CalledProcessError as e: + _logger.warning(f"Error executing Git: {e}") + + os.chdir(backup_cwd) + return last_commit_message From fc9bef8c3d7bb31e81168103c2ff3ed7d61c5aa1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:16:27 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/_helpers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/_helpers.py b/scripts/_helpers.py index b6b3ad821..b3bb8e90f 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -818,7 +818,8 @@ def filter_codes(c_list, iso_coding=True): def get_last_commit_message(path): """ - Function to get the last PyPSA-Earth Git commit message + Function to get the last PyPSA-Earth Git commit message. + Returns ------- result : string