forked from c4urself/bump2version
-
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
0 parents
commit db5aa7b
Showing
7 changed files
with
149 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.tox | ||
_test_run/ | ||
bin/ | ||
include/ | ||
lib/ | ||
.Python |
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 @@ | ||
include README.rst |
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,17 @@ | ||
=========== | ||
bumpversion | ||
=========== | ||
|
||
.. image:: https://travis-ci.org/peritus/bumpversion.png?branch=master | ||
:target: https://travis-ci.org/peritus/bumpversion | ||
|
||
Version-bump your software with a single command | ||
|
||
Usage | ||
===== | ||
|
||
This replaces the string ``1.2.0`` in file setup.py with ``1.2.1``:: | ||
|
||
bumpversion --old-version 1.2.0 --new-version 1.2.1 setup.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,51 @@ | ||
|
||
import ConfigParser | ||
import argparse | ||
import os.path | ||
|
||
def main(args=None): | ||
|
||
parser = argparse.ArgumentParser(description='Bumps version strings') | ||
|
||
parser.add_argument('--config-file', default='.bumpversion.cfg', metavar='FILE', | ||
help='Config file to read most of the variables from', required=False) | ||
|
||
known_args, remaining_argv = parser.parse_known_args(args) | ||
|
||
defaults = {} | ||
if known_args.config_file and os.path.exists(known_args.config_file): | ||
config = ConfigParser.SafeConfigParser() | ||
config.read([known_args.config_file]) | ||
defaults = dict(config.items("bumpversion")) | ||
defaults['files'] = defaults['files'].split(" ") | ||
print defaults | ||
|
||
parser.set_defaults(**defaults) | ||
|
||
parser.add_argument('--old-version', metavar='VERSION', | ||
help='Version that needs to be updated') | ||
parser.add_argument('--new-version', metavar='VERSION', | ||
help='New version that should be in the files') | ||
|
||
parser.add_argument('files', metavar='file', nargs='*', | ||
help='Files to change') | ||
|
||
print defaults, remaining_argv | ||
|
||
args = parser.parse_args(remaining_argv) | ||
|
||
do_it(args.old_version, args.new_version, args.files) | ||
|
||
def do_it(old_version, new_version, files): | ||
for path in files: | ||
with open(path, 'r') as f: | ||
before = f.read() | ||
|
||
assert old_version in before, 'Did not find string {} in file {}'.format( | ||
old_version, path) | ||
|
||
after = before.replace(old_version, new_version) | ||
|
||
with open(path, 'w') as f: | ||
f.write(after) | ||
|
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,24 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
name='bumpversion', | ||
version='0.0.1', | ||
url='https://github.com/peritus/bumpversion', | ||
author='Filip Noetzel', | ||
author_email='[email protected]', | ||
license='', | ||
packages=['bumpversion'], | ||
description='Version-bump your software with a single command', | ||
long_description=open('README.rst', 'r').read(), | ||
entry_points={ | ||
'console_scripts': [ | ||
'bumpversion = bumpversion:main', | ||
] | ||
}, | ||
classifiers=( | ||
'Development Status :: 3 - Alpha', | ||
'Intended Audience :: Developers', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 2.7', | ||
), | ||
) |
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,43 @@ | ||
|
||
import subprocess | ||
from os import curdir, makedirs, chdir | ||
from os.path import join, curdir, dirname | ||
from shlex import split as shlex_split | ||
|
||
from bumpversion import main | ||
|
||
def test_simple_replacement(): | ||
path = join(curdir, '_test_run', 'simple_replacement') | ||
makedirs(path) | ||
chdir(path) | ||
|
||
with open('VERSION', 'w') as f: | ||
f.write("1.2.0") | ||
|
||
main(shlex_split("--old-version 1.2.0 --new-version 1.2.1 VERSION")) | ||
|
||
with open('VERSION', 'r') as f: | ||
assert "1.2.1" == f.read() | ||
|
||
chdir('../..') | ||
|
||
def test_config_file(): | ||
path = join(curdir, '_test_run', 'config_file') | ||
makedirs(path) | ||
chdir(path) | ||
|
||
with open('mybumpconfig.cfg', 'w') as f: | ||
f.write("""[bumpversion] | ||
old_version: 0.9.34 | ||
new_version: 0.9.35 | ||
files: file1""") | ||
|
||
with open('file1', 'w') as f: | ||
f.write("0.9.34") | ||
|
||
main(shlex_split("--config-file mybumpconfig.cfg")) | ||
|
||
with open('file1', 'r') as f: | ||
assert "0.9.35" == f.read() | ||
|
||
chdir('../..') |
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,7 @@ | ||
[tox] | ||
envlist = py27 | ||
|
||
[testenv] | ||
deps=pytest | ||
commands= | ||
py.test tests.py |