Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sphinx argparse #1581

Merged
merged 7 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ jobs:
run: |
python3 -m pip install ruamel.yaml scons numpy cython sphinx==5.1.1 \
sphinxcontrib-matlabdomain sphinxcontrib-doxylink pint \
pydata-sphinx-theme==0.13.3
pydata-sphinx-theme==0.13.3 sphinx-argparse
- name: Build Cantera with documentation
run: python3 `which scons` build -j2 doxygen_docs=y sphinx_docs=y debug=n optimize=n use_pch=n
- name: Ensure 'scons help' options work
Expand Down
1 change: 1 addition & 0 deletions doc/sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.autosummary',
'sphinxarg.ext',
'sphinxcontrib.doxylink',
'sphinx.ext.intersphinx',
]
Expand Down
11 changes: 11 additions & 0 deletions doc/sphinx/cython/ck_conversion.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
**************************
Chemkin to YAML conversion
**************************

For documentation and tutorial, refer to the `Converting Chemkin-format files
<https://cantera.org/tutorials/ck2yaml-tutorial.html>`_ pages.

Module-level documentation
==========================

.. automodule:: cantera.ck2yaml
12 changes: 12 additions & 0 deletions doc/sphinx/cython/cti_conversion.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
***********************
CTI to YAML conversion
***********************

For documentation of the command line interface, see the :ref:`cti2yaml <sec-cti2yaml>`
section. For a tutorial, refer to the `Converting CTI and XML input files to YAML
<https://cantera.org/tutorials/legacy2yaml.html>`_ pages.

Module-level documentation
==========================

.. automodule:: cantera.cti2yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
CTML to YAML conversion
***********************

For documentation of the command line interface, see the :ref:`cml2yaml <sec-ctml2yaml>`
section. For a tutorial, refer to the `Converting CTI and XML input files to YAML
<https://cantera.org/tutorials/legacy2yaml.html>`_ pages.


Module-level documentation
==========================

.. py:module:: cantera.ctml2yaml
.. py:currentmodule:: cantera.ctml2yaml

Expand All @@ -16,7 +24,7 @@ processed, while `convert` takes an input filename or a string containing the CT
to be converted, and optionally the name of the output file.

Module-level functions
======================
----------------------

.. autofunction:: float2string
.. autofunction:: represent_float
Expand All @@ -30,7 +38,7 @@ Module-level functions
.. autofunction:: main

Conversion classes
==================
------------------

.. autoclass:: Phase
:no-undoc-members:
Expand All @@ -44,7 +52,7 @@ Conversion classes
:no-undoc-members:

Exceptions
==========
----------

.. autoexception:: MissingXMLNode
.. autoexception:: MissingXMLAttribute
Expand Down
1 change: 1 addition & 0 deletions doc/sphinx/cython/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Contents:
constants
units
utilities
scripts
14 changes: 14 additions & 0 deletions doc/sphinx/cython/scripts.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. _sec-converter-documentation:

Mechanism Conversion
====================

Contents:

.. toctree::
:maxdepth: 1

ck_conversion
cti_conversion
ctml_conversion
yaml_conversion
ischoegl marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 10 additions & 0 deletions doc/sphinx/cython/yaml_conversion.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**************************
YAML to Chemkin conversion
**************************

For documentation of the command line interface, see :ref:`sec-yaml2ck`.

Module-level documentation
==========================

.. automodule:: cantera.yaml2ck
7 changes: 7 additions & 0 deletions doc/sphinx/yaml/ck2yaml.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**************************
Chemkin to YAML conversion
**************************

.. note::
For documentation and tutorial, refer to the `Converting Chemkin-format files
<https://cantera.org/tutorials/ck2yaml-tutorial.html>`_ pages.
5 changes: 0 additions & 5 deletions doc/sphinx/yaml/ck_conversion.rst

This file was deleted.

14 changes: 14 additions & 0 deletions doc/sphinx/yaml/cti2yaml.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. _sec-cti2yaml:

***********************
CTI to YAML conversion
***********************

.. note::
For a tutorial, refer to the `Converting CTI and XML input files to YAML
<https://cantera.org/tutorials/legacy2yaml.html>`_ pages.

.. argparse::
:module: cantera.cti2yaml
:func: create_argparser
:prog: cti2yaml
5 changes: 0 additions & 5 deletions doc/sphinx/yaml/cti_conversion.rst

This file was deleted.

14 changes: 14 additions & 0 deletions doc/sphinx/yaml/ctml2yaml.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. _sec-ctml2yaml:

***********************
CTML to YAML conversion
***********************

.. note::
For a tutorial, refer to the `Converting CTI and XML input files to YAML
<https://cantera.org/tutorials/legacy2yaml.html>`_ pages.

.. argparse::
:module: cantera.ctml2yaml
:func: create_argparser
:prog: ctml2yaml
7 changes: 4 additions & 3 deletions doc/sphinx/yaml/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ YAML Input File Reference
elements
species
reactions
cti_conversion
ctml_conversion
ck_conversion
ck2yaml
cti2yaml
ctml2yaml
yaml2ck
10 changes: 10 additions & 0 deletions doc/sphinx/yaml/yaml2ck.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _sec-yaml2ck:

**************************
YAML to Chemkin conversion
**************************

.. argparse::
:module: cantera.yaml2ck
:func: create_argparser
:prog: yaml2ck
6 changes: 3 additions & 3 deletions interfaces/cython/cantera/ck2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
return repr(data)

def represent_float(self, data):
# type: (Any) -> Any
if data != data:
value = '.nan'
elif data == self.inf_value:
Expand Down Expand Up @@ -2217,8 +2216,9 @@

if '--id' in options:
phase_name = options.get('--id', 'gas')
logger.warning("\nFutureWarning: "
"Option '--id=...' will be replaced by '--name=...'")
logger.warning("\nDeprecationWarning: "

Check warning on line 2219 in interfaces/cython/cantera/ck2yaml.py

View check run for this annotation

Codecov / codecov/patch

interfaces/cython/cantera/ck2yaml.py#L2219

Added line #L2219 was not covered by tests
"Option '--id=...' is replaced by '--name=...' and will be "
"removed after Cantera 3.0.\n")
else:
phase_name = options.get('--name', 'gas')

Expand Down
12 changes: 10 additions & 2 deletions interfaces/cython/cantera/cti2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1720,8 +1720,10 @@
return len(_species), len(_reactions), surfaces, output_name


def main():
"""Parse command line arguments and pass them to `convert`."""
def create_argparser():
"""
Create argparse parser
"""
parser = argparse.ArgumentParser(
description=(
"Convert legacy CTI input files to YAML format, where the first contiguous "
Expand All @@ -1743,6 +1745,12 @@
"--no-validate", action="store_true", default=False,
help="Skip validation step.")

return parser

Check warning on line 1748 in interfaces/cython/cantera/cti2yaml.py

View check run for this annotation

Codecov / codecov/patch

interfaces/cython/cantera/cti2yaml.py#L1748

Added line #L1748 was not covered by tests


def main():
"""Parse command line arguments and pass them to `convert`."""
parser = create_argparser()

Check warning on line 1753 in interfaces/cython/cantera/cti2yaml.py

View check run for this annotation

Codecov / codecov/patch

interfaces/cython/cantera/cti2yaml.py#L1753

Added line #L1753 was not covered by tests
if len(sys.argv) not in [2, 3, 4, 5]:
if len(sys.argv) > 5:
print(
Expand Down
13 changes: 11 additions & 2 deletions interfaces/cython/cantera/ctml2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2652,8 +2652,10 @@
emitter.dump(output_reactions, output_file)


def main():
"""Parse command line arguments and pass them to `convert`."""
def create_argparser():
"""
Create argparse parser
"""
parser = argparse.ArgumentParser(
description="Convert legacy CTML input files to YAML format",
epilog=(
Expand All @@ -2664,6 +2666,13 @@
)
parser.add_argument("input", help="The input CTML filename. Must be specified.")
parser.add_argument("output", nargs="?", help="The output YAML filename. Optional.")

return parser

Check warning on line 2670 in interfaces/cython/cantera/ctml2yaml.py

View check run for this annotation

Codecov / codecov/patch

interfaces/cython/cantera/ctml2yaml.py#L2670

Added line #L2670 was not covered by tests


def main():
"""Parse command line arguments and pass them to `convert`."""
parser = create_argparser()

Check warning on line 2675 in interfaces/cython/cantera/ctml2yaml.py

View check run for this annotation

Codecov / codecov/patch

interfaces/cython/cantera/ctml2yaml.py#L2675

Added line #L2675 was not covered by tests
if len(sys.argv) not in [2, 3]:
if len(sys.argv) > 3:
print(
Expand Down
16 changes: 11 additions & 5 deletions interfaces/cython/cantera/yaml2ck.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,10 @@
return output_files


def main():
def create_argparser():
"""
Parse command line arguments and pass them to `convert`

.. versionadded:: 3.0
Create argparse parser
"""

parser = argparse.ArgumentParser(
description="Convert Cantera YAML input files to Chemkin-format mechanisms",
)
Expand Down Expand Up @@ -795,7 +792,16 @@
default=True,
help="Check that the mechanism can be loaded back into Cantera.",
)
return parser

Check warning on line 795 in interfaces/cython/cantera/yaml2ck.py

View check run for this annotation

Codecov / codecov/patch

interfaces/cython/cantera/yaml2ck.py#L795

Added line #L795 was not covered by tests


def main():
"""
Parse command line arguments and pass them to `convert`

.. versionadded:: 3.0
"""
parser = create_argparser()

Check warning on line 804 in interfaces/cython/cantera/yaml2ck.py

View check run for this annotation

Codecov / codecov/patch

interfaces/cython/cantera/yaml2ck.py#L804

Added line #L804 was not covered by tests
args = parser.parse_args()

output_paths = convert(
Expand Down
Loading