|
From: <mi...@us...> - 2023-02-07 14:24:39
|
Revision: 9328
http://sourceforge.net/p/docutils/code/9328
Author: milde
Date: 2023-02-07 14:24:37 +0000 (Tue, 07 Feb 2023)
Log Message:
-----------
New general setting "output".
This setting obsoletes the positional argument <destination>.
Cf. the announcement of command line pattern changes in the
RELEASE-NOTES.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docs/user/config.txt
trunk/docutils/docutils/core.py
trunk/docutils/docutils/frontend.py
trunk/docutils/test/data/help/docutils.txt
trunk/docutils/test/data/help/rst2html.txt
trunk/docutils/test/data/help/rst2latex.txt
trunk/docutils/test/test_publisher.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2023-02-07 14:24:19 UTC (rev 9327)
+++ trunk/docutils/HISTORY.txt 2023-02-07 14:24:37 UTC (rev 9328)
@@ -27,6 +27,11 @@
output as binary data in a `bytes` object.
- New functions `rst2…()` for use as "console_scripts" `entry point`_.
+* docutils/frontend.py
+
+ - New setting ``output``. Obsoletes the ``<destination>`` positional
+ argument (cf. "Future changes" in the RELEASE-NOTES).
+
* docutils/languages/
docutils/parsers/rst/languages/
Modified: trunk/docutils/docs/user/config.txt
===================================================================
--- trunk/docutils/docs/user/config.txt 2023-02-07 14:24:19 UTC (rev 9327)
+++ trunk/docutils/docs/user/config.txt 2023-02-07 14:24:37 UTC (rev 9328)
@@ -420,6 +420,21 @@
.. _class attribute: ../ref/doctree.html#classes
+
+output
+------
+
+The name of the output destination. Use ``-`` for stdout.
+
+Obsoletes the ``<destination>`` positional argument
+(cf. `Future changes`_ in the RELEASE-NOTES).
+
+Default: None (stdout). Option: ``--output``.
+
+New in Docutils 0.20.
+
+.. _Future changes: ../../RELEASE-NOTES.html#future-changes
+
output_encoding
---------------
Modified: trunk/docutils/docutils/core.py
===================================================================
--- trunk/docutils/docutils/core.py 2023-02-07 14:24:19 UTC (rev 9327)
+++ trunk/docutils/docutils/core.py 2023-02-07 14:24:37 UTC (rev 9328)
@@ -192,9 +192,16 @@
def set_destination(self, destination=None, destination_path=None):
if destination_path is None:
- destination_path = self.settings._destination
- else:
- self.settings._destination = destination_path
+ if (self.settings.output and self.settings._destination
+ and self.settings.output != self.settings._destination):
+ raise SystemExit('The positional argument <destination> is '
+ 'obsoleted by the --output option. '
+ 'You cannot use them together.')
+ if self.settings.output == '-': # means stdout
+ self.settings.output = None
+ destination_path = (self.settings.output
+ or self.settings._destination)
+ self.settings._destination = destination_path
self.destination = self.destination_class(
destination=destination, destination_path=destination_path,
encoding=self.settings.output_encoding,
@@ -362,8 +369,8 @@
# TODO: or not to do? cf. https://clig.dev/#help
#
# Display output on success, but keep it brief.
+# Provide a -q option to suppress all non-essential output.
#
-# Provide a -q option to suppress all non-essential output.
# Chain several args as input and use --output or redirection for output:
# argparser.add_argument('source', nargs='+')
#
Modified: trunk/docutils/docutils/frontend.py
===================================================================
--- trunk/docutils/docutils/frontend.py 2023-02-07 14:24:19 UTC (rev 9327)
+++ trunk/docutils/docutils/frontend.py 2023-02-07 14:24:37 UTC (rev 9328)
@@ -461,8 +461,11 @@
settings_spec = (
'General Docutils Options',
None,
- (('Specify the document title as metadata.',
- ['--title'], {}),
+ (('Output destination name. Obsoletes the <destination> '
+ 'positional argument. Default: None (stdout).',
+ ['--output'], {'metavar': '<destination>'}),
+ ('Specify the document title as metadata.',
+ ['--title'], {'metavar': '<title>'}),
('Include a "Generated by Docutils" credit and link.',
['--generator', '-g'], {'action': 'store_true',
'validator': validate_boolean}),
Modified: trunk/docutils/test/data/help/docutils.txt
===================================================================
--- trunk/docutils/test/data/help/docutils.txt 2023-02-07 14:24:19 UTC (rev 9327)
+++ trunk/docutils/test/data/help/docutils.txt 2023-02-07 14:24:37 UTC (rev 9328)
@@ -11,7 +11,9 @@
=======
General Docutils Options
------------------------
---title=TITLE Specify the document title as metadata.
+--output=<destination> Output destination name. Obsoletes the <destination>
+ positional argument. Default: None (stdout).
+--title=<title> Specify the document title as metadata.
--generator, -g Include a "Generated by Docutils" credit and link.
--no-generator Do not include a generator credit.
--date, -d Include the date at the end of the document (UTC).
Modified: trunk/docutils/test/data/help/rst2html.txt
===================================================================
--- trunk/docutils/test/data/help/rst2html.txt 2023-02-07 14:24:19 UTC (rev 9327)
+++ trunk/docutils/test/data/help/rst2html.txt 2023-02-07 14:24:37 UTC (rev 9328)
@@ -12,7 +12,9 @@
=======
General Docutils Options
------------------------
---title=TITLE Specify the document title as metadata.
+--output=<destination> Output destination name. Obsoletes the <destination>
+ positional argument. Default: None (stdout).
+--title=<title> Specify the document title as metadata.
--generator, -g Include a "Generated by Docutils" credit and link.
--no-generator Do not include a generator credit.
--date, -d Include the date at the end of the document (UTC).
Modified: trunk/docutils/test/data/help/rst2latex.txt
===================================================================
--- trunk/docutils/test/data/help/rst2latex.txt 2023-02-07 14:24:19 UTC (rev 9327)
+++ trunk/docutils/test/data/help/rst2latex.txt 2023-02-07 14:24:37 UTC (rev 9328)
@@ -12,7 +12,9 @@
=======
General Docutils Options
------------------------
---title=TITLE Specify the document title as metadata.
+--output=<destination> Output destination name. Obsoletes the <destination>
+ positional argument. Default: None (stdout).
+--title=<title> Specify the document title as metadata.
--generator, -g Include a "Generated by Docutils" credit and link.
--no-generator Do not include a generator credit.
--date, -d Include the date at the end of the document (UTC).
Modified: trunk/docutils/test/test_publisher.py
===================================================================
--- trunk/docutils/test/test_publisher.py 2023-02-07 14:24:19 UTC (rev 9327)
+++ trunk/docutils/test/test_publisher.py 2023-02-07 14:24:37 UTC (rev 9328)
@@ -19,7 +19,7 @@
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import docutils
-from docutils import core, nodes, io
+from docutils import core, nodes
# DATA_ROOT is ./test/data/ from the docutils root
DATA_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
@@ -75,11 +75,30 @@
def test_output_error_handling(self):
# pass IOErrors to calling application if `traceback` is True
- with self.assertRaises(io.OutputError):
+ with self.assertRaises(docutils.io.OutputError):
core.publish_cmdline(argv=[os.path.join(DATA_ROOT, 'include.txt'),
'nonexisting/path'],
settings_overrides={'traceback': True})
+ def test_set_destination(self):
+ # Exit if `_destination` and `output` settings conflict.
+ publisher = core.Publisher()
+ publisher.get_settings(output='out_name', _destination='out_name')
+ # no conflict if both have same value:
+ publisher.set_destination()
+ # no conflict if both are overridden:
+ publisher.set_destination(destination_path='winning_dest')
+ # ... also sets _destination to 'winning_dest' -> conflict
+ with self.assertRaises(SystemExit):
+ publisher.set_destination()
+
+ def test_destination_output_conflict(self):
+ # Exit if positional argument and --output option conflict.
+ settings = {'output': 'out_name'}
+ with self.assertRaises(SystemExit):
+ core.publish_cmdline(argv=['-', 'dest_name'],
+ settings_overrides=settings)
+
def test_publish_string(self):
# Transparently decode `bytes` source (with "input_encoding" setting)
# default: auto-detect, fallback utf-8
@@ -107,7 +126,7 @@
settings_default_overrides = {
'_disable_config': True,
- 'warning_stream': io.NullOutput()}
+ 'warning_stream': docutils.io.NullOutput()}
def test_publish_doctree(self):
# Test `publish_doctree` and `publish_from_doctree`.
@@ -144,7 +163,7 @@
# Test publishing parts using document as the source.
parts = core.publish_parts(
- reader_name='doctree', source_class=io.DocTreeInput,
+ reader_name='doctree', source_class=docutils.io.DocTreeInput,
source=doctree, source_path='test', writer_name='html',
settings_spec=self)
self.assertTrue(isinstance(parts, dict))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|