Skip to content

Commit

Permalink
adding header keyword COMMIT to keep track of commit hash (closes #155)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmejia committed Sep 30, 2024
1 parent ed2b88b commit 1c0de20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions python/lvmdrp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sdsstools import get_config, get_logger, get_package_version
from tree import Tree
from sdss_access.path import Path
import subprocess


NAME = 'lvmdrp'
Expand Down Expand Up @@ -35,3 +36,14 @@ def setup_paths(release: str = 'sdsswork', replant: bool = False):


__version__ = os.getenv("LVMDRP_VERSION") or get_package_version(path=__file__, package_name=NAME)


# NOTE: taken from https://stackoverflow.com/questions/14989858/get-the-current-git-hash-in-a-python-script
def get_git_revision_hash() -> str:
return subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip()

def get_git_revision_short_hash() -> str:
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip()


DRP_COMMIT = get_git_revision_short_hash()
4 changes: 3 additions & 1 deletion python/lvmdrp/functions/imageMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from typing import List, Tuple

from lvmdrp import log, __version__ as DRPVER
from lvmdrp import log, DRP_COMMIT, __version__ as DRPVER
from lvmdrp.core.constants import CONFIG_PATH, SPEC_CHANNELS, ARC_LAMPS, LVM_REFERENCE_COLUMN, LVM_NBLOCKS, FIDUCIAL_PLATESCALE
from lvmdrp.utils.decorators import skip_on_missing_input_path, drop_missing_input_paths
from lvmdrp.utils.bitmask import QualityFlag
Expand Down Expand Up @@ -3365,6 +3365,8 @@ def preproc_raw_frame(

# set drp tag version
proc_img.setHdrValue("DRPVER", DRPVER, comment='data reduction pipeline software tag')
# set drp commit SHA
proc_img.setHdrValue("COMMIT", DRP_COMMIT, comment="data reduction pipeline commit HASH")

# write out FITS file
log.info(f"writing preprocessed image to {os.path.basename(out_image)}")
Expand Down

0 comments on commit 1c0de20

Please sign in to comment.