diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc new file mode 100644 index 0000000..df9f6ec --- /dev/null +++ b/CHANGELOG.adoc @@ -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. diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index a297051..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,11 +0,0 @@ -Verace Changelog -================ -## verace-0.1.0 (2015-07-18) -### Release highlights - - First release. - -### All additions and changes -Not applicable. - -### Bug fixes -Not applicable. diff --git a/README.adoc b/README.adoc new file mode 100644 index 0000000..07517b7 --- /dev/null +++ b/README.adoc @@ -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". diff --git a/README.md b/README.md deleted file mode 100644 index fea2a52..0000000 --- a/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# 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. diff --git a/_Check_Versions.py b/_Check_Versions.py index a88e422..eb67a4a 100644 --- a/_Check_Versions.py +++ b/_Check_Versions.py @@ -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...") diff --git a/examples/check_1.py b/examples/check_1.py index 31c5684..816ded8 100644 --- a/examples/check_1.py +++ b/examples/check_1.py @@ -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() diff --git a/examples/check_2.py b/examples/check_2.py new file mode 100644 index 0000000..3dcc7bd --- /dev/null +++ b/examples/check_2.py @@ -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() diff --git a/examples/env.py b/examples/env.py new file mode 100644 index 0000000..b6f134f --- /dev/null +++ b/examples/env.py @@ -0,0 +1,2 @@ +import sys +sys.path.insert(0, "..\lib") diff --git a/examples/file.txt b/examples/file_1.txt similarity index 100% rename from examples/file.txt rename to examples/file_1.txt diff --git a/examples/file_2.txt b/examples/file_2.txt new file mode 100644 index 0000000..350e805 --- /dev/null +++ b/examples/file_2.txt @@ -0,0 +1,2 @@ +Another example file! +"version" = "0.1.0" diff --git a/lib/setup.py b/lib/setup.py index 190c076..6002e10 100644 --- a/lib/setup.py +++ b/lib/setup.py @@ -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 = "jeffrimko@gmail.com", - 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") diff --git a/lib/verace.py b/lib/verace.py index 4c69c6b..b51e83e 100644 --- a/lib/verace.py +++ b/lib/verace.py @@ -8,6 +8,7 @@ ## SECTION: Imports # ##==============================================================# +import copy import os.path as op from collections import namedtuple @@ -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") @@ -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**: @@ -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 = [] @@ -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 ##==============================================================# @@ -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)] ##==============================================================#