Skip to content

Commit

Permalink
Simplify template maintenance generating docs using nwb-docutils
Browse files Browse the repository at this point in the history
  • Loading branch information
jcfr committed May 19, 2019
1 parent fa36bce commit 014182f
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 743 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ MATLAB support is in development.

## Getting started

1. Install [cookiecutter](https://pypi.org/project/cookiecutter/), a Python-based
command-line utility that creates projects from templates:
1. Install [cookiecutter](https://pypi.org/project/cookiecutter/) and [nwb-docutils](https://pypi.org/project/nwb-docutils/).
`cookiecutter` is a Python-based command-line utility that creates projects from templates.
```bash
python -m pip install cookiecutter
python -m pip install cookiecutter "nwb-docutils>=0.3.1"
```
2. Run cookiecutter on your local working directory:
```bash
Expand Down
3 changes: 2 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ jobs:
- script: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install cookiecutter
python -m pip install cookiecutter "nwb-docutils>=0.3.1"
displayName: 'Install build dependencies'
- bash: |
python -m cookiecutter --no-input --output-dir "$(Agent.BuildDirectory)" "$(Build.SourcesDirectory)"
python tests/test_template_evaluation.py "$(Build.BuildDirectory)/ndx-my-namespace/"
displayName: 'Evaluate template'
20 changes: 20 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import shutil
import textwrap

from nwb_docutils.init_sphinx_extension_doc import main as init_sphinx_extension_doc


def _select_dev_language():
dev_language = '{{ cookiecutter.dev_language }}'
Expand All @@ -11,11 +13,29 @@ def _select_dev_language():
shutil.rmtree(os.path.join(os.getcwd(), 'src', 'matnwb'))


def _generate_doc():
init_sphinx_extension_doc([
"--project", "{{ cookiecutter.namespace }}",
"--author", "{{ cookiecutter.author }}",
"--version", "{{ cookiecutter.version }}",
"--release", "{{ cookiecutter.release }}",
"--output", "docs",
"--spec_dir", "spec",
"--namespace_filename", "{{ cookiecutter.namespace }}.namespace.yaml",
"--default_namespace", "{{ cookiecutter.namespace }}",
"--custom_description", "description.rst",
"--custom_release_notes", "release_notes.rst",
])


def main():
"""
Runs the post gen project hook main entry point.
"""

_select_dev_language()
_generate_doc()

print(textwrap.dedent(
"""
Success! Directory {{ cookiecutter.namespace }} was created with a skeleton for your new NWB:N extension.
Expand Down
26 changes: 26 additions & 0 deletions tests/test_template_evaluation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import os
import sys


def test_post_gen_project_hook(project_dir):
for expected_file in [
# Generated using init_sphinx_extension_doc
"docs/Makefile",
"docs/README.md",
"docs/make.bat",
"docs/source/_static/theme_overrides.css",
"docs/source/conf.py",
"docs/source/conf_doc_autogen.py",
"docs/source/credits.rst",
"docs/source/description.rst",
"docs/source/format.rst",
"docs/source/index.rst",
"docs/source/release_notes.rst",
]:
expected_file = os.path.join(project_dir, expected_file)
assert os.path.exists(expected_file)


if __name__ == "__main__":
test_post_gen_project_hook(sys.argv[1])
179 changes: 0 additions & 179 deletions {{ cookiecutter.namespace }}/docs/Makefile

This file was deleted.

121 changes: 0 additions & 121 deletions {{ cookiecutter.namespace }}/docs/README.md

This file was deleted.

Loading

0 comments on commit 014182f

Please sign in to comment.