Skip to content

Commit

Permalink
py/makeversionhdr: Fall back to py/mpconfig.h instead of docs/conf.py.
Browse files Browse the repository at this point in the history
Commit 64af916 removed the version string
from docs/conf.py.  py/mpconfig.h is a better place to get the version
from, so use that (when there is no git repository).

Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Oct 27, 2022
1 parent 11910e2 commit c138e10
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions py/makeversionhdr.py
Expand Up @@ -62,21 +62,27 @@ def get_version_info_from_git():
return git_tag, git_hash


def get_version_info_from_docs_conf():
with open(os.path.join(os.path.dirname(sys.argv[0]), "..", "docs", "conf.py")) as f:
def get_version_info_from_mpconfig():
with open(os.path.join(os.path.dirname(sys.argv[0]), "..", "py", "mpconfig.h")) as f:
for line in f:
if line.startswith("version = release = '"):
ver = line.strip().split(" = ")[2].strip("'")
git_tag = "v" + ver
if line.startswith("#define MICROPY_VERSION_MAJOR "):
ver_major = int(line.strip().split()[2])
elif line.startswith("#define MICROPY_VERSION_MINOR "):
ver_minor = int(line.strip().split()[2])
elif line.startswith("#define MICROPY_VERSION_MICRO "):
ver_micro = int(line.strip().split()[2])
git_tag = "v%d.%d" % (ver_major, ver_minor)
if ver_micro != 0:
git_tag += ".%d" % (ver_micro,)
return git_tag, "<no hash>"
return None


def make_version_header(filename):
# Get version info using git, with fallback to docs/conf.py
# Get version info using git, with fallback to py/mpconfig.h
info = get_version_info_from_git()
if info is None:
info = get_version_info_from_docs_conf()
info = get_version_info_from_mpconfig()

git_tag, git_hash = info

Expand Down

0 comments on commit c138e10

Please sign in to comment.