~oubiwann/pylisp-ng/ast-lisp

« back to all changes in this revision

Viewing changes to pylispng/util/dist.py

  • Committer: Duncan McGreggor
  • Date: 2008-11-11 17:09:09 UTC
  • Revision ID: duncan@canonical.com-20081111170909-5bjw2pugjsaybhj1
* Added cust dist util subpackage.
* Cleaned up admin scripts.
* Added initial content to setup.py.
* Added initial content to README.
* Added README to the test runner.
* Updated TODO.
* Added a bin script for running a lisp interpreter.
* Split PRELUDE and HISTORY out of README.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
import re
 
3
 
 
4
 
 
5
def setup(*args, **kwds):
 
6
    """
 
7
    Compatibility wrapper.
 
8
    """
 
9
    try:
 
10
        from setuptools import setup
 
11
    except ImportError:
 
12
        from distutils.core import setup
 
13
    return setup(*args, **kwds)
 
14
 
 
15
 
 
16
def findPackages():
 
17
    """
 
18
    Compatibility wrapper.
 
19
 
 
20
    Taken from storm setup.py.
 
21
    """
 
22
    try:
 
23
        from setuptools import find_packages
 
24
        return find_packages()
 
25
    except ImportError:
 
26
        pass
 
27
    packages = []
 
28
    for directory, subdirectories, files in os.walk("txlb"):
 
29
        if '__init__.py' in files:
 
30
            packages.append(directory.replace(os.sep, '.'))
 
31
    return packages
 
32
 
 
33
 
 
34
def hasDocutils():
 
35
    """
 
36
    Check to see if docutils is installed.
 
37
    """
 
38
    try:
 
39
        import docutils
 
40
        return True
 
41
    except ImportError:
 
42
        return False
 
43
 
 
44
 
 
45
def _validateReST(text):
 
46
    """
 
47
    Make sure that the given ReST text is valid.
 
48
 
 
49
    Taken from Zope Corp's zc.twist setup.py.
 
50
    """
 
51
    import docutils.utils
 
52
    import docutils.parsers.rst
 
53
    import StringIO
 
54
 
 
55
    doc = docutils.utils.new_document('validator')
 
56
    # our desired settings
 
57
    doc.reporter.halt_level = 5
 
58
    doc.reporter.report_level = 1
 
59
    stream = doc.reporter.stream = StringIO.StringIO()
 
60
    # docutils buglets (?)
 
61
    doc.settings.tab_width = 2
 
62
    doc.settings.pep_references = doc.settings.rfc_references = False
 
63
    doc.settings.trim_footnote_reference_space = None
 
64
    # and we're off...
 
65
    parser = docutils.parsers.rst.Parser()
 
66
    parser.parse(text, doc)
 
67
    return stream.getvalue()
 
68
 
 
69
 
 
70
def validateReST(text):
 
71
    """
 
72
    A wrapper that ensafens the validation for pythons that are not embiggened
 
73
    with docutils.
 
74
    """
 
75
    if hasDocutils():
 
76
        return _validateReST(text)
 
77
    print " *** No docutils; can't validate ReST."
 
78
    return ''
 
79
 
 
80
 
 
81
def catReST(*args, **kwds):
 
82
    """
 
83
    Concatenate the contents of one or more ReST files.
 
84
 
 
85
    Taken from Zope Corp's zc.twist setup.py.
 
86
    """
 
87
    # note: distutils explicitly disallows unicode for setup values :-/
 
88
    # http://docs.python.org/dist/meta-data.html
 
89
    tmp = []
 
90
    for a in args:
 
91
        if a in ['README', 'DEPENDENCIES'] or a.endswith('.txt'):
 
92
            f = open(os.path.join(*a.split('/')))
 
93
            tmp.append(f.read())
 
94
            f.close()
 
95
            tmp.append('\n\n')
 
96
        else:
 
97
            tmp.append(a)
 
98
    if len(tmp) == 1:
 
99
        res = tmp[0]
 
100
    else:
 
101
        res = ''.join(tmp)
 
102
    out = kwds.get('out')
 
103
    if out is True:
 
104
        out = 'CHECK_THIS_BEFORE_UPLOAD.txt'
 
105
    if out:
 
106
        f = open(out, 'w')
 
107
        f.write(res)
 
108
        f.close()
 
109
        report = validateReST(res)
 
110
        if report:
 
111
            print report
 
112
            raise ValueError('ReST validation error')
 
113
    return res
 
114