0

I have some code that runs simulations and saves the results into text files.

To ensure reproducibility, I was also saving the git hash of the last commit , so that if I look a simulation several months later I can know exactly which commit was used to produce the result.

Now we are looking into making our code conda-installable. I know I can access the git hast in the conda recipe by using the {{ GIT_FULL_HASH }} env variable; and save it in the about section of my meta.yaml:

about:
  summary: data['description']
  description: data['long_description']
  githash: {{ GIT_FULL_HASH }}

is there a way I can access its value programmatically after the package has been built and installed, so that I can include it on the saved sim data?

Javier
  • 672
  • 4
  • 14
  • IMO the best way is to include it in the package code itself - when you build the package, store the git hash in a variable in `__init__.py` so you can access it `import foo; foo.__git_hash__`. That way, you don't have to worry about different build systems, etc. – darthbith Sep 10 '18 at 15:33
  • If I modify the source code, the git status will change, unless the file where I save the git hash is not kept under version control. But in that case it doesn't get downloaded, so adding the githash must happen after conda dowloads the source. My build script is the usual `python -m pip install ...`, how would you add the variable to the `__init__` file before running that, but after conda downloads the source? – Javier Sep 10 '18 at 16:00
  • 1
    You can add it in the `setup.py` which is just a normal Python script where you call the special `setup` function – darthbith Sep 10 '18 at 19:18
  • That's a great suggestion, thanks! I think I will save it on a separate file rather than `__init__.py` though, as the idea of the build script changing the source makes me cringe a little bit ;-) – Javier Sep 11 '18 at 10:58
  • Sure, then you can just import that extra file from the __init__.py script. You can put it in a `try...except` block in case the file isn't present during testing, etc. – darthbith Sep 11 '18 at 15:42

0 Answers0