Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
peritus committed Mar 10, 2013
0 parents commit db5aa7b
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.tox
_test_run/
bin/
include/
lib/
.Python
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include README.rst
17 changes: 17 additions & 0 deletions README.rst
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


51 changes: 51 additions & 0 deletions bumpversion/__init__.py
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)

24 changes: 24 additions & 0 deletions setup.py
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',
),
)
43 changes: 43 additions & 0 deletions tests.py
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('../..')
7 changes: 7 additions & 0 deletions tox.ini
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

0 comments on commit db5aa7b

Please sign in to comment.