Skip to content

Commit 415d7bc

Browse files
committed
add date-based version to modules
1 parent 28d670b commit 415d7bc

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

build.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import glob
77
import json
88
import os
9+
import re
910
import shutil
1011
import stat
1112
import subprocess
@@ -18,23 +19,32 @@
1819
def 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)
3746
TAG = 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
3949
BUILD_DIR = "_build"
4050
BUILD_DEPS = os.path.join(BUILD_DIR, "deps")
@@ -54,10 +64,7 @@ def get_current_version():
5464
MODULES_DIR = "libraries"
5565
REQUIREMENTS_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}'"
6168
THIS_REPOSITORY = "https://github.com/Neradoc/Circuitpython_Keyboard_Layouts.git"
6269

6370
PLATFORMS = ["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", "")

libraries/keyboard_layout.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"""
1111

1212

13+
__version__ = "0.0.0-auto.0"
14+
__repo__ = "https://github.com/Neradoc/Circuitpython_Keyboard_Layouts.git"
15+
16+
1317
class KeyboardLayout:
1418
"""Map ASCII characters to appropriate keypresses on a standard US PC keyboard.
1519

libraries/keyboard_layout_us_dvo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from keyboard_layout import KeyboardLayout
22

3+
34
__version__ = "0.0.0-auto.0"
45
__repo__ = "https://github.com/Neradoc/Circuitpython_Keyboard_Layouts.git"
56

libraries/keycode_mac_fr.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
"""
3030

3131

32+
__version__ = "0.0.0-auto.0"
33+
__repo__ = "https://github.com/Neradoc/Circuitpython_Keyboard_Layouts.git"
34+
35+
3236
class Keycode:
3337
"""USB HID Keycode constants.
3438
This list is modeled after the names for USB keycodes defined in

0 commit comments

Comments
 (0)