Permalink
Browse files

Initial commit

  • Loading branch information...
Dinoshauer committed Apr 9, 2014
0 parents commit 2442ed0cbbcc935032ba8a634ef08be3c77a10bb
Showing with 94 additions and 0 deletions.
  1. +10 −0 .editorconfig
  2. +1 −0 .gitignore
  3. +21 −0 LICENSE
  4. +4 −0 README.md
  5. +58 −0 semverpy/semver.py
@@ -0,0 +1,10 @@
root = true
[*]
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
[*.py]
indent_style = space
indent_size = 4
@@ -0,0 +1 @@
*.pyc
21 LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,4 @@
SemVerPy
========
Bumping versions. Semantically.
@@ -0,0 +1,58 @@
import re
class InvalidVersionException(Exception):
pass
class SemVerPy():
def __init__(self, version):
self.pattern = r'(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(?:-(?P<build>\w*)|)'
self.version = self._validate(version)
def __str__(self):
if self.version['build'] is not None:
return '{major}.{minor}.{patch}-{build}'.format(**self.version)
return '{major}.{minor}.{patch}'.format(**self.version)
def __getitem__(self, key):
return self.version[key]
def __setitem__(self, key, value):
self.version[key] = value
return self.version
def _get_dict(self, string):
return re.search(self.pattern, string).groupdict()
@staticmethod
def _parse_dict(version_dict):
try:
version_dict['major'] = int(version_dict['major'])
version_dict['minor'] = int(version_dict['minor'])
version_dict['patch'] = int(version_dict['patch'])
return version_dict
except ValueError:
raise
def _validate(self, string):
try:
version = self._get_dict(string)
version_dict = self._parse_dict(version)
return version_dict
except AttributeError:
raise InvalidVersionException('Not a valid version: {}'.format(string))
def bump_major(self):
self.version['major'] = self.version['major'] + 1
return self.version
def bump_minor(self):
self.version['minor'] = self.version['minor'] + 1
return self.version
def bump_patch(self):
self.version['patch'] = self.version['patch'] + 1
return self.version
def set_build(self, build_string):
self.version['build'] = build_string
return self.version

0 comments on commit 2442ed0

Please sign in to comment.