Skip to content

Missing git hash for release versions prints warnings #1068

@NicoWeio

Description

@NicoWeio

I am not entirely sure if this is an error on my side, but when working with a release version of NuRadioMC, I always get a warning due to Git not finding a repository to read a commit hash from.

$ python3
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import NuRadioReco.utilities.version
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
>>>

The relevant call stack in my specific case is

from NuRadioReco.modules.channelBandPassFilter import channelBandPassFilterimport NuRadioReco.framework.eventfrom NuRadioReco.utilities import io_utilities, version

As per #924, the herein-imported version.py tries to read the git hash upon loading.

But if I'm not mistaken, this will never work with a release version – the pip-installed package does not come with a .git directory.

Upon researching this, I also found that some code tries to warn the user if no hash is specified but will never actually do so, as all exceptions are caught before in version.py:

try:
commit_hash = version.get_NuRadioMC_commit_hash()
self.set_parameter(evp.hash_NuRadioMC, commit_hash)
except:
logger.warning("Event is serialized without commit hash!")
self.set_parameter(evp.hash_NuRadioMC, None)

Here are my suggestions of what we could do:

  • check if we are in a release version before trying to access the hash (speedup!)
  • bake in the hash somewhere in the release pipeline
  • silence the error by redirecting Git's stderr

And we should do the following:

  • make the hash parsing more reliable by using the porcelain git rev-parse HEAD command instead of git status
  • fix the defunct warning mentioned above, either by removing or rewriting it

I'll gladly create a PR, but we first need to decide on how we intend to handle the hashes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions