[med-svn] [sphinxcontrib-autoprogram] 02/04: Imported Upstream version 0.1.2

Kevin Murray daube-guest at moszumanska.debian.org
Sun Jan 10 00:06:02 UTC 2016


This is an automated email from the git hooks/post-receive script.

daube-guest pushed a commit to branch master
in repository sphinxcontrib-autoprogram.

commit 92547432e3bc265e195c12675a12f31c71bbfcda
Author: Kevin Murray <spam at kdmurray.id.au>
Date:   Sun Jan 10 10:50:03 2016 +1100

    Imported Upstream version 0.1.2
---
 PKG-INFO                                           |  8 ++-
 README.rst                                         |  6 ++
 setup.py                                           |  4 +-
 sphinxcontrib/autoprogram.py                       | 84 ++++++++++++++++++----
 .../PKG-INFO                                       |  8 ++-
 sphinxcontrib_autoprogram.egg-info/requires.txt    |  2 +
 6 files changed, 94 insertions(+), 18 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index 3729d4c..f2e40a5 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: sphinxcontrib-autoprogram
-Version: 0.1.1
+Version: 0.1.2
 Summary: Documenting CLI programs
 Home-page: https://bitbucket.org/birkenfeld/sphinx-contrib
 Author: Hong Minhee
@@ -14,6 +14,12 @@ Description: ``sphinxcontrib.autoprogram`` --- Documenting CLI programs
         and then expands it into a set of ``.. program::`` and ``.. option::``
         directives.
         
+        Install using ``pip``:
+        
+        .. code-block:: console
+        
+           $ pip install sphinxcontrib-autoprogram
+        
         You can find the documentation from the following URL:
         
         https://pythonhosted.org/sphinxcontrib-autoprogram/
diff --git a/README.rst b/README.rst
index e3bd953..45c7188 100644
--- a/README.rst
+++ b/README.rst
@@ -6,6 +6,12 @@ way to document CLI programs.  It scans ``arparser.ArgumentParser`` object,
 and then expands it into a set of ``.. program::`` and ``.. option::``
 directives.
 
+Install using ``pip``:
+
+.. code-block:: console
+
+   $ pip install sphinxcontrib-autoprogram
+
 You can find the documentation from the following URL:
 
 https://pythonhosted.org/sphinxcontrib-autoprogram/
diff --git a/setup.py b/setup.py
index 2bb92ca..10a5a1c 100644
--- a/setup.py
+++ b/setup.py
@@ -7,9 +7,9 @@ from setuptools import setup, find_packages
 
 
 # Do not change the variable name.  It's parsed by doc/conf.py script.
-version = '0.1.1'
+version = '0.1.2'
 
-requires = ['Sphinx >= 1.2']
+requires = ['Sphinx >= 1.2', 'six']
 
 if sys.version_info < (2, 7):
     requires.append('argparse')
diff --git a/sphinxcontrib/autoprogram.py b/sphinxcontrib/autoprogram.py
index a427f9a..3c1eb61 100644
--- a/sphinxcontrib/autoprogram.py
+++ b/sphinxcontrib/autoprogram.py
@@ -8,6 +8,7 @@
     :license: BSD, see LICENSE for details.
 
 """
+# pylint: disable=protected-access,missing-docstring
 import argparse
 import collections
 try:
@@ -17,6 +18,7 @@ except ImportError:
 import functools
 import re
 import unittest
+import six
 
 from docutils import nodes
 from docutils.parsers.rst.directives import unchanged
@@ -41,14 +43,19 @@ def scan_programs(parser, command=[]):
         if arg.option_strings:
             if isinstance(arg, (argparse._StoreAction,
                                 argparse._AppendAction)):
-                metavar = (arg.metavar or arg.dest).lower()
-                names = ['{0} <{1}>'.format(option_string, metavar)
-                         for option_string in arg.option_strings]
+                if arg.choices is None:
+                    metavar = (arg.metavar or arg.dest).lower()
+                    names = ['{0} <{1}>'.format(option_string, metavar)
+                             for option_string in arg.option_strings]
+                else:
+                    choices = '{0}'.format(','.join(arg.choices))
+                    names = ['{0} {{{1}}}'.format(option_string, choices)
+                             for option_string in arg.option_strings]
             else:
                 names = list(arg.option_strings)
             desc = (arg.help or '') % {'default': arg.default}
             options.append((names, desc))
-    yield command, options, parser.description or ''
+    yield command, options, parser.description, parser.epilog or ''
     if parser._subparsers:
         choices = parser._subparsers._actions[-1].choices.items()
         if not (hasattr(collections, 'OrderedDict') and
@@ -62,7 +69,32 @@ def scan_programs(parser, command=[]):
 
 def import_object(import_name):
     module_name, expr = import_name.split(':', 1)
-    mod = __import__(module_name)
+    try:
+        mod = __import__(module_name)
+    except ImportError:
+        # This happens if the file is a script with no .py extension. Here we
+        # trick autoprogram to load a module in memory with the contents of
+        # the script, if there is a script named module_name. Otherwise, raise
+        # an ImportError as it did before.
+        import glob
+        import sys
+        import os
+        import imp
+
+        for p in sys.path:
+            f = glob.glob(os.path.join(p, module_name))
+            if len(f) > 0:
+                with open(f[0]) as fobj:
+                    codestring = fobj.read()
+                foo = imp.new_module("foo")
+                six.exec_(codestring, foo.__dict__)
+
+                sys.modules["foo"] = foo
+                mod = __import__("foo")
+                break
+        else:
+            raise ImportError("No module named {}".format(module_name))
+
     reduce_ = getattr(functools, 'reduce', None) or reduce
     mod = reduce_(getattr, module_name.split('.')[1:], mod)
     globals_ = builtins
@@ -80,23 +112,28 @@ class AutoprogramDirective(Directive):
     def make_rst(self):
         import_name, = self.arguments
         parser = import_object(import_name or '__undefined__')
-        prog = self.options.get('prog', parser.prog)
-        for commands, options, desc in scan_programs(parser):
+        parser.prog = self.options.get('prog', parser.prog)
+        for commands, options, desc, epilog in scan_programs(parser):
             command = ' '.join(commands)
-            title = '{0} {1}'.format(prog, command).rstrip()
+            title = '{0} {1}'.format(parser.prog, command).rstrip()
             yield ''
             yield '.. program:: ' + title
             yield ''
             yield title
             yield ('!' if commands else '?') * len(title)
             yield ''
-            yield desc
+            yield desc or ''
+            yield ''
+            yield parser.format_usage()
             yield ''
             for option_strings, help_ in options:
                 yield '.. option:: {0}'.format(', '.join(option_strings))
                 yield ''
                 yield '   ' + help_.replace('\n', '   \n')
                 yield ''
+            yield ''
+            for line in epilog.splitlines():
+                yield line or ''
 
     def run(self):
         node = nodes.section()
@@ -141,8 +178,8 @@ class ScannerTestCase(unittest.TestCase):
         programs = scan_programs(parser)
         programs = list(programs)
         self.assertEqual(1, len(programs))
-        pair, = programs
-        program, options, desc = pair
+        parser_info, = programs
+        program, options, desc, _ = parser_info
         self.assertEqual([], program)
         self.assertEqual('Process some integers.', desc)
         self.assertEqual(4, len(options))
@@ -180,7 +217,7 @@ class ScannerTestCase(unittest.TestCase):
         programs = list(programs)
         self.assertEqual(3, len(programs))
         # main
-        program, options, desc = programs[0]
+        program, options, desc, _ = programs[0]
         self.assertEqual([], program)
         self.assertEqual('Process some integers.', desc)
         self.assertEqual(1, len(options))
@@ -190,7 +227,7 @@ class ScannerTestCase(unittest.TestCase):
             options[0]
         )
         # max
-        program, options, desc = programs[1]
+        program, options, desc, _ = programs[1]
         self.assertEqual(['max'], program)
         self.assertEqual('Find the max.', desc)
         self.assertEqual(2, len(options))
@@ -202,13 +239,32 @@ class ScannerTestCase(unittest.TestCase):
             options[1]
         )
         # sum
-        program, options, desc = programs[2]
+        program, options, desc, _ = programs[2]
         self.assertEqual(['sum'], program)
         self.assertEqual('Sum the integers.', desc)
         self.assertEqual(2, len(options))
         self.assertEqual((['n'], 'An integer for the accumulator.'),
                          options[0])
 
+    def test_choices(self):
+        parser = argparse.ArgumentParser()
+        parser.add_argument("--awesomeness", choices=["meh", "awesome"])
+        program, options, desc, _ = list(scan_programs(parser))[0]
+        log_option = options[1]
+        self.assertEqual((["--awesomeness {meh,awesome}"], ''), log_option)
+
+    def test_parse_epilog(self):
+        parser = argparse.ArgumentParser(
+            description='Process some integers.',
+            epilog='The integers will be processed.'
+        )
+        programs = scan_programs(parser)
+        programs = list(programs)
+        self.assertEqual(1, len(programs))
+        parser_data, = programs
+        program, options, desc, epilog = parser_data
+        self.assertEqual('The integers will be processed.', epilog)
+
 
 class UtilTestCase(unittest.TestCase):
 
diff --git a/PKG-INFO b/sphinxcontrib_autoprogram.egg-info/PKG-INFO
similarity index 91%
copy from PKG-INFO
copy to sphinxcontrib_autoprogram.egg-info/PKG-INFO
index 3729d4c..f2e40a5 100644
--- a/PKG-INFO
+++ b/sphinxcontrib_autoprogram.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: sphinxcontrib-autoprogram
-Version: 0.1.1
+Version: 0.1.2
 Summary: Documenting CLI programs
 Home-page: https://bitbucket.org/birkenfeld/sphinx-contrib
 Author: Hong Minhee
@@ -14,6 +14,12 @@ Description: ``sphinxcontrib.autoprogram`` --- Documenting CLI programs
         and then expands it into a set of ``.. program::`` and ``.. option::``
         directives.
         
+        Install using ``pip``:
+        
+        .. code-block:: console
+        
+           $ pip install sphinxcontrib-autoprogram
+        
         You can find the documentation from the following URL:
         
         https://pythonhosted.org/sphinxcontrib-autoprogram/
diff --git a/sphinxcontrib_autoprogram.egg-info/requires.txt b/sphinxcontrib_autoprogram.egg-info/requires.txt
new file mode 100644
index 0000000..efa4bab
--- /dev/null
+++ b/sphinxcontrib_autoprogram.egg-info/requires.txt
@@ -0,0 +1,2 @@
+Sphinx >= 1.2
+six
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/sphinxcontrib-autoprogram.git



More information about the debian-med-commit mailing list