-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bump version files for release (#19)
* Added bump_version.py .bump_version.cfg files
- Loading branch information
1 parent
c6d82ed
commit e1f0e02
Showing
3 changed files
with
94 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[bumpversion] | ||
__version__ = '0.0.4' | ||
commit = True | ||
tag = False | ||
|
||
[bumpversion:file:version.py] |
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
""" | ||
Tool which bumps the version based on the following commandline args: | ||
--dev | ||
--patch | ||
--minor | ||
--major | ||
For more information on the versioning scheme, please refer to: semver.org | ||
""" | ||
import argparse | ||
|
||
|
||
def bump_version(version, bump_type): | ||
if "dev" in version: | ||
main_version, dev_str = version.split('.dev') | ||
dev = int(dev_str) | ||
else: | ||
main_version = version | ||
dev = None | ||
major, minor, patch = [int(x) for x in version.split('.', 2)] # gets "[patch].[dev]" for last str | ||
|
||
major, minor, patch = map(int, main_version.split('.')) | ||
|
||
if bump_type == 'dev': | ||
if dev is not None: | ||
dev = dev + 1 | ||
else: | ||
dev = 0 | ||
elif bump_type == 'patch': | ||
patch += 1 | ||
dev = None | ||
elif bump_type == 'minor': | ||
minor += 1 | ||
patch = 0 | ||
dev = None | ||
elif bump_type == 'major': | ||
major += 1 | ||
minor = 0 | ||
patch = 0 | ||
dev = None | ||
|
||
new_version = f"{major}.{minor}.{patch}" | ||
if dev is not None: | ||
new_version += f".dev{dev}" | ||
|
||
print(f"Bumping a {bump_type} release from {version} to {new_version}") | ||
|
||
return new_version | ||
|
||
def process_file(filename, bump_type): | ||
with open(filename, 'r') as f: | ||
lines = f.readlines() | ||
|
||
with open(filename, 'w') as f: | ||
for line in lines: | ||
if '__version__' in line or 'current_version' in line: | ||
version = line.split(' = ')[1].strip().strip("'") | ||
new_version = bump_version(version, bump_type) | ||
f.write(f"__version__ = '{new_version}'\n") | ||
else: | ||
f.write(line) | ||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser(description="Bump version script.") | ||
parser.add_argument("--dev", action="store_true", help="Bump development version.") | ||
parser.add_argument("--patch", action="store_true", help="Bump patch version.") | ||
parser.add_argument("--minor", action="store_true", help="Bump minor version.") | ||
parser.add_argument("--major", action="store_true", help="Bump major version.") | ||
args = parser.parse_args() | ||
|
||
bump_type = None | ||
if args.dev: | ||
bump_type = 'dev' | ||
elif args.patch: | ||
bump_type = 'patch' | ||
elif args.minor: | ||
bump_type = 'minor' | ||
elif args.major: | ||
bump_type = 'major' | ||
|
||
if bump_type: | ||
# Example files to be processed | ||
files = [".bump_version.cfg", "version.py"] | ||
for file in files: | ||
process_file(file, bump_type) | ||
else: | ||
print("Error: Please specify a bump type. Use -h for help.") |
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,3 +1,3 @@ | ||
__version__='0.0.2' | ||
__version__ = '0.0.4' | ||
|
||
|