Skip to content

Commit

Permalink
Update bump_version.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tmart234 authored Oct 30, 2023
1 parent 50d155c commit a38986d
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions .github/bump_version.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
import re
import toml

# Bump version in setup.cfg
def get_version_from_cfg(content):
return re.search(r'version\s*=\s*(.+)', content).group(1)

def bump_version(version_str):
major, minor, patch = map(int, version_str.split('.'))
return f"{major}.{minor}.{patch + 1}"

# Extract version from setup.cfg
with open("setup.cfg", "r") as f:
content = f.read()
cfg_version = get_version_from_cfg(content)

# Extract version from setup.cfg
version = re.search(r'version\s*=\s*(.+)', content).group(1)
major, minor, patch = map(int, version.split("."))
# Extract version from pyproject.toml
with open("pyproject.toml", 'r') as file:
toml_content = toml.load(file)
toml_version = toml_content['project']['version']

# Bump patch version
new_version = f"{major}.{minor}.{patch + 1}"
# Compare versions and pick the higher version
cfg_version_tuple = tuple(map(int, cfg_version.split('.')))
toml_version_tuple = tuple(map(int, toml_version.split('.')))

# Replace in content
updated_content = content.replace(f'version = {version}', f'version = {new_version}')
if cfg_version_tuple > toml_version_tuple:
higher_version = cfg_version
else:
higher_version = toml_version

# Bump the higher version
bumped_version = bump_version(higher_version)

# Update setup.cfg
updated_content = content.replace(f'version = {cfg_version}', f'version = {bumped_version}')
with open("setup.cfg", "w") as f:
f.write(updated_content)

# Bump version in pyproject.toml
def bump_version(version_str):
major, minor, patch = map(int, version_str.split('.'))
return f"{major}.{minor}.{patch + 1}"

with open("pyproject.toml", 'r') as file:
content = toml.load(file)

old_version = content['project']['version']
content['project']['version'] = bump_version(old_version)

# Update pyproject.toml
toml_content['project']['version'] = bumped_version
with open("pyproject.toml", 'w') as file:
toml.dump(content, file)
toml.dump(toml_content, file)

0 comments on commit a38986d

Please sign in to comment.