Skip to content

Commit 947a53c

Browse files
authored
Merge pull request #6033 from jepler/better-describe
Improve use of `git describe`
2 parents feb6533 + 27f2c45 commit 947a53c

File tree

7 files changed

+26
-20
lines changed

7 files changed

+26
-20
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ jobs:
4242
run: python tools/ci_fetch_deps.py test ${{ github.sha }}
4343
- name: CircuitPython version
4444
run: |
45-
git describe --dirty --tags || git log --parents HEAD~4..
46-
echo >>$GITHUB_ENV CP_VERSION=$(git describe --dirty --tags)
45+
tools/describe || git log --parents HEAD~4..
46+
echo >>$GITHUB_ENV CP_VERSION=$(tools/describe)
4747
- name: Install dependencies
4848
run: |
4949
sudo apt-get update
@@ -148,8 +148,8 @@ jobs:
148148
run: python tools/ci_fetch_deps.py mpy-cross-mac ${{ github.sha }}
149149
- name: CircuitPython version
150150
run: |
151-
git describe --dirty --tags
152-
echo >>$GITHUB_ENV CP_VERSION=$(git describe --dirty --tags)
151+
tools/describe || git log --parents HEAD~4..
152+
echo >>$GITHUB_ENV CP_VERSION=$(tools/describe)
153153
- name: Install dependencies
154154
run: |
155155
brew install gettext
@@ -204,8 +204,8 @@ jobs:
204204
run: python tools/ci_fetch_deps.py docs ${{ github.sha }}
205205
- name: CircuitPython version
206206
run: |
207-
git describe --dirty --tags
208-
echo >>$GITHUB_ENV CP_VERSION=$(git describe --dirty --tags)
207+
tools/describe || git log --parents HEAD~4..
208+
echo >>$GITHUB_ENV CP_VERSION=$(tools/describe)
209209
- name: Set up Python 3
210210
uses: actions/setup-python@v2
211211
with:
@@ -379,7 +379,9 @@ jobs:
379379
- name: Get CP deps
380380
run: python tools/ci_fetch_deps.py ${{ matrix.board }} ${{ github.sha }}
381381
- name: CircuitPython version
382-
run: git describe --dirty --tags
382+
run: |
383+
tools/describe || git log --parents HEAD~4..
384+
echo >>$GITHUB_ENV CP_VERSION=$(tools/describe)
383385
- uses: actions/cache@v2
384386
name: Fetch IDF tool cache
385387
id: idf-cache

.github/workflows/create_website_pr.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ jobs:
3434
gcc --version
3535
python3 --version
3636
- name: CircuitPython version
37-
run: git describe --dirty --tags
37+
run: |
38+
tools/describe || git log --parents HEAD~4..
39+
echo >>$GITHUB_ENV CP_VERSION=$(tools/describe)
3840
- name: Website
3941
run: python3 build_board_info.py
4042
working-directory: tools

.github/workflows/ports_windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ jobs:
7777
run: python tools/ci_fetch_deps.py windows ${{ github.sha }}
7878
- name: CircuitPython version
7979
run: |
80-
git describe --dirty --tags
81-
echo >>$GITHUB_ENV CP_VERSION=$(git describe --dirty --tags)
80+
tools/describe || git log --parents HEAD~4..
81+
echo >>$GITHUB_ENV CP_VERSION=$(tools/describe)
8282
8383
- name: build mpy-cross
8484
run: make -j2 -C mpy-cross

conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
import sys
2525
import urllib.parse
2626
import time
27+
import pathlib
2728
from collections import defaultdict
2829

2930
from sphinx.transforms import SphinxTransform
3031
from docutils import nodes
3132
from sphinx import addnodes
3233

34+
tools_describe = str(pathlib.Path(__file__).parent / "tools/describe")
35+
3336
# If extensions (or modules to document with autodoc) are in another directory,
3437
# add these directories to sys.path here. If the directory is relative to the
3538
# documentation root, use os.path.abspath to make it absolute, like shown here.
@@ -129,7 +132,7 @@ def autoapi_prepare_jinja_env(jinja_env):
129132

130133
final_version = ""
131134
git_describe = subprocess.run(
132-
["git", "describe", "--dirty", "--tags"],
135+
[tools_describe],
133136
stdout=subprocess.PIPE,
134137
stderr=subprocess.STDOUT,
135138
encoding="utf-8"

py/makeversionhdr.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
"""
22
Generate header file with macros defining MicroPython version info.
33
4-
This script works with Python 2.6, 2.7, 3.3 and 3.4.
4+
This script works with Python 3.7 and newer
55
"""
66

77
from __future__ import print_function
88

99
import sys
1010
import os
11+
import pathlib
1112
import datetime
1213
import subprocess
1314

15+
tools_describe = str(pathlib.Path(__file__).parent.parent / "tools/describe")
1416

15-
def get_version_info_from_git():
16-
# Python 2.6 doesn't have check_output, so check for that
17-
try:
18-
subprocess.check_output
19-
subprocess.check_call
20-
except AttributeError:
21-
return None
2217

18+
def get_version_info_from_git():
2319
# Note: git describe doesn't work if no tag is available
2420
try:
2521
git_tag = subprocess.check_output(
26-
["git", "describe", "--tags", "--dirty", "--always", "--match", "[1-9].*"],
22+
[tools_describe],
2723
stderr=subprocess.STDOUT,
2824
universal_newlines=True,
2925
).strip()

setup.py-stubs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ setup(
4343
"root": "..",
4444
"relative_to": __file__,
4545
"local_scheme": local_scheme,
46+
"git_describe_command": "tools/describe",
4647
},
4748
zip_safe=False,
4849
)

tools/describe

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
git describe --first-parent --dirty --tags --always --match "[1-9].*"

0 commit comments

Comments
 (0)