diff options
author | Damien George <damien.p.george@gmail.com> | 2020-02-27 15:36:53 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-02-28 10:33:03 +1100 |
commit | 69661f3343bedf86e514337cff63d96cc42f8859 (patch) | |
tree | af5dfb380ffdb75dda84828f63cf9d840d992f0f /py/makeversionhdr.py | |
parent | 3f39d18c2b884d32f0443e2e8114ff9d7a14d718 (diff) | |
download | micropython-69661f3343bedf86e514337cff63d96cc42f8859.tar.gz micropython-69661f3343bedf86e514337cff63d96cc42f8859.zip |
all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
Diffstat (limited to 'py/makeversionhdr.py')
-rw-r--r-- | py/makeversionhdr.py | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/py/makeversionhdr.py b/py/makeversionhdr.py index 2ab99d89b4..567b3b8322 100644 --- a/py/makeversionhdr.py +++ b/py/makeversionhdr.py @@ -11,6 +11,7 @@ import os import datetime import subprocess + def get_version_info_from_git(): # Python 2.6 doesn't have check_output, so check for that try: @@ -21,7 +22,11 @@ def get_version_info_from_git(): # Note: git describe doesn't work if no tag is available try: - git_tag = subprocess.check_output(["git", "describe", "--dirty", "--always"], stderr=subprocess.STDOUT, universal_newlines=True).strip() + git_tag = subprocess.check_output( + ["git", "describe", "--dirty", "--always"], + stderr=subprocess.STDOUT, + universal_newlines=True, + ).strip() except subprocess.CalledProcessError as er: if er.returncode == 128: # git exit code of 128 means no repository found @@ -30,7 +35,11 @@ def get_version_info_from_git(): except OSError: return None try: - git_hash = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"], stderr=subprocess.STDOUT, universal_newlines=True).strip() + git_hash = subprocess.check_output( + ["git", "rev-parse", "--short", "HEAD"], + stderr=subprocess.STDOUT, + universal_newlines=True, + ).strip() except subprocess.CalledProcessError: git_hash = "unknown" except OSError: @@ -38,9 +47,13 @@ def get_version_info_from_git(): try: # Check if there are any modified files. - subprocess.check_call(["git", "diff", "--no-ext-diff", "--quiet", "--exit-code"], stderr=subprocess.STDOUT) + subprocess.check_call( + ["git", "diff", "--no-ext-diff", "--quiet", "--exit-code"], stderr=subprocess.STDOUT + ) # Check if there are any staged files. - subprocess.check_call(["git", "diff-index", "--cached", "--quiet", "HEAD", "--"], stderr=subprocess.STDOUT) + subprocess.check_call( + ["git", "diff-index", "--cached", "--quiet", "HEAD", "--"], stderr=subprocess.STDOUT + ) except subprocess.CalledProcessError: git_hash += "-dirty" except OSError: @@ -48,6 +61,7 @@ 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: for line in f: @@ -57,6 +71,7 @@ def get_version_info_from_docs_conf(): return git_tag, "<no hash>" return None + def make_version_header(filename): # Get version info using git, with fallback to docs/conf.py info = get_version_info_from_git() @@ -71,12 +86,16 @@ def make_version_header(filename): #define MICROPY_GIT_TAG "%s" #define MICROPY_GIT_HASH "%s" #define MICROPY_BUILD_DATE "%s" -""" % (git_tag, git_hash, datetime.date.today().strftime("%Y-%m-%d")) +""" % ( + git_tag, + git_hash, + datetime.date.today().strftime("%Y-%m-%d"), + ) # Check if the file contents changed from last time write_file = True if os.path.isfile(filename): - with open(filename, 'r') as f: + with open(filename, "r") as f: existing_data = f.read() if existing_data == file_data: write_file = False @@ -84,8 +103,9 @@ def make_version_header(filename): # Only write the file if we need to if write_file: print("GEN %s" % filename) - with open(filename, 'w') as f: + with open(filename, "w") as f: f.write(file_data) + if __name__ == "__main__": make_version_header(sys.argv[1]) |