66import glob
77import json
88import os
9+ import re
910import shutil
1011import stat
1112import subprocess
1819def get_current_version ():
1920 path = os .getcwd ()
2021 procs = subprocess .run (
21- [
22- "git" ,
23- "describe" ,
24- "--tags" ,
25- "--exact-match" ,
26- ],
22+ "git describe --tags --exact-match" ,
2723 stdout = subprocess .PIPE ,
2824 stderr = subprocess .PIPE ,
2925 cwd = path ,
26+ shell = True
3027 )
3128 if procs .returncode != 0 :
3229 return None
3330 return procs .stdout .decode ("utf8" ).strip ()
3431
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
3541
3642# 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)
3746TAG = get_current_version () or datetime .date .today ().strftime ("%Y%m%d" )
47+ VERSION_NUMBER = date_to_version (TAG )
3848# the dirs for putting the things in it
3949BUILD_DIR = "_build"
4050BUILD_DEPS = os .path .join (BUILD_DIR , "deps" )
@@ -54,10 +64,7 @@ def get_current_version():
5464MODULES_DIR = "libraries"
5565REQUIREMENTS_FILE = "requirements-modules.txt"
5666
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 } '"
6168THIS_REPOSITORY = "https://github.com/Neradoc/Circuitpython_Keyboard_Layouts.git"
6269
6370PLATFORMS = ["mpy6" , "mpy7" ]
@@ -133,6 +140,18 @@ def make_bundle_files():
133140 # copy all the layouts and keycodes
134141 shutil .copytree (MODULES_DIR , fmt (BUNDLE_LIB_DIR ))
135142
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+
136155 # list of the modules
137156 all_modules = [
138157 mod .replace (".py" , "" )
0 commit comments