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

Simplify and improve template #8

Merged
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
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
18 changes: 17 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,27 @@ 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: |
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
displayName: 'Configure git'

- bash: |
python -m cookiecutter --no-input --output-dir "$(Agent.BuildDirectory)" "$(Build.SourcesDirectory)"
displayName: 'Evaluate template'

- bash: |
python tests/test_template_evaluation.py "$(Agent.BuildDirectory)/ndx-my-namespace/" "ndx-my-namespace"
displayName: 'Check files'

- bash: |
set -e
cd "$(Agent.BuildDirectory)/ndx-my-namespace/docs"
make apidoc
make html
displayName: 'Build documentation'


3 changes: 2 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"github_name": "myname",
"copyright": "2019, {{ cookiecutter.author }}",
"version": "0.1.0",
"release": "alpha"
"release": "alpha",
"py_pkg_name": "{{ cookiecutter.namespace|replace('-', '_') }}"
}
36 changes: 36 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os
import shutil
import sys
import textwrap

from nwb_docutils.init_sphinx_extension_doc import main as init_sphinx_extension_doc
from subprocess import check_call


def _select_dev_language():
dev_language = '{{ cookiecutter.dev_language }}'
Expand All @@ -11,11 +15,43 @@ 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 _create_extension_spec():
spec_dir = "src/spec"
sys.path.insert(0, spec_dir)
check_call([sys.executable, spec_dir + "/create_extension_spec.py"])


def _initialize_git():
check_call(["git", "init"])
check_call(["git", "add", "-A"])
check_call(["git", "commit", "-m", "Initial commit"])


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

_select_dev_language()
_generate_doc()
_create_extension_spec()
_initialize_git()

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

import os
import sys


def test_post_gen_project_hook(project_dir, namespace):
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",
# Generated using "src/spec/create_extension_spec.py"
"spec/%s.extensions.yaml" % namespace,
"spec/%s.namespace.yaml" % namespace,
]:
expected_file = os.path.join(project_dir, expected_file)
assert os.path.exists(expected_file)

with open(expected_file, "r") as fp:
assert fp.read().strip() != ""


if __name__ == "__main__":
test_post_gen_project_hook(sys.argv[1], sys.argv[2])
3 changes: 3 additions & 0 deletions {{ cookiecutter.namespace }}/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ docs/source/_format_auto_docs
docs/source/_static
!docs/source/_static/theme_overrides.css

# copied spec files
src/pynwb/{{ cookiecutter.py_pkg_name }}/spec/*.yaml

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
11 changes: 11 additions & 0 deletions {{ cookiecutter.namespace }}/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include LICENSE.txt
include README.md
include requirements.txt

include spec/*.yaml

recursive-include tests *
recursive-exclude * __pycache__
recursive-exclude * *.py[co]

recursive-include docs *.css *.rst conf.py conf_doc_autogen.py Makefile make.bat README.md
11 changes: 5 additions & 6 deletions {{ cookiecutter.namespace }}/NEXTSTEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ use any dependencies.
<sup>1</sup>: To ensure the YAML files are distributed with your extension, make sure to
update `setup.py` setting the `package_data` and `include_package_data` keyword parameters:
```python
setup(
setup_args = {
# [...]
package_data={'': [
'{{ cookiecutter.namespace }}.namespace.yaml',
'{{ cookiecutter.namespace }}.extensions.yaml'
'package_data': {'{{ cookiecutter.py_pkg_name }}': [
'spec/{{ cookiecutter.namespace }}.namespace.yaml',
'spec/{{ cookiecutter.namespace }}.extensions.yaml',
]},
include_package_data=True
)
}
```


Expand Down
179 changes: 0 additions & 179 deletions {{ cookiecutter.namespace }}/docs/Makefile

This file was deleted.

Loading