|
From: <mi...@us...> - 2021-10-19 17:03:05
|
Revision: 8858
http://sourceforge.net/p/docutils/code/8858
Author: milde
Date: 2021-10-19 17:03:02 +0000 (Tue, 19 Oct 2021)
Log Message:
-----------
docutils-cli.py: Read settings from standard configuration files.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docs/user/config.txt
trunk/docutils/docutils/frontend.py
trunk/docutils/tools/docutils-cli.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2021-10-16 21:07:52 UTC (rev 8857)
+++ trunk/docutils/HISTORY.txt 2021-10-19 17:03:02 UTC (rev 8858)
@@ -45,7 +45,11 @@
- New option "image_loading". Support "lazy" loading of images.
Obsoletes "embed_images".
+* tools/docutils-cli.py
+ - Read settings from standard configuration files.
+
+
Release 0.18b1 (2021-10-05)
===========================
Modified: trunk/docutils/docs/user/config.txt
===================================================================
--- trunk/docutils/docs/user/config.txt 2021-10-16 21:07:52 UTC (rev 8857)
+++ trunk/docutils/docs/user/config.txt 2021-10-19 17:03:02 UTC (rev 8858)
@@ -2126,6 +2126,35 @@
.. _HTML writer: html.html
+[docutils-cli application]
+--------------------------
+
+New in 0.18.
+
+reader
+~~~~~~
+Reader component name. One of "standalone" or "pep".
+
+Default: "standalone".
+Option: ``--reader``
+
+parser
+~~~~~~
+Parser component name. One of "markdown", "recommonmark", or "rst"
+
+Default: "rst".
+Option: ``--parser``
+
+.. _writer [docutils-cli application]:
+
+writer
+~~~~~~
+Writer component name. One of the valid writer names or aliases.
+
+Default: "html5".
+Option: ``--writer``
+
+
Other Settings
==============
Modified: trunk/docutils/docutils/frontend.py
===================================================================
--- trunk/docutils/docutils/frontend.py 2021-10-16 21:07:52 UTC (rev 8857)
+++ trunk/docutils/docutils/frontend.py 2021-10-19 17:03:02 UTC (rev 8858)
@@ -332,7 +332,7 @@
def copy(self):
"""Return a shallow copy of `self`."""
return self.__class__(defaults=self.__dict__)
-
+
def setdefault(self, name, default):
"""V.setdefault(n[,d]) -> getattr(V,n,d), also set D.n=d if n not in D or None.
"""
@@ -683,7 +683,7 @@
parser.read(config_file, self)
self.config_files.extend(parser._files)
base_path = os.path.dirname(config_file)
- applied = {}
+ applied = set()
settings = Values()
for component in self.components:
if not component:
@@ -692,7 +692,7 @@
+ (component.config_section,)):
if section in applied:
continue
- applied[section] = 1
+ applied.add(section)
settings.update(parser.get_section(section), self)
make_paths_absolute(
settings.__dict__, self.relative_path_settings, base_path)
Modified: trunk/docutils/tools/docutils-cli.py
===================================================================
--- trunk/docutils/tools/docutils-cli.py 2021-10-16 21:07:52 UTC (rev 8857)
+++ trunk/docutils/tools/docutils-cli.py 2021-10-19 17:03:02 UTC (rev 8858)
@@ -28,31 +28,54 @@
from docutils.core import publish_cmdline, default_description
from docutils.utils import SystemMessage
+from docutils.frontend import ConfigParser, OptionParser
+config_section = 'docutils-cli application'
+
+def config_settings_from_files():
+ """Return dict with default settings for the docutils-cli front end.
+
+ Read default values for the three docutils-cli options from the
+ [docutils-cli application] section in standard configuration files.
+
+ Command-line options are defined separately, using the "argparse" module
+ to allow two-stage parsing of the command line.
+ """
+ settings = {'reader': 'standalone',
+ 'parser': 'rst',
+ 'writer': 'html5'
+ }
+ option_parser = OptionParser()
+ config_parser = ConfigParser()
+ config_files = option_parser.get_standard_config_files()
+ config_parser.read(config_files, option_parser)
+ settings.update(config_parser.get_section(config_section))
+ return settings
+
+default_settings = config_settings_from_files()
+
description = u'Generate documents from reStructuredText or Markdown sources.'
-
-epilog = (u'Currently, the component selection cannot be specified in the '
- u'configuration file. '
- u'The availability of some options depends on the selected '
+
+epilog = (u'The availability of some options depends on the selected '
u'components, the list below adapts to your selection.'
)
-parser = argparse.ArgumentParser(add_help=False,
+parser = argparse.ArgumentParser(add_help=False,
description=description, epilog=epilog,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--reader', choices=('standalone', 'pep'),
help=u'reader name',
- default='standalone')
-parser.add_argument('--parser', choices=('markdown', 'rst'),
+ default=default_settings['reader'])
+parser.add_argument('--parser', choices=('markdown', 'recommonmark', 'rst'),
help=u'parser name',
- default='rst')
-parser.add_argument('--writer',
+ default=default_settings['parser'])
+parser.add_argument('--writer',
# choices=('html', 'html4', 'html5', 'latex', 'xelatex',
# 'odt', 'xml', 'pseudoxml', 'manpage',
# 'pep_html', 's5_html'),
help=u'writer name',
- default='html5')
+ default=default_settings['writer'])
(args, remainder) = parser.parse_known_args()
@@ -64,7 +87,8 @@
try:
publish_cmdline(reader_name=args.reader,
parser_name=args.parser,
- writer_name=args.writer,
+ writer_name=args.writer,
+ config_section=config_section,
description=default_description,
argv=remainder)
except ImportError as error:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|