6
6
import glob
7
7
import json
8
8
import os
9
+ import re
9
10
import shutil
10
11
import stat
11
12
import subprocess
18
19
def get_current_version ():
19
20
path = os .getcwd ()
20
21
procs = subprocess .run (
21
- [
22
- "git" ,
23
- "describe" ,
24
- "--tags" ,
25
- "--exact-match" ,
26
- ],
22
+ "git describe --tags --exact-match" ,
27
23
stdout = subprocess .PIPE ,
28
24
stderr = subprocess .PIPE ,
29
25
cwd = path ,
26
+ shell = True
30
27
)
31
28
if procs .returncode != 0 :
32
29
return None
33
30
return procs .stdout .decode ("utf8" ).strip ()
34
31
32
+ def date_to_version (tag ):
33
+ # YYYYMMDD
34
+ if re .match ('\d\d\d\d\d\d\d\d' , tag ):
35
+ year = int (tag [2 :4 ]) - 20
36
+ month = int (tag [4 :6 ])
37
+ day = int (tag [6 :8 ])
38
+ return f"{ year } .{ month } .{ day } "
39
+ else :
40
+ return tag
35
41
36
42
# the date tag for the generated files and stuff
43
+ # TODO: retrieve the version number from git or something
44
+ # TODO: give each file a different version number possibly
45
+ # (that of the latest released change if possible)
37
46
TAG = get_current_version () or datetime .date .today ().strftime ("%Y%m%d" )
47
+ VERSION_NUMBER = date_to_version (TAG )
38
48
# the dirs for putting the things in it
39
49
BUILD_DIR = "_build"
40
50
BUILD_DEPS = os .path .join (BUILD_DIR , "deps" )
@@ -54,10 +64,7 @@ def get_current_version():
54
64
MODULES_DIR = "libraries"
55
65
REQUIREMENTS_FILE = "requirements-modules.txt"
56
66
57
- # TODO: retrieve the version number from git or something
58
- # TODO: give each file a different version number possibly (that of the latest released change)
59
- # TODO: fill in the repository from git ?
60
- VERSION_NUMBER = "0.0.1"
67
+ SET_VERSION = f"__version__ = '{ VERSION_NUMBER } '"
61
68
THIS_REPOSITORY = "https://github.com/Neradoc/Circuitpython_Keyboard_Layouts.git"
62
69
63
70
PLATFORMS = ["mpy6" , "mpy7" ]
@@ -133,6 +140,18 @@ def make_bundle_files():
133
140
# copy all the layouts and keycodes
134
141
shutil .copytree (MODULES_DIR , fmt (BUNDLE_LIB_DIR ))
135
142
143
+ # 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 :
147
+ 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 )
154
+
136
155
# list of the modules
137
156
all_modules = [
138
157
mod .replace (".py" , "" )
0 commit comments