-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |