Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOGS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change Logs
0.3.0
+++++

* :pr:`28`: add syntax to check the readme syntax
* :pr:`27`: fix missing __text_signature__ in docassert

0.2.0
Expand Down
19 changes: 18 additions & 1 deletion _doc/api/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@
tools
=====


Checks the readme syntax
========================

The command line checks the readme syntax in virtual environments.

::

python -m sphinx_runpython readme -p <path_to_readme.rst> -v

It is based on function:

.. autofunction:: sphinx_runpython.readme.check_readme_syntax

However, it is better to run command line ``twine check dist/*``
assuming the whl was built by a command such as ``python setup.py sdist``.

Convert notebooks into examples
===============================

The command line converts every notebook in a folder
into exmaples which can be used into a sphinx gallery.
into examples which can be used into a sphinx gallery.

::

Expand Down
32 changes: 32 additions & 0 deletions _unittests/ut__main/test_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import unittest
import sys
from io import StringIO
from contextlib import redirect_stdout
from tempfile import TemporaryDirectory
from sphinx_runpython.ext_test_case import ExtTestCase
from sphinx_runpython.readme import check_readme_syntax


class TestReadme(ExtTestCase):
@unittest.skipIf(
sys.platform == "win32", reason="Fails on windows due to tempoerary path"
)
def test_venv_docutils08_readme(self):
fold = os.path.dirname(os.path.abspath(__file__))
readme = os.path.join(fold, "..", "..", "README.rst")
assert os.path.exists(readme)
with open(readme, "r", encoding="utf8") as f:
content = f.read()
self.assertNotEmpty(content)

with TemporaryDirectory() as temp:
st = StringIO()
with redirect_stdout(st):
check_readme_syntax(readme, folder=temp, verbose=1)
text = st.getvalue()
print(text)


if __name__ == "__main__":
unittest.main()
18 changes: 15 additions & 3 deletions sphinx_runpython/_cmd_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import glob
import os
from argparse import ArgumentParser
from tempfile import TemporaryDirectory
from .convert import convert_ipynb_to_gallery


Expand All @@ -10,12 +11,17 @@ def get_parser():
description="A collection of quick tools.",
epilog="",
)
parser.add_argument("command", help="Command to run, only nb2py is available")
parser.add_argument(
"-p", "--path", help="Folder which contains the files to process"
"command", help="Command to run, only 'nb2py' or 'readme' are available"
)
parser.add_argument(
"-r", "--recursive", help="Recursive search.", action="store_true"
"-p", "--path", help="Folder or file which contains the files to process"
)
parser.add_argument(
"-r",
"--recursive",
help="Recursive search.",
action="store_true",
)
parser.add_argument("-v", "--verbose", help="verbosity", default=1, type=int)
return parser
Expand All @@ -41,6 +47,12 @@ def process_args(args):
if cmd == "nb2py":
nb2py(args.path, recursive=args.recursive, verbose=args.verbose)
return
if cmd == "readme":
from .readme import check_readme_syntax

with TemporaryDirectory() as temp:
check_readme_syntax(args.path, verbose=args.verbose, folder=temp)
return
raise ValueError(f"Command {cmd!r} is unknown.")


Expand Down
Loading