Skip to content

Commit

Permalink
Updated the attrs['source'] hash strings:
Browse files Browse the repository at this point in the history
* Now includes the git commit ID in the source string when the repository has uncommitted changes for reference.
* Removed assumptions about relative paths and repository roots in the input file paths. The previous approach assumed the data issues path was already the root, causing the function to fail.
  • Loading branch information
ladsmund committed Aug 23, 2024
1 parent 3813c77 commit 7bf618e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/pypromice/process/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ def __init__(
"""
assert os.path.isfile(config_file), "cannot find " + config_file
assert os.path.isdir(inpath), "cannot find " + inpath
logger.info("AWS object initialising...")
logger.info(
"AWS("
f"config_file={config_file},"
f" inpath={inpath},"
f" data_issues_repository={data_issues_repository},"
f" var_file={var_file},"
f" meta_file={meta_file}"
")"
)

# Load config, variables CSF standards, and L0 files
self.config = self.loadConfig(config_file, inpath)
Expand All @@ -73,6 +81,7 @@ def __init__(
l0_data_root=inpath_hash,
data_issues=data_issues_hash,
)
logger.debug('Source information: %s', source_dict)
self.meta["source"] = json.dumps(source_dict)

# Load config file
Expand Down
14 changes: 8 additions & 6 deletions src/pypromice/utilities/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
logger = logging.getLogger(__name__)


def get_commit_hash_and_check_dirty(file_path) -> str:
repo_path = Path(file_path).parent
def get_commit_hash_and_check_dirty(file_path: str | Path) -> str:
if isinstance(file_path, str):
file_path = Path(file_path)
if file_path.is_dir():
repo_path = file_path
else:
repo_path = file_path.parent

try:
# Ensure the file path is relative to the repository
relative_file_path = os.path.relpath(file_path, repo_path)

# Get the latest commit hash for the file
commit_hash = (
Expand All @@ -25,8 +29,6 @@ def get_commit_hash_and_check_dirty(file_path) -> str:
"-n",
"1",
"--pretty=format:%H",
#"--",
#relative_file_path,
],
stderr=subprocess.STDOUT,
)
Expand All @@ -49,7 +51,7 @@ def get_commit_hash_and_check_dirty(file_path) -> str:

if is_dirty:
logger.warning(f"Warning: The file {file_path} is dirty compared to the last commit. {commit_hash}")
return 'unknown'
return f'{commit_hash} (dirty)'
if commit_hash == "":
logger.warning(f"Warning: The file {file_path} is not under version control.")
return 'unknown'
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/test_get_l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ def test_get_l2_raw(self):
)
data_root_hash = source_decoded["l0_data_root"]
data_issues_hash = source_decoded["data_issues"]
self.assertNotEquals(config_hash, 'unknown', 'This test will fail while the commit is dirty')
self.assertNotEquals(data_root_hash, 'unknown', 'This test will fail while the commit is dirty')
self.assertNotEquals(data_issues_hash, 'unknown', 'This test will fail while the commit is dirty')
self.assertFalse(config_hash.endswith(" (dirty)"), 'This test will fail while the commit is dirty')
self.assertFalse(data_root_hash.endswith(" (dirty)"), 'This test will fail while the commit is dirty')
self.assertFalse(data_issues_hash.endswith(" (dirty)"), 'This test will fail while the commit is dirty')

0 comments on commit 7bf618e

Please sign in to comment.