|
15 | 15 |
|
16 | 16 | import requests
|
17 | 17 |
|
18 |
| - |
19 |
| -def get_current_version(): |
| 18 | +def get_git_command(command): |
20 | 19 | path = os.getcwd()
|
21 | 20 | procs = subprocess.run(
|
22 |
| - "git describe --tags --exact-match", |
| 21 | + command, |
23 | 22 | stdout=subprocess.PIPE,
|
24 | 23 | stderr=subprocess.PIPE,
|
25 | 24 | cwd=path,
|
26 |
| - shell=True |
27 | 25 | )
|
28 | 26 | if procs.returncode != 0:
|
29 | 27 | return None
|
30 | 28 | return procs.stdout.decode("utf8").strip()
|
31 | 29 |
|
| 30 | +def get_current_version(): |
| 31 | + return get_git_command("git describe --tags --exact-match".split()) |
| 32 | + |
32 | 33 | def date_to_version(tag):
|
33 | 34 | # YYYYMMDD
|
34 | 35 | if re.match('\d\d\d\d\d\d\d\d', tag):
|
@@ -60,11 +61,12 @@ def date_to_version(tag):
|
60 | 61 | # py platform directory
|
61 | 62 | BUNDLE_REQ_DIR = os.path.join(BUNDLE_DIR.format(platform="py"), "requirements")
|
62 | 63 | BUNDLE_ZIP_JSON = os.path.join(BUNDLE_DIR.format(platform="py"), f"{BUNDLE_NAME}.json")
|
63 |
| - |
| 64 | +# where the modules are |
64 | 65 | MODULES_DIR = "libraries"
|
| 66 | +# the base requirement file |
65 | 67 | REQUIREMENTS_FILE = "requirements-modules.txt"
|
66 |
| - |
67 |
| -SET_VERSION = f"__version__ = '{VERSION_NUMBER}'" |
| 68 | +# in-file informations to update (or not) |
| 69 | +SET_VERSION_PATTERN = "\n__version__ = '{}'\n" |
68 | 70 | THIS_REPOSITORY = "https://github.com/Neradoc/Circuitpython_Keyboard_Layouts.git"
|
69 | 71 |
|
70 | 72 | PLATFORMS = ["mpy6", "mpy7"]
|
@@ -98,6 +100,21 @@ def date_to_version(tag):
|
98 | 100 | MPYCROSS = MPYCROSSES[sys.platform]
|
99 | 101 |
|
100 | 102 |
|
| 103 | +def file_version_tag(path): |
| 104 | + hash = get_git_command(["git", "log", "-1", '--pretty=%H', path]) |
| 105 | + #ptag = get_git_command(["git", "describe", "--tags", "--always", hash]) |
| 106 | + #pdate = re.split(r"[~-]", ptag)[0] |
| 107 | + ctag = get_git_command(["git", "describe", "--tags", "--always", "--contains", hash]) |
| 108 | + cdate = re.split(r"[~-]", ctag)[0] |
| 109 | + if "." in cdate: |
| 110 | + ver = cdate |
| 111 | + elif hash.startswith(cdate): |
| 112 | + ver = date_to_version(TAG) |
| 113 | + else: |
| 114 | + ver = date_to_version(cdate[0:8]) |
| 115 | + return ver |
| 116 | + |
| 117 | + |
101 | 118 | def fmt(path, platform="py"):
|
102 | 119 | """shortcut for the py directory"""
|
103 | 120 | return path.format(platform=PLATFORM_NAMES[platform])
|
@@ -141,16 +158,18 @@ def make_bundle_files():
|
141 | 158 | shutil.copytree(MODULES_DIR, fmt(BUNDLE_LIB_DIR))
|
142 | 159 |
|
143 | 160 | # change the version number of all the bundles
|
144 |
| - py_files = os.path.join(fmt(BUNDLE_LIB_DIR), "**", "*.py") |
145 |
| - for module in glob.glob(py_files, recursive=True): |
146 |
| - with open(module, "r") as fp: |
| 161 | + for module_local in list_all_files(MODULES_DIR): |
| 162 | + module_file = os.path.join(fmt(BUNDLE_LIB_DIR), module_local) |
| 163 | + file_tag = file_version_tag(os.path.join(MODULES_DIR, module_local)) |
| 164 | + with open(module_file, "r") as fp: |
147 | 165 | data = fp.read()
|
148 |
| - data = data.replace( |
149 |
| - '\n__version__ = "0.0.0-auto.0"\n', |
150 |
| - f"\n{SET_VERSION}\n", |
151 |
| - ) |
152 |
| - with open(module, "w") as fp: |
153 |
| - fp.write(data) |
| 166 | + if "__version__" in data: |
| 167 | + data = data.replace( |
| 168 | + '\n__version__ = "0.0.0-auto.0"\n', |
| 169 | + SET_VERSION_PATTERN.format(file_tag), |
| 170 | + ) |
| 171 | + with open(module_file, "w") as fp: |
| 172 | + fp.write(data) |
154 | 173 |
|
155 | 174 | # list of the modules
|
156 | 175 | all_modules = [
|
|
0 commit comments