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

👌 Refresh template plugin #88

Merged
merged 3 commits into from
Jan 18, 2022
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
.DS_Store
aiida-diff/
.pytest_cache/
aiida-ck/
.tox/
.vscode/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See the [`support/aiida-0.x` branch](https://github.com/aiidateam/aiida-plugin-c

## Usage instructions

pip install cookiecutter yapf
pip install cookiecutter black
cookiecutter https://github.com/aiidateam/aiida-plugin-cutter.git

![Demo](https://image.ibb.co/ct6rL8/aiida_plugin_cutter.gif "The fastest way to kickstart an AiiDA plugin.")
Expand Down
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"version": "0.1.0a0",
"author": "The AiiDA Team",
"aiida_min_version": "1.1.0",
"year": "2020"
"year": "2022"
}
8 changes: 4 additions & 4 deletions hooks/post_gen_project.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
if [ -x "$(command -v yapf)" ]; then
echo "Running yapf on {{ cookiecutter.plugin_name }}"
yapf -i -r '../{{ cookiecutter.plugin_name }}/'
if [ -x "$(command -v black)" ]; then
echo "Running black on {{ cookiecutter.plugin_name }}"
black '../{{ cookiecutter.plugin_name }}/'
else
echo "yapf not found. 'pip install yapf' to automatically \
echo "black not found. 'pip install black' to automatically \
run formatter on {{ cookiecutter.plugin_name }}"
fi

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cookiecutter
yapf==0.30.0
black==21.12b0
23 changes: 23 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[tox]
envlist = build

[testenv]
basepython = python3
skip_install = true

[testenv:build]
description = Build a package from the template and install
deps = -rrequirements.txt
setenv =
PLUGIN_NAME = aiida-ck
whitelist_externals =
cd
git
rm
commands =
rm -rf {env:PLUGIN_NAME}
cookiecutter --no-input . plugin_name={env:PLUGIN_NAME}
git init -b main {env:PLUGIN_NAME}
cd {env:PLUGIN_NAME} && git add -A
pip install -e {env:PLUGIN_NAME}[testing,docs,pre-commit]
reentry scan -r aiida
2 changes: 0 additions & 2 deletions {{cookiecutter.plugin_name}}/.coveragerc

This file was deleted.

37 changes: 0 additions & 37 deletions {{cookiecutter.plugin_name}}/.github/check_version.py

This file was deleted.

8 changes: 4 additions & 4 deletions {{cookiecutter.plugin_name}}/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
timeout-minutes: 30
strategy:
matrix:
python-version: [3.8]
python-version: ["3.8"]
backend: ['django']

services:
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
AIIDA_TEST_BACKEND: ${{ '{{ matrix.backend }}' }}
# show timings of tests
PYTEST_ADDOPTS: "--durations=0"
run: py.test --cov {{cookiecutter.module_name}} --cov-append .
run: pytest --cov {{cookiecutter.module_name}} --cov-append .

docs:
runs-on: ubuntu-latest
Expand All @@ -60,7 +60,7 @@ jobs:
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: "3.8"
- name: Install python dependencies
run: |
pip install --upgrade pip
Expand All @@ -77,7 +77,7 @@ jobs:
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: "3.8"
- name: Install python dependencies
run: |
pip install --upgrade pip
Expand Down
25 changes: 9 additions & 16 deletions {{cookiecutter.plugin_name}}/.github/workflows/publish-on-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,16 @@ jobs:
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: '3.8'

- name: Upgrade setuptools and install package
- name: Install flit
run: |
python -m pip install --upgrade pip setuptools
python -m pip install -e .
python -m pip install --upgrade pip
python -m pip install flit~=3.4

- name: Assert package version
- name: Build and publish
run: |
flit publish
env:
TAG_VERSION: ${{ '{{ github.ref }}' }}
run: python ./.github/check_version.py

- name: Build source distribution
run: python ./setup.py sdist

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ '{{ secrets.pypi_token }}' }}
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ '{{ secrets.pypi_token }}' }}
30 changes: 15 additions & 15 deletions {{cookiecutter.plugin_name}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@
# pre-commit install
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.1.0
hooks:
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: fix-encoding-pragma
- id: mixed-line-ending
- id: trailing-whitespace
- id: check-json

# yapf = yet another python formatter
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.30.0
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
hooks:
- id: yapf
name: yapf
args: ["-i"]
- id: pyupgrade
args: ["--py37-plus"]

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
- id: black

- repo: local
hooks:
Expand All @@ -31,9 +37,3 @@ repos:
docs/.*|
)$
entry: pylint

- id: version-number
name: Check version numbers
entry: python ./.github/check_version.py
language: system
files: '^(setup.json)|({{cookiecutter.module_name}}/__init__.py)'
2 changes: 1 addition & 1 deletion {{cookiecutter.plugin_name}}/.readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2

python:
version: 3.8
version: "3.8"
install:
- method: pip
path: .
Expand Down
2 changes: 0 additions & 2 deletions {{cookiecutter.plugin_name}}/MANIFEST.in

This file was deleted.

27 changes: 16 additions & 11 deletions {{cookiecutter.plugin_name}}/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build Status](https://github.com/{{ cookiecutter.github_user }}/{{ cookiecutter.repo_name }}/workflows/ci/badge.svg?branch=master)](https://github.com/{{ cookiecutter.github_user }}/{{ cookiecutter.repo_name }}/actions)
[![Coverage Status](https://coveralls.io/repos/github/{{ cookiecutter.github_user}}/{{ cookiecutter.repo_name }}/badge.svg?branch=master)](https://coveralls.io/github/{{ cookiecutter.github_user }}/{{ cookiecutter.repo_name }}?branch=master)
[![Docs status](https://readthedocs.org/projects/{{ cookiecutter.plugin_name }}/badge)](http://{{ cookiecutter.plugin_name }}.readthedocs.io/)
[![PyPI version](https://badge.fury.io/py/{{ cookiecutter.plugin_name }}.svg)](https://badge.fury.io/py/{{ cookiecutter.plugin_name }})
[![Build Status][ci-badge]][ci-link]
[![Coverage Status][cov-badge]][cov-link]
[![Docs status][docs-badge]][docs-link]
[![PyPI version][pypi-badge]][pypi-link]

# {{ cookiecutter.plugin_name }}

Expand All @@ -25,22 +25,16 @@ intended to help developers get started with their AiiDA plugins.
* [`docs/`](docs/): A documentation template ready for publication on [Read the Docs](http://aiida-diff.readthedocs.io/en/latest/)
* [`examples/`](examples/): An example of how to submit a calculation using this plugin
* [`tests/`](tests/): Basic regression tests using the [pytest](https://docs.pytest.org/en/latest/) framework (submitting a calculation, ...). Install `pip install -e .[testing]` and run `pytest`.
* [`.coveragerc`](.coveragerc): Configuration of [coverage.py](https://coverage.readthedocs.io/en/latest) tool reporting which lines of your plugin are covered by tests
* [`.gitignore`](.gitignore): Telling git which files to ignore
* [`.pre-commit-config.yaml`](.pre-commit-config.yaml): Configuration of [pre-commit hooks](https://pre-commit.com/) that sanitize coding style and check for syntax errors. Enable via `pip install -e .[pre-commit] && pre-commit install`
* [`.readthedocs.yml`](.readthedocs.yml): Configuration of documentation build for [Read the Docs](https://readthedocs.org/)
* [`LICENSE`](LICENSE): License for your plugin
* [`MANIFEST.in`](MANIFEST.in): Configure non-Python files to be included for publication on [PyPI](https://pypi.org/)
* [`README.md`](README.md): This file
* [`conftest.py`](conftest.py): Configuration of fixtures for [pytest](https://docs.pytest.org/en/latest/)
* [`pytest.ini`](pytest.ini): Configuration of [pytest](https://docs.pytest.org/en/latest/) test discovery
* [`setup.json`](setup.json): Plugin metadata for registration on [PyPI](https://pypi.org/) and the [AiiDA plugin registry](https://aiidateam.github.io/aiida-registry/) (including entry points)
* [`setup.py`](setup.py): Installation script for pip / [PyPI](https://pypi.org/)

* [`pyproject.toml`](setup.json): Python package metadata for registration on [PyPI](https://pypi.org/) and the [AiiDA plugin registry](https://aiidateam.github.io/aiida-registry/) (including entry points)

See also the following video sequences from the 2019-05 AiiDA tutorial:

* [aiida-diff setup.json](https://www.youtube.com/watch?v=2CxiuiA1uVs&t=240s)
* [run aiida-diff example calculation](https://www.youtube.com/watch?v=2CxiuiA1uVs&t=403s)
* [aiida-diff CalcJob plugin](https://www.youtube.com/watch?v=2CxiuiA1uVs&t=685s)
* [aiida-diff Parser plugin](https://www.youtube.com/watch?v=2CxiuiA1uVs&t=936s)
Expand Down Expand Up @@ -109,6 +103,7 @@ verdi data {{cookiecutter.entry_point_prefix}} export <PK>
```shell
git clone https://github.com/{{ cookiecutter.github_user }}/{{ cookiecutter.repo_name}} .
cd {{ cookiecutter.repo_name }}
pip install --upgrade pip
pip install -e .[pre-commit,testing] # install extra dependencies
pre-commit install # install pre-commit hooks
pytest -v # discover and run all tests
Expand All @@ -122,3 +117,13 @@ MIT{%if cookiecutter.contact_email!=""%}
## Contact

{{ cookiecutter.contact_email }}{%endif%}


[ci-badge]: https://github.com/{{ cookiecutter.github_user }}/{{ cookiecutter.repo_name }}/workflows/ci/badge.svg?branch=master
[ci-link]: https://github.com/{{ cookiecutter.github_user }}/{{ cookiecutter.repo_name }}/actions
[cov-badge]: https://coveralls.io/repos/github/{{ cookiecutter.github_user}}/{{ cookiecutter.repo_name }}/badge.svg?branch=master
[cov-link]: https://coveralls.io/github/{{ cookiecutter.github_user }}/{{ cookiecutter.repo_name }}?branch=master
[docs-badge]: https://readthedocs.org/projects/{{ cookiecutter.plugin_name }}/badge
[docs-link]: http://{{ cookiecutter.plugin_name }}.readthedocs.io/
[pypi-badge]: https://badge.fury.io/py/{{ cookiecutter.plugin_name }}.svg
[pypi-link]: https://badge.fury.io/py/{{ cookiecutter.plugin_name }}
12 changes: 5 additions & 7 deletions {{cookiecutter.plugin_name}}/conftest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# -*- coding: utf-8 -*-
"""pytest fixtures for simplified testing."""
from __future__ import absolute_import
import pytest
pytest_plugins = ['aiida.manage.tests.pytest_fixtures']

pytest_plugins = ["aiida.manage.tests.pytest_fixtures"]

@pytest.fixture(scope='function', autouse=True)

@pytest.fixture(scope="function", autouse=True)
def clear_database_auto(clear_database): # pylint: disable=unused-argument
"""Automatically clear database in between tests."""


@pytest.fixture(scope='function')
def {{cookiecutter.entry_point_prefix}}_code(aiida_local_code_factory):
"""Get a {{cookiecutter.entry_point_prefix}} code.
"""
return aiida_local_code_factory(executable='diff', entry_point='{{cookiecutter.entry_point_prefix}}')
"""Get a {{cookiecutter.entry_point_prefix}} code."""
return aiida_local_code_factory(executable="diff", entry_point="{{cookiecutter.entry_point_prefix}}")
2 changes: 1 addition & 1 deletion {{cookiecutter.plugin_name}}/docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
## Runs nit-picky and converting warnings into errors to
## make sure the documentation is properly written
customdefault:
$(SPHINXBUILD) -b html -nW $(ALLSPHINXOPTS) $(BUILDDIR)/html
$(SPHINXBUILD) -b html -nW --keep-going $(ALLSPHINXOPTS) $(BUILDDIR)/html

all: html

Expand Down
Loading