From e56e773f4247e6f75dc84bb45e260dab45d3e243 Mon Sep 17 00:00:00 2001 From: Ian Hunter Date: Thu, 9 May 2024 09:07:08 +0100 Subject: [PATCH 1/4] Create release_autoversioning.py Signed-off-by: Ian Hunter --- scripts/release_autoversioning.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scripts/release_autoversioning.py diff --git a/scripts/release_autoversioning.py b/scripts/release_autoversioning.py new file mode 100644 index 000000000..66167fc93 --- /dev/null +++ b/scripts/release_autoversioning.py @@ -0,0 +1,22 @@ +import configparser + +def update_version_in_setup_cfg(gnoll_ini_path, setup_cfg_path): + # Read version from GNOLL.ini + config = configparser.ConfigParser() + config.read(gnoll_ini_path) + version = config['Meta Information']['version'] + + # Update version in setup.cfg + with open(setup_cfg_path, 'r') as f: + lines = f.readlines() + + with open(setup_cfg_path, 'w') as f: + for line in lines: + if line.startswith('version ='): + f.write(f'version = {version}\n') + else: + f.write(line) + +gnoll_ini_path = 'GNOLL.ini' +setup_cfg_path = 'src/python/setup.cfg' +update_version_in_setup_cfg(gnoll_ini_path, setup_cfg_path) From 3a155fbb6cd05d3a1af6c29265b95ed98a33d375 Mon Sep 17 00:00:00 2001 From: Ian Hunter Date: Thu, 9 May 2024 09:10:08 +0100 Subject: [PATCH 2/4] Update release_autoversioning.py Signed-off-by: Ian Hunter --- scripts/release_autoversioning.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/release_autoversioning.py b/scripts/release_autoversioning.py index 66167fc93..1ac36252f 100644 --- a/scripts/release_autoversioning.py +++ b/scripts/release_autoversioning.py @@ -1,6 +1,7 @@ + import configparser -def update_version_in_setup_cfg(gnoll_ini_path, setup_cfg_path): +def update_version_in_files(gnoll_ini_path, setup_cfg_path, project_toml_path): # Read version from GNOLL.ini config = configparser.ConfigParser() config.read(gnoll_ini_path) @@ -17,6 +18,18 @@ def update_version_in_setup_cfg(gnoll_ini_path, setup_cfg_path): else: f.write(line) + # Update version in Project.toml + with open(project_toml_path, 'r') as f: + lines = f.readlines() + + with open(project_toml_path, 'w') as f: + for line in lines: + if line.startswith('version ='): + f.write(f'version = "{version}"\n') + else: + f.write(line) + gnoll_ini_path = 'GNOLL.ini' setup_cfg_path = 'src/python/setup.cfg' -update_version_in_setup_cfg(gnoll_ini_path, setup_cfg_path) +project_toml_path = 'GNOLL/src/julia/GNOLL/Project.toml' +update_version_in_files(gnoll_ini_path, setup_cfg_path, project_toml_path) From 438b45af2132924f5f84608633f2d74eb0e597a1 Mon Sep 17 00:00:00 2001 From: Ian Hunter Date: Thu, 9 May 2024 09:33:06 +0100 Subject: [PATCH 3/4] Update scripts/release_autoversioning.py Co-authored-by: code-review-doctor[bot] <72320148+code-review-doctor[bot]@users.noreply.github.com> Signed-off-by: Ian Hunter --- scripts/release_autoversioning.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release_autoversioning.py b/scripts/release_autoversioning.py index 1ac36252f..8ecdfb907 100644 --- a/scripts/release_autoversioning.py +++ b/scripts/release_autoversioning.py @@ -22,7 +22,7 @@ def update_version_in_files(gnoll_ini_path, setup_cfg_path, project_toml_path): with open(project_toml_path, 'r') as f: lines = f.readlines() - with open(project_toml_path, 'w') as f: + with open(project_toml_path, 'w', encoding='utf_8') as f: for line in lines: if line.startswith('version ='): f.write(f'version = "{version}"\n') From 95ed543f2973266d2f2e885788f33b157818923b Mon Sep 17 00:00:00 2001 From: Ian Hunter Date: Thu, 9 May 2024 09:50:14 +0100 Subject: [PATCH 4/4] Update release_autoversioning.py Signed-off-by: Ian Hunter --- scripts/release_autoversioning.py | 39 ++++++++++++++----------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/scripts/release_autoversioning.py b/scripts/release_autoversioning.py index 8ecdfb907..5eccad65d 100644 --- a/scripts/release_autoversioning.py +++ b/scripts/release_autoversioning.py @@ -1,34 +1,29 @@ - import configparser -def update_version_in_files(gnoll_ini_path, setup_cfg_path, project_toml_path): - # Read version from GNOLL.ini - config = configparser.ConfigParser() - config.read(gnoll_ini_path) - version = config['Meta Information']['version'] - - # Update version in setup.cfg - with open(setup_cfg_path, 'r') as f: +def update_version(path, find, replace): + with open(path, 'r') as f: + # Get every line lines = f.readlines() - - with open(setup_cfg_path, 'w') as f: + + with open(path, 'w', encoding='utf_8') as f: for line in lines: - if line.startswith('version ='): - f.write(f'version = {version}\n') + if find in line: + f.write(replace) else: f.write(line) - # Update version in Project.toml - with open(project_toml_path, 'r') as f: - lines = f.readlines() - with open(project_toml_path, 'w', encoding='utf_8') as f: - for line in lines: - if line.startswith('version ='): - f.write(f'version = "{version}"\n') - else: - f.write(line) +def update_version_in_files(gnoll_ini_path, setup_cfg_path, project_toml_path): + # Read version from GNOLL.ini + config = configparser.ConfigParser() + config.read(gnoll_ini_path) + version = config['Meta Information']['version'] + update_version(setup_cfg_path, 'version =', f'version = "{version}"\n') + update_version(project_toml_path, 'version =', f'version = "{version}"\n') + update_version("src/grammar/dice.yacc", 'printf("GNOLL', f'printf("GNOLL {version}")\n') + + gnoll_ini_path = 'GNOLL.ini' setup_cfg_path = 'src/python/setup.cfg' project_toml_path = 'GNOLL/src/julia/GNOLL/Project.toml'