Rely on git archive "export-subst" git attribute. See 'man gitattributes' for more details. Note: describe is only supported with git >= 2.32.0, and the `tags=true` option with git >= 2.35.0 but we use it to workaround GH#3121.
()
| 46 | |
| 47 | |
| 48 | def _version_from_git_archive(): |
| 49 | # type: () -> str |
| 50 | """ |
| 51 | Rely on git archive "export-subst" git attribute. |
| 52 | See 'man gitattributes' for more details. |
| 53 | Note: describe is only supported with git >= 2.32.0, |
| 54 | and the `tags=true` option with git >= 2.35.0 but we |
| 55 | use it to workaround GH#3121. |
| 56 | """ |
| 57 | git_archive_id = '$Format:%ct %(describe:tags=true)$'.split() |
| 58 | tstamp = git_archive_id[0] |
| 59 | if len(git_archive_id) > 1: |
| 60 | tag = git_archive_id[1] |
| 61 | else: |
| 62 | # project is run in CI and has another %(describe) |
| 63 | tag = "" |
| 64 | |
| 65 | if "Format" in tstamp: |
| 66 | raise ValueError('not a git archive') |
| 67 | |
| 68 | if "describe" in tag: |
| 69 | # git is too old! |
| 70 | tag = "" |
| 71 | if tag: |
| 72 | # archived revision is tagged, use the tag |
| 73 | return _parse_tag(tag) |
| 74 | elif tstamp: |
| 75 | # archived revision is not tagged, use the commit date |
| 76 | d = datetime.datetime.fromtimestamp(int(tstamp), datetime.timezone.utc) |
| 77 | return d.strftime('%Y.%m.%d') |
| 78 | |
| 79 | raise ValueError("invalid git archive format") |
| 80 | |
| 81 | |
| 82 | def _version_from_git_describe(): |
no test coverage detected
searching dependent graphs…