Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove "scripts." in snakefile #926

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading