# HG changeset patch # User Jeff Hammel # Date 1408058776 25200 # Node ID 48d0f28311a33500bb6b1f23df3ea18e8d693082 init diff -r 000000000000 -r 48d0f28311a3 INSTALL.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/INSTALL.py Thu Aug 14 16:26:16 2014 -0700 @@ -0,0 +1,67 @@ +#!/usr/bin/env python + +""" +installation script for kplot +personal experiments in plotting +""" + +import os +import sys +import urllib2 +import subprocess +try: + from subprocess import check_call as call +except: + from subprocess import call + +REPO='http://k0s.org/hg/kplot' +DEST='kplot' # name of the virtualenv +VIRTUALENV='https://raw.github.com/pypa/virtualenv/develop/virtualenv.py' + +def which(binary, path=os.environ['PATH']): + dirs = path.split(os.pathsep) + for dir in dirs: + if os.path.isfile(os.path.join(dir, fileName)): + return os.path.join(dir, fileName) + if os.path.isfile(os.path.join(dir, fileName + ".exe")): + return os.path.join(dir, fileName + ".exe") + +def main(args=sys.argv[1:]): + + # create a virtualenv + virtualenv = which('virtualenv') or which('virtualenv.py') + if virtualenv: + call([virtualenv, DEST]) + else: + process = subproces.Popen([sys.executable, '-', DEST], stdin=subprocess.PIPE) + process.communicate(stdin=urllib2.urlopen(VIRTUALENV).read()) + + # create a src directory + src = os.path.join(DEST, 'src') + os.mkdir(src) + + # clone the repository + call(['hg', 'clone', REPO], cwd=src) + + # find the virtualenv python + python = None + for path in (('bin', 'python'), ('Scripts', 'python.exe')): + _python = os.path.join(DEST, *path) + if os.path.exists(_python) + python = _python + break + else: + raise Exception("Python binary not found in %s" % DEST) + + # find the clone + filename = REPO.rstrip('/') + filename = filename.split('/')[-1] + clone = os.path.join(src, filename) + assert os.path.exists(clone), "Clone directory not found in %s" % src + + # ensure setup.py exists + assert os.path.exists(os.path.join(clone, 'setup.py')), 'setup.py not found in %s' % clone + + # install the package in develop mode + call([python 'setup.py', 'develop'], cwd=clone) + diff -r 000000000000 -r 48d0f28311a3 README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.txt Thu Aug 14 16:26:16 2014 -0700 @@ -0,0 +1,11 @@ +kplot +=========== + +personal experiments in plotting + +---- + +Jeff Hammel + +http://k0s.org/hg/kplot + diff -r 000000000000 -r 48d0f28311a3 kplot/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kplot/__init__.py Thu Aug 14 16:26:16 2014 -0700 @@ -0,0 +1,3 @@ +# +from main import * + diff -r 000000000000 -r 48d0f28311a3 kplot/main.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kplot/main.py Thu Aug 14 16:26:16 2014 -0700 @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +personal experiments in plotting +""" + +# imports +import argparse +import os +import subprocess +import sys + +# module globals +__all__ = ['main', 'Parser'] +here = os.path.dirname(os.path.realpath(__file__)) +string = (str, unicode) + +def ensure_dir(directory): + """ensure a directory exists""" + if os.path.exists(directory): + assert os.path.isdir(directory) + return directory + os.makedirs(directory) + return directory + + +class Parser(argparse.ArgumentParser): + """CLI option parser""" + def __init__(self, **kwargs): + kwargs.setdefault('description', __doc__) + argparse.ArgumentParser.__init__(self, **kwargs) + self.options = None + + def parse_args(self, *args, **kw): + options = argparse.ArgumentParser.parse_args(self, *args, **kw) + self.validate(options) + self.options = options + return options + + def validate(self, options): + """validate options""" + +def main(args=sys.argv[1:]): + """CLI""" + + # parse command line options + parser = Parser() + options = parser.parse_args(args) + +if __name__ == '__main__': + main() + diff -r 000000000000 -r 48d0f28311a3 kplot/template.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kplot/template.py Thu Aug 14 16:26:16 2014 -0700 @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +""" +kplot template for makeitso +""" + +import sys +from cli import MakeItSoCLI +from optparse import OptionParser +from template import MakeItSoTemplate + +class kplotTemplate(MakeItSoTemplate): + """ + kplot template + """ + name = 'kplot' + templates = ['template'] + look = True + +class TemplateCLI(MakeItSoCLI): + """ + CLI driver for the kplot template + """ + +def main(args=sys.argv[:]): + cli = TemplateCLI() + cli(*args) + +if __name__ == '__main__': + main() + + diff -r 000000000000 -r 48d0f28311a3 kplot/web.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kplot/web.py Thu Aug 14 16:26:16 2014 -0700 @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +""" +web handler for kplot +""" + +from webob import Request, Response, exc + +class Handler(object): + + def __init__(self, **kw): + pass + + def __call__(self, environ, start_response): + request = Request(environ) + response = Response(content_type='text/plain', + body="kplot") + return response(environ, start_response) + +if __name__ == '__main__': + from wsgiref import simple_server + app = Handler() + server = simple_server.make_server(host='0.0.0.0', port=8080, app=app) + server.serve_forever() + + diff -r 000000000000 -r 48d0f28311a3 setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Thu Aug 14 16:26:16 2014 -0700 @@ -0,0 +1,45 @@ +""" +setup packaging script for kplot +""" + +import os + +version = "0.0" +dependencies = ['MakeItSo', 'webob'] + +# allow use of setuptools/distribute or distutils +kw = {} +try: + from setuptools import setup + kw['entry_points'] = """ + [console_scripts] + kplot = kplot.main:main + kplot-template = kplot.template:main +""" + kw['install_requires'] = dependencies +except ImportError: + from distutils.core import setup + kw['requires'] = dependencies + +try: + here = os.path.dirname(os.path.abspath(__file__)) + description = file(os.path.join(here, 'README.txt')).read() +except IOError: + description = '' + + +setup(name='kplot', + version=version, + description="personal experiments in plotting", + long_description=description, + classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers + author='Jeff Hammel', + author_email='k0scist@gmail.com', + url='http://k0s.org/hg/kplot', + license='', + packages=['kplot'], + include_package_data=True, + zip_safe=False, + **kw + ) + diff -r 000000000000 -r 48d0f28311a3 tests/doctest.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/doctest.txt Thu Aug 14 16:26:16 2014 -0700 @@ -0,0 +1,11 @@ +Test kplot +================ + +The obligatory imports: + + >>> import kplot + +Run some tests. This test will fail, please fix it: + + >>> assert True == False + diff -r 000000000000 -r 48d0f28311a3 tests/run_doctests.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/run_doctests.py Thu Aug 14 16:26:16 2014 -0700 @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +""" +doctest runner +""" + +import doctest +import os +import sys +from optparse import OptionParser + + +def run_tests(raise_on_error=False, report_first=False): + + # add results here + results = {} + + # doctest arguments + directory = os.path.dirname(os.path.abspath(__file__)) + extraglobs = {'here': directory} + doctest_args = dict(extraglobs=extraglobs, raise_on_error=raise_on_error) + doctest_args['optionsflags'] = doctest.ELLIPSIS + if report_first: + doctest_args['optionflags'] |= doctest.REPORT_ONLY_FIRST_FAILURE + + # gather tests + tests = [test for test in os.listdir(directory) + if test.endswith('.txt')] + + # run the tests + for test in tests: + try: + results[test] = doctest.testfile(test, **doctest_args) + except doctest.DocTestFailure, failure: + raise + except doctest.UnexpectedException, failure: + raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2] + + return results + +def main(args=sys.argv[1:]): + + # parse command line args + parser = OptionParser(description=__doc__) + parser.add_option('--raise', dest='raise_on_error', + default=False, action='store_true', + help="raise on first error") + parser.add_option('--report-first', dest='report_first', + default=False, action='store_true', + help="report the first error only (all tests will still run)") + options, args = parser.parse_args(args) + + # run the tests + results = run_tests(**options.__dict__) + if sum([i.failed for i in results.values()]): + sys.exit(1) # error + + +if __name__ == '__main__': + main() + diff -r 000000000000 -r 48d0f28311a3 tests/test_kplot.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_kplot.py Thu Aug 14 16:26:16 2014 -0700 @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +""" +unit tests +""" + +import os +import sys +import unittest + +# globals +here = os.path.dirname(os.path.abspath(__file__)) + +class kplotUnitTest(unittest.TestCase): + + def test_kplot(self): + pass + +if __name__ == '__main__': + unittest.main() + diff -r 000000000000 -r 48d0f28311a3 tests/testall.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/testall.py Thu Aug 14 16:26:16 2014 -0700 @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +""" +run all unit tests +""" + +import os +import sys +import unittest + +here = os.path.dirname(os.path.abspath(__file__)) + +def main(args=sys.argv[1:]): + + results = unittest.TestResult() + suite = unittest.TestLoader().discover(here, 'test_*.py') + suite.run(results) + n_errors = len(results.errors) + n_failures = len(results.failures) + print ("Run {} tests ({} failures; {} errors)".format(results.testsRun, + n_failures, + n_errors)) + if results.wasSuccessful(): + print ("Success") + sys.exit(0) + else: + # print failures and errors + for label, item in (('FAIL', results.failures), + ('ERROR', results.errors)): + if item: + print ("\n{}::\n".format(label)) + for index, (i, message) in enumerate(item): + print ('{}) {}:'.format(index, str(i))) + print (message) + sys.exit(1) + +if __name__ == '__main__': + main() + +