Skip to content

Commit

Permalink
Use pyproject.toml, hatch, importlib, black, cookiecutter prompts (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
rly authored Oct 16, 2023
1 parent d6380d2 commit 4d3ef6e
Show file tree
Hide file tree
Showing 21 changed files with 574 additions and 364 deletions.
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

164 changes: 164 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
.ruff_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Mac finder
.DS_Store
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This repo provides a template for creating Neurodata Extensions (NDX) for the
[Neurodata Without Borders](https://nwb.org/)
data standard.

We currently support creating Neurodata Extensions only using Python.
We currently support creating Neurodata Extensions only using Python 3.8+.
MATLAB support is in development.

## Getting started
Expand All @@ -24,6 +24,12 @@ python -m pip install -U cookiecutter pynwb hdmf-docutils
```bash
cookiecutter gh:nwb-extensions/ndx-template
```

To overwrite the contents of an existing directory, use the `--overwrite-if-exists` flag:
```bash
cookiecutter --overwrite-if-exists gh:nwb-extensions/ndx-template
```
This can be useful if you want to populate an existing empty git repository with a new extension.
4. Answer the prompts, which will be used to fill in the blanks throughout the
template automatically. You will be prompted for:
- `namespace` - The name of the namespace for your extension. This could be a
Expand Down
17 changes: 5 additions & 12 deletions azure-pipelines-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
imageName: 'ubuntu-20.04'
pythonVersion: '3.10'

macOS-py3.10:
imageName: 'macos-10.15'
pythonVersion: '3.10'
# macOS-py3.10:
# imageName: 'macos-10.15'
# pythonVersion: '3.10'

Windows-py3.10:
imageName: 'windows-2019'
Expand All @@ -33,12 +33,6 @@ jobs:
Windows-py3.8:
imageName: 'windows-2019'
pythonVersion: '3.8'
Windows-py3.7:
imageName: 'windows-2019'
pythonVersion: '3.7'
Windows-py3.6:
imageName: 'windows-2019'
pythonVersion: '3.6'

pool:
vmImage: $(imageName)
Expand All @@ -55,8 +49,7 @@ jobs:

- script: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install cookiecutter "pynwb>=1.5.0" "hdmf-docutils>=0.4.4"
python -m pip install --upgrade cookiecutter pynwb hdmf-docutils
displayName: 'Install build dependencies'
- bash: |
Expand All @@ -75,7 +68,7 @@ jobs:
- bash: |
cd "$(Agent.BuildDirectory)/ndx-my-namespace"
python setup.py install
python -m pip install .
python -m unittest src/pynwb/tests/test_tetrodeseries.py
displayName: 'Run PyNWB test'
Expand Down
17 changes: 5 additions & 12 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
imageName: 'ubuntu-20.04'
pythonVersion: '3.10'

macOS-py3.10:
imageName: 'macos-10.15'
pythonVersion: '3.10'
# macOS-py3.10:
# imageName: 'macos-10.15'
# pythonVersion: '3.10'

Windows-py3.10:
imageName: 'windows-2019'
Expand All @@ -27,12 +27,6 @@ jobs:
Windows-py3.8:
imageName: 'windows-2019'
pythonVersion: '3.8'
Windows-py3.7:
imageName: 'windows-2019'
pythonVersion: '3.7'
Windows-py3.6:
imageName: 'windows-2019'
pythonVersion: '3.6'

pool:
vmImage: $(imageName)
Expand All @@ -49,8 +43,7 @@ jobs:

- script: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install cookiecutter "pynwb>=1.5.0" "hdmf-docutils>=0.4.4"
python -m pip install --upgrade cookiecutter pynwb hdmf-docutils
displayName: 'Install build dependencies'
- bash: |
Expand All @@ -68,7 +61,7 @@ jobs:
- bash: |
cd "$(Agent.BuildDirectory)/ndx-my-namespace"
python setup.py install
python -m pip install .
python -m unittest src/pynwb/tests/test_tetrodeseries.py
displayName: 'Run PyNWB test'
Expand Down
17 changes: 16 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,20 @@
"version": "0.1.0",
"release": "alpha",
"license": ["BSD-3", "MIT", "Apache Software License 2.0", "Other"],
"py_pkg_name": "{{ cookiecutter.namespace|replace('-', '_') }}"
"py_pkg_name": "{{ cookiecutter.namespace|replace('-', '_') }}",
"initialize_git": true,
"_extensions": ["local_extensions.ZipExtension"],
"__prompts__": {
"namespace": "Select a name for your extension. It must start with 'ndx-'",
"description": "Describe your extension",
"author": "Enter your full name or a comma-separated list of names",
"email": "Enter your email address or a comma-separated list of email addresses",
"github_username": "Enter your GitHub username or a comma-separated list of usernames",
"copyright": "Copyright",
"version": "Select an initial version string",
"release": "Select an initial release level",
"license": "Select a license",
"py_pkg_name": "Select a name for the Python package",
"initialize_git": "Initialize a git repository?"
}
}
58 changes: 33 additions & 25 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import sys
import textwrap

from hdmf_docutils.init_sphinx_extension_doc import main as init_sphinx_extension_doc
from subprocess import check_call, CalledProcessError
from subprocess import check_call
import sys


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",
])
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():
Expand All @@ -34,20 +44,18 @@ def _initialize_git():


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

_generate_doc()
_create_extension_spec()
_initialize_git()
if "{{ cookiecutter.initialize_git }}" == "True":
_initialize_git()

print(textwrap.dedent(
"""
Success! Directory {{ cookiecutter.namespace }} was created with a skeleton for your new NWB extension.
Please see {{ cookiecutter.namespace }}/NEXTSTEPS.md for creating and publishing your extension.
print(
"""
))
Success! Directory {{ cookiecutter.namespace }} was created with a skeleton for your new NWB extension.
Please see {{ cookiecutter.namespace }}/NEXTSTEPS.md for creating and publishing your extension."""
)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 4d3ef6e

Please sign in to comment.