Skip to content

Commit

Permalink
feat: remove "scripts." in snakefile (#926)
Browse files Browse the repository at this point in the history
* feat: remove "scripts." in snakefile

* feat: adjust get_last_commit_message()

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
doneachh and pre-commit-ci[bot] authored Nov 29, 2023
1 parent 5f77c98 commit 35ada5e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
10 changes: 5 additions & 5 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"])
Expand Down Expand Up @@ -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
Expand Down
28 changes: 18 additions & 10 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,21 +816,29 @@ 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

0 comments on commit 35ada5e

Please sign in to comment.