Skip to content

Commit

Permalink
Replace not windows supported sed with nox workflow and template
Browse files Browse the repository at this point in the history
  • Loading branch information
insspb committed Jun 7, 2022
1 parent 94631a8 commit ac047dc
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 14 deletions.
14 changes: 3 additions & 11 deletions Makefile
Expand Up @@ -60,21 +60,13 @@ coverage: ## Check code coverage quickly with the default Python
.PHONY: docs
docs: ## Generate Sphinx HTML documentation, including API docs
@echo "+ $@"
@rm -f docs/cookiecutter.rst
@sphinx-apidoc -o docs/ cookiecutter
@rm -f docs/modules.rst
@sed -i 's/cookiecutter package/===\nAPI\n===/' docs/cookiecutter.rst
@sed -i 's/====================//' docs/cookiecutter.rst
@sed -i 's/Submodules/This is the Cookiecutter modules API documentation./' docs/cookiecutter.rst
@sed -i 's/^----------$$//' docs/cookiecutter.rst
@$(MAKE) -C docs clean
@$(MAKE) -C docs html
@nox --non-interactive -s docs
@$(BROWSER) docs/_build/html/index.html

.PHONY: servedocs
servedocs: docs ## Rebuild docs automatically
servedocs: ## Rebuild docs automatically
@echo "+ $@"
@watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .
@nox -s docs

.PHONY: submodules
submodules: ## Pull and update git submodules recursively
Expand Down
51 changes: 51 additions & 0 deletions docs/_templates/package.rst_t
@@ -0,0 +1,51 @@
{%- macro automodule(modname, options) -%}
.. automodule:: {{ modname }}
{%- for option in options %}
:{{ option }}:
{%- endfor %}
{%- endmacro %}
{%- macro toctree(docnames) -%}
.. toctree::
:maxdepth: {{ maxdepth }}
{% for docname in docnames %}
{{ docname }}
{%- endfor %}
{%- endmacro -%}
===
API
===


{%- if modulefirst and not is_namespace %}
{{ automodule(pkgname, automodule_options) }}
{% endif %}

{%- if subpackages %}
Subpackages
-----------

{{ toctree(subpackages) }}
{% endif %}

{%- if submodules %}

This is the Cookiecutter modules API documentation.

{% if separatemodules %}
{{ toctree(submodules) }}
{% else %}
{%- for submodule in submodules %}
{% if show_headings %}
{{- [submodule, "module"] | join(" ") | e | heading(2) }}
{% endif %}
{{ automodule(submodule, automodule_options) }}
{% endfor %}
{%- endif %}
{%- endif %}

{%- if not modulefirst and not is_namespace %}
Module contents
---------------

{{ automodule(pkgname, automodule_options) }}
{% endif %}
6 changes: 6 additions & 0 deletions docs/conf.py
Expand Up @@ -54,6 +54,7 @@
'sphinx.ext.viewcode',
'sphinx_click.ext',
'myst_parser',
'sphinxcontrib.apidoc',
]

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -359,3 +360,8 @@
"fieldlist",
]
myst_heading_anchors = 3
# Apidoc extension config
apidoc_module_dir = "../cookiecutter"
apidoc_output_dir = "."
apidoc_toc_file = False
apidoc_extra_args = ["-t", "_templates"]
1 change: 0 additions & 1 deletion docs/cookiecutter.rst
Expand Up @@ -2,7 +2,6 @@
API
===


This is the Cookiecutter modules API documentation.


Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
@@ -1,6 +1,6 @@
watchdog>=0.10.2
sphinx-rtd-theme>=1.0.0
sphinx-click>=4.1.0
myst-parser>=0.17.2
sphinx-autobuild>=2021.3.14
Sphinx>=4.0.1
sphinxcontrib-apidoc>=0.3.0
5 changes: 4 additions & 1 deletion noxfile.py
Expand Up @@ -2,6 +2,9 @@
Nox is Tox tool replacement.
"""
import shutil
from pathlib import Path

import nox

nox.options.keywords = "not docs"
Expand Down Expand Up @@ -50,7 +53,7 @@ def documentation_tests(session):
@nox.session(python="3.10")
def docs(session, batch_run: bool = False):
"""Build the documentation or serve documentation interactively."""
session.run("rm", "-rf", "docs/_build", external=True)
shutil.rmtree(Path("docs").joinpath("_build"), ignore_errors=True)
session.install("-r", "docs/requirements.txt")
session.install(".")
session.cd("docs")
Expand Down

0 comments on commit ac047dc

Please sign in to comment.