changeset 0:96362e527bd6

initial package
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 21 Feb 2012 20:30:10 -0800
parents
children a011af5e765a
files INSTALL.py README.txt paint/__init__.py paint/main.py setup.py tests/doctest.txt tests/test.py
diffstat 7 files changed, 206 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/INSTALL.py	Tue Feb 21 20:30:10 2012 -0800
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+
+"""
+installation script for PaInt
+python PAckage INTrospection
+"""
+
+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/mozilla/hg/PaInt'
+DEST='PaInt' # 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)
+
+"""
+XXX unfinished
+
+hg clone ${REPO}
+cd PaInt
+python setup.py develop
+"""
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.txt	Tue Feb 21 20:30:10 2012 -0800
@@ -0,0 +1,11 @@
+PaInt
+===========
+
+python PAckage INTrospection
+
+----
+
+Jeff Hammel
+
+http://k0s.org/mozilla/hg/PaInt
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paint/__init__.py	Tue Feb 21 20:30:10 2012 -0800
@@ -0,0 +1,2 @@
+#
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paint/main.py	Tue Feb 21 20:30:10 2012 -0800
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+"""
+python PAckage INTrospection
+"""
+
+import sys
+import optparse
+
+def main(args=sys.argv[:]):
+
+  # parse command line options
+  usage = '%prog [options]'
+
+  # description formatter
+  class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
+    def format_description(self, description):
+      if description:
+        return description + '\n'
+      else:
+        return ''
+  
+  parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
+  options, args = parser.parse_args(args)
+
+if __name__ == '__main__':
+  main()  
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.py	Tue Feb 21 20:30:10 2012 -0800
@@ -0,0 +1,41 @@
+"""
+setup packaging script for PaInt
+"""
+
+import os
+
+version = "0.0"
+dependencies = []
+
+# allow use of setuptools/distribute or distutils
+kw = {}
+try:
+    from setuptools import setup
+    kw['entry_points'] = """
+      [console_scripts]
+      python-package = PaInt.main:main
+"""
+    kw['install_requires'] = dependencies
+except ImportError:
+    from distutils.core import setup
+
+try:
+    here = os.path.dirname(os.path.abspath(__file__))
+    description = file(os.path.join(here, 'README.txt')).read()
+except IOError:
+    description = ''
+
+setup(name='PaInt',
+      version=version,
+      description="python PAckage INTrospection",
+      long_description=description,
+      classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
+      author='Jeff Hammel',
+      author_email='jhammel@mozilla.com',
+      url='http://k0s.org/mozilla/hg/PaInt',
+      license='',
+      packages=['paint'],
+      include_package_data=True,
+      zip_safe=False,
+      **kw
+      )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/doctest.txt	Tue Feb 21 20:30:10 2012 -0800
@@ -0,0 +1,11 @@
+Test PaInt
+================
+
+The obligatory imports:
+
+    >>> import paint
+
+Run some tests.  This test will fail, please fix it:
+
+    >>> assert True == False
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test.py	Tue Feb 21 20:30:10 2012 -0800
@@ -0,0 +1,60 @@
+#!/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)
+    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()
+