Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions scripts/release_autoversioning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import configparser

def update_version(path, find, replace):
with open(path, 'r') as f:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnicodeDecodeError can occur if the content of the file has characters incompatible with the OS's default encoding. Python uses the OS's default text encoding on the content because encoding is not set. Explained here.

# Get every line
lines = f.readlines()

with open(path, 'w', encoding='utf_8') as f:
for line in lines:
if find in line:
f.write(replace)
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'
update_version_in_files(gnoll_ini_path, setup_cfg_path, project_toml_path)