Skip to content
Open
Changes from 4 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
41 changes: 40 additions & 1 deletion invisible_cities/cities/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import warnings
import math
import os
import subprocess
import traceback

from .. dataflow import dataflow as fl
from .. dataflow.dataflow import sink
Expand Down Expand Up @@ -143,7 +145,8 @@ def proxy(**kwds):
args = vars(conf)
result = check_annotations(city_function)(**args)
if os.path.exists(conf.file_out):
write_city_configuration(conf.file_out, city_function.__name__, args)
git_info = add_git_info()
write_city_configuration(conf.file_out, city_function.__name__, {**args, **git_info})
copy_cities_configuration(conf.files_in[0], conf.file_out)
index_tables(conf.file_out)
return result
Expand Down Expand Up @@ -198,6 +201,42 @@ def create_timestamp_(event_number: Union[int, float]) -> float:
return create_timestamp_


def run_git_command(git_command : str,
git_parameter : str = ""):
"""
Runs a git command and stores the output.

Parameters
----------
git_command : the standard terminal git command the user would input
git_parameter (Optional) : a string input to specify what git parameter the user is fetching

Returns
-------
The standard git terminal output
"""
git_command = git_command.split() # turns the string input into a list of strings
try:
git_output = subprocess.run(git_command, text=True, capture_output=True, check=True).stdout.strip()
return git_output
except subprocess.CalledProcessError as e:
print(f"Following error encountered when running: " + ' '.join(git_command))
print(e.stderr)
return None
except Exception as e:
print(traceback.format_exc())


def add_git_info():
git_info = dict(
IC_tag = run_git_command("git describe --tags --exact-match", "git tag"),
upstream_name = run_git_command("git rev-parse --abbrev-ref @{upstream}", "remote upstream").split('/')[0],
branch_name = run_git_command("git branch --show-current", "branch"),
commit_hash = run_git_command("git rev-parse HEAD", "commit hash")
)
return git_info


def index_tables(file_out):
"""
-finds all tables in output_file
Expand Down
Loading