Skip to content

[fix] import if dynamic versioning fails

Alexis GAMELIN requested to merge fix-versioning into develop

Got this error while testing docker image:

(base) dockeruser@27a44d917f6f:~$ python
Python 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:36:13) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from mbtrack2 import *
Traceback (most recent call last):
  File "/home/dockeruser/mbtrack2/__init__.py", line 16, in <module>
    __version__ = subprocess.check_output(
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dockeruser/miniconda3/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dockeruser/miniconda3/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'git --git-dir=/home/dockeruser/.git/ --work-tree=/home/dockeruser describe --long --dirty --abbrev=10 --tags' returned non-zero exit status 128.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dockeruser/mbtrack2/__init__.py", line 31, in <module>
    from ._version import __version__
ModuleNotFoundError: No module named 'mbtrack2._version'
>>> from mbtrack2 import Synchrotron
Traceback (most recent call last):
  File "/home/dockeruser/mbtrack2/__init__.py", line 16, in <module>
    __version__ = subprocess.check_output(
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dockeruser/miniconda3/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dockeruser/miniconda3/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'git --git-dir=/home/dockeruser/.git/ --work-tree=/home/dockeruser describe --long --dirty --abbrev=10 --tags' returned non-zero exit status 128.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dockeruser/mbtrack2/__init__.py", line 31, in <module>
    from ._version import __version__
ModuleNotFoundError: No module named 'mbtrack2._version'

With this fix the static versioning works but I am not sure why the dynamic one fails in the docker image.

Also I think it would be great to print out the branch name if the git tree is dirty

Merge request reports

Loading