From b0803054b56905f273936bb6c6e81f4e488c84f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=BCnter=20Milde?= Date: Thu, 23 Feb 2017 22:49:20 +0100 Subject: [PATCH] pylit 0.7.10 * lua support out of the box * setup.py * regexp-test --- .gitignore | 10 +++++++ pylit.py | 21 ++++++++++---- setup.py | 53 +++++++++++++++++++++++++++++++++++ test/regexp-test.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100644 setup.py create mode 100644 test/regexp-test.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1da58ef --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*~ +*.pyc +/doc/build/* +/README.html +/doc/logo/*.png +/doc/logo/*.ico +/doc/conf.py.txt +/doc/examples/pylit.py.txt +/doc/examples/*.py +/doc/examples/*.sty diff --git a/pylit.py b/pylit.py index d2885eb..f5103ab 100755 --- a/pylit.py +++ b/pylit.py @@ -6,9 +6,9 @@ # Literate programming with reStructuredText # ++++++++++++++++++++++++++++++++++++++++++ # -# :Date: $Date$ -# :Revision: $Revision$ -# :URL: $URL$ +# :Date: $Date: 2011-10-12 12:51:40 +0200 (Mi, 12. Okt 2011) $ +# :Revision: $Revision: 125 $ +# :URL: $URL: svn+ssh://svn.berlios.de/svnroot/repos/pylit/trunk/src/pylit.py $ # :Copyright: © 2005, 2007 Günter Milde. # Released without warranty under the terms of the # GNU General Public License (v. 2 or later) @@ -17,8 +17,8 @@ """pylit: bidirectional text <-> code converter -Convert between a *text document* with embedded code -and *source code* with embedded documentation. +Covert between a *text source* with embedded computer code and a *code source* +with embedded documentation. """ # .. contents:: @@ -108,6 +108,7 @@ and *source code* with embedded documentation. # 0.7.8 2011-03-30 bugfix: do not overwrite custom `add_missing_marker` value, # allow directive options following the 'code' directive. # 0.7.9 2011-04-05 Decode doctest string if 'magic comment' gives encoding. +# 0.7.10 2013-06-07 Add "lua" to defaults.languages # ====== ========== =========================================================== # # :: @@ -189,6 +190,7 @@ defaults.languages = DefaultDict("python", # fallback language {".c": "c", ".cc": "c++", ".css": "css", + ".lua": "lua", ".py": "python", ".sh": "shell", ".sl": "slang", @@ -231,6 +233,7 @@ defaults.comment_strings = DefaultDict('# ', {"css": '// ', "c": '// ', "c++": '// ', + "lua": '-- ', "latex": '% ', "python": '# ', "shell": '# ', @@ -1315,6 +1318,10 @@ class PylitOptions(object): help="overwrite output file (default 'update')") p.add_option("--replace", action="store_true", help="move infile to a backup copy (appending '~')") + # TODO: do we need this? If yes, make mtime update depend on it! + # p.add_option("--keep-mtime", action="store_true", + # help="do not set the modification time of the outfile " + # "to the corresponding value of the infile") p.add_option("-s", "--strip", action="store_true", help='"export" by stripping documentation or code') @@ -1495,6 +1502,8 @@ def open_streams(infile = '-', outfile = '-', overwrite='update', **keyw): out_stream = sys.stdout elif overwrite == 'no' and os.path.exists(outfile): raise IOError, (1, "Output file exists!", outfile) + elif overwrite == 'update' and is_newer(outfile, infile) is None: + raise IOError, (1, "Output file is as old as input file!", outfile) elif overwrite == 'update' and is_newer(outfile, infile): raise IOError, (1, "Output file is newer than input file!", outfile) else: @@ -1734,6 +1743,8 @@ def main(args=sys.argv[1:], **defaults): # the output file to the one of the input file to indicate that the contained # information is equal. [#]_ :: + + # print "fractions?", os.stat_float_times() try: os.utime(options.outfile, (os.path.getatime(options.outfile), os.path.getmtime(options.infile)) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6a2edff --- /dev/null +++ b/setup.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +# coding=utf-8 +from distutils.core import setup + +setup(name='PyLit', + # version='0.7.9', + description='Literate programming with reStructuredText', + long_description=""" + +PyLit (Python Literate) provides a plain but efficient tool for `literate +programming`_: a bidirectional text/code converter. + + The idea is that you do not document programs (after the fact), but + write documents that *contain* the programs. + + -- John Max Skaller in a `Charming Python interview`_ + +Features +-------- + +* `Dual Source`_ +* Simplicity +* Markup with reStructuredText_ +* Python Doctest Support + +.. _Charming Python interview: + http://www.ibm.com/developerworks/library/l-pyth7.html +.. _reStructuredText: http://docutils.sourceforge.net/rst.html +.. _dual source: http://pylit.berlios.de/features.html#dual-source +.. _literate programming: http://pylit.berlios.de/literate-programming.html + """, + author='Guenter Milde', + author_email='milde@users.sf.net', + url='http://pylit.berlios.de/', + download_url='http://pylit.berlios.de/download/', + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: GNU General Public License (GPL)', + 'Natural Language :: English', + 'Natural Language :: German', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 2.4', + 'Topic :: Software Development :: Documentation', + 'Topic :: Software Development :: User Interfaces', + 'Topic :: Text Processing :: Markup' + ], + provides=['pylit'], + scripts=['rstdocs/download/pylit'], + package_dir = {'': 'src'}, + py_modules = ['pylit'] + ) diff --git a/test/regexp-test.py b/test/regexp-test.py new file mode 100644 index 0000000..1585011 --- /dev/null +++ b/test/regexp-test.py @@ -0,0 +1,80 @@ +import re + +literal = """\ +:: + :: +t :: +text:: + indented:: + indented :: +more text :: + indented text :: +. no-directive:: +a .. directive:: somewhere:: +""" + +directive = """\ +.. code-block:: python + .. code-block:: python +.. code-block:: python listings + .. code-block:: python listings +""" + +misses = """\ +.. comment string :: +.. :: +text: +""" + +def get_regexp(marker): + class self: pass # dummy to make the definitions compatible to pylit + if marker == '::': + self.marker_regexp = re.compile('^( *(?!\.\.).*)(%s)([ \n]*)$' + % marker) + else: + # assume code_block_marker is a directive like '.. code-block::' + self.marker_regexp = re.compile('^( *)(%s)(.*\n?)$' % marker) + return self.marker_regexp + +for marker in ('::', '.. code-block::'): + print 'regexp test for %r' % marker + regexp = get_regexp(marker) + for sample in (literal + directive + misses).splitlines(True): + match = regexp.search(sample) + print '%-40r'%(sample), + if match: + print '-> ', match.groups() + # print '-> ', repr(match.group()) + else: + print '-> ', match + +options = """\ + :lineno: + :lineno: 2 + :line-no: + :line+no: + :lineno+: + :x:x: +""" + +no_options = [' :lineno:2', # no space before option arg + ':lineno:', # no leading whitespace + ' ::', # empty option + ' :lin$no:', # invalid character + ] +option_regexp = re.compile(r' +:(\w|[-._+:])+:( |$)') + +print 'regexp test for option_regexp' +for sample in (options).splitlines(True) + no_options: + match = option_regexp.search(sample) + print '%-40r'%(sample), + if match: + print '-> ', match.groups() + # print '-> ', repr(match.group()) + else: + print '-> ', match + + + + + -- 2.11.4.GIT