Skip to content

Commit

Permalink
Updates for new release.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffrimko committed Oct 18, 2015
1 parent 9e26077 commit b09570e
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 72 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
= Verace Changelog

== verace-0.2.0 (2015-10-18)
=== Release highlights
- Significant change to library design, now using functions instead of class methods to check version strings.

=== All additions and changes
Not applicable.

=== Bug fixes
Not applicable.

== verace-0.1.0 (2015-07-18)
=== Release highlights
- First release.

=== All additions and changes
Not applicable.

=== Bug fixes
Not applicable.
11 changes: 0 additions & 11 deletions CHANGELOG.md

This file was deleted.

30 changes: 30 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
= Verace

== Introduction
This project provides a Python 2.x library for creating scripts that check version strings. The main features are the following:

- Custom parse any project files for version strings.
- Easily determine if all version strings in a project are consistent.
- Should work on any platform without additional dependencies.

== Status
Currently, this project is **under active development**. The contents of the repository should be considered unstable during active development.

== Requirements
Verace should run on any Python 2.x interpreter without additional dependencies.

== Installation
Verace can be installed with pip using the following command: `pip install verace`

Additional, Verace can be installed from source by running: `python setup.py install`

== Usage
The following are basic examples of Verace (all examples can be found https://github.com/jeffrimko/Verace/tree/master/examples[here]):

- https://github.com/jeffrimko/Verace/blob/master/examples/check_1.py[`examples/check_1.py`] - Basic version checking.
- https://github.com/jeffrimko/Verace/blob/master/examples/check_2.py[`examples/check_2.py`] - Basic version checking.

== FAQ
How is **Verace** pronounced?

- "ver-AH-che" - Italian word for "truthful/accurate".
11 changes: 0 additions & 11 deletions README.md

This file was deleted.

29 changes: 6 additions & 23 deletions _Check_Versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,18 @@
from verace import VerChecker, VerInfo

##==============================================================#
## SECTION: Class Definitions #
## SECTION: Global Definitions #
##==============================================================#

class VeraceChecker(VerChecker):
"""Check versions in the Verace project (meta)."""
NAME = "Verace"
def check_setup(self):
path = r"lib\setup.py"
with open(path) as f:
for num,line in enumerate(f.readlines(), 1):
if line.find("version =") > -1:
return [VerInfo(path, num, line.split('"')[1].strip())]
def check_main(self):
path = r"lib\verace.py"
with open(path) as f:
for num,line in enumerate(f.readlines(), 1):
if line.find("__version__ =") > -1:
return [VerInfo(path, num, line.split('"')[1].strip())]
def check_log(self):
path = r"CHANGELOG.md"
with open(path) as f:
for num,line in enumerate(f.readlines(), 1):
if line.find("verace-") > -1:
return [VerInfo(path, num, line.split('-')[1].split(" ")[0].strip())]
VERCHK = VerChecker("Verace", __file__)
VERCHK.include(r"lib\setup.py", opts={'match':"version = ", 'delim':'"'})
VERCHK.include(r"lib\verace.py", match="__version__ = ", delim='"')
VERCHK.include(r"CHANGELOG.adoc", match="verace-", delim="-", delim2=" ")

##==============================================================#
## SECTION: Main Body #
##==============================================================#

if __name__ == '__main__':
VeraceChecker(debug=False).show()
print VERCHK.run()
raw_input("Press ENTER to continue...")
19 changes: 9 additions & 10 deletions examples/check_1.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import sys
sys.path.insert(0, "..\lib")
import env
from verace import VerChecker, VerInfo

v1 = VerChecker("Example 1", __file__)
v1.include("file.txt", opts={'match':"version", 'delim':"="})
v1.include("file.txt", opts={'match':"another", 'delim':"="})
v1.include("file.txt", opts={'match':"onemore", 'delim':":"})
v1 = VerChecker("Example 1a", __file__)
v1.include("file_1.txt")
v1.include("file_1.txt", match="another")
v1.include("file_1.txt", match="onemore", delim=":")
v1.run()

v2 = VerChecker("Example 2", __file__)
v2.include("file.txt", opts={'match':"version", 'delim':"="})
v2.include("file.txt", opts={'match':"another", 'delim':"="})
v2.include("file.txt", opts={'match':"diffver", 'delim':"= v"})
v2 = VerChecker("Example 1b", __file__)
v2.include("file_1.txt")
v2.include("file_1.txt", match="another")
v2.include("file_1.txt", match="diffver", delim="= v")
v2.run()
14 changes: 14 additions & 0 deletions examples/check_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import env
from verace import VerChecker, VerInfo

def check_ver(path):
for num,line in enumerate(open(path).readlines()):
if line.find("version") > -1:
ver = line.split("=")[1]
ver = ver.split('"')[1].split('"')[0]
return [VerInfo(path, num+1, ver)]

v1 = VerChecker("Example 2", __file__)
v1.include("file_1.txt", match="onemore", delim=":")
v1.include("file_2.txt", check_ver)
v1.run()
2 changes: 2 additions & 0 deletions examples/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import sys
sys.path.insert(0, "..\lib")
File renamed without changes.
2 changes: 2 additions & 0 deletions examples/file_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Another example file!
"version" = "0.1.0"
14 changes: 11 additions & 3 deletions lib/setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import os
import subprocess
from setuptools import setup, find_packages

subprocess.call("asciidoc -b docbook ../README.adoc", shell=True)
subprocess.call("pandoc -r docbook -w rst -o ../README.rst ../README.xml", shell=True)
os.remove("../README.xml")

setup(
name = "verace",
version = "0.2.0-alpha",
version = "0.2.0",
author = "Jeff Rimko",
author_email = "[email protected]",
description = "Library for creating version string checking scripts.",
description = "Library for checking version strings in project files.",
license = "MIT",
url = "https://github.com/jeffrimko/Verace",
py_modules=["verace"],
long_description=__doc__,
long_description=open("../README.rst").read(),
classifiers=[
"Development Status :: 3 - Alpha",
"Topic :: Utilities",
"Programming Language :: Python :: 2.7",
],
)

os.remove("../README.rst")
36 changes: 22 additions & 14 deletions lib/verace.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
## SECTION: Imports #
##==============================================================#

import copy
import os.path as op
from collections import namedtuple

Expand All @@ -16,7 +17,7 @@
##==============================================================#

#: Library version string.
__version__ = "0.2.0-alpha"
__version__ = "0.2.0"

#: Contains version information for a single checked item.
VerInfo = namedtuple("VerInfo", "path linenum string")
Expand Down Expand Up @@ -44,7 +45,7 @@ def string(self):
"""Returns the version string if `run()` found no inconsistencies,
otherwise None is returned."""
return self._string
def include(self, path, func=None, opts={}, **kwargs):
def include(self, path, func=None, opts=None, **kwargs):
"""Includes a file to check.
**Params**:
Expand All @@ -54,11 +55,14 @@ def include(self, path, func=None, opts={}, **kwargs):
- opts (dict) - Options to pass to the check function. Any additional
key word args will be included.
"""
opts.update(kwargs)
if not opts:
opts = {}
opts.update(copy.deepcopy(kwargs))
if not func:
func = check_basic
self._checks.append((path, func, opts))
def run(self, verbose=True):
c = (path, func, copy.deepcopy(opts))
self._checks.append(c)
def run(self, verbose=True, debug=False):
"""Runs checks on all included items, reports any inconsistencies."""
vprint = get_vprint(verbose)
self._vinfos = []
Expand All @@ -69,16 +73,20 @@ def run(self, verbose=True):
if not op.isabs(path):
path = op.join(self.root, path)
path = op.normpath(path)
self._vinfos.extend(c[1](path, c[2]))
self._vinfos.extend(c[1](path, **c[2]))
for vinfo in self._vinfos:
vprint(" `%s` (%s:%u)" % (
vinfo.string,
op.relpath(vinfo.path),
vinfo.linenum))
strings = set([v.string for v in self._vinfos])
self._string = list(strings)[0] if 1 == len(strings) else None
if not self._string:
vprint(" [!] WARNING: Version numbers differ!")
if strings:
self._string = list(strings)[0] if 1 == len(strings) else None
if not self._string:
vprint(" [!] WARNING: Version info differs!")
else:
self._string = None
vprint(" [!] WARNING: No version info found!")
return self._string

##==============================================================#
Expand All @@ -98,13 +106,13 @@ def _nprint(msg, endl=True):
return _vprint
return _nprint

def check_basic(path, opts):
def check_basic(path, match="version", delim="=", delim2=""):
"""Basic version check function."""
for num,line in enumerate(open(path).readlines()):
if line.find(opts['match']) > -1:
ver = line.split(opts['delim'])[1].strip()
if 'delim2' in opts.keys():
ver = ver.split(opts['delim2'])[0].strip()
if line.find(match) > -1:
ver = line.split(delim)[1].strip()
if delim2:
ver = ver.split(delim2)[0].strip()
return [VerInfo(path, num+1, ver)]

##==============================================================#
Expand Down

0 comments on commit b09570e

Please sign in to comment.