From b584238aa050d4d2664702b43c216708208f73de Mon Sep 17 00:00:00 2001 From: Leopold Talirz Date: Wed, 25 Sep 2019 12:34:43 +0200 Subject: [PATCH 1/4] update depndencies * update dependencies * aiida-core * yapf * prospector * pylint * fix trusty dist for rabbitmq service * add features to README --- .travis.yml | 3 +-- README.md | 23 +++++++++++++++++++---- aiida_diff/calculations.py | 1 - aiida_diff/cli.py | 3 --- aiida_diff/parsers.py | 1 - setup.json | 14 ++++++++------ 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index fcc4b82..2e2525f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ --- # Configuration of integration tests on travis-ci.org language: python - -cache: pip +dist: trusty services: - postgresql diff --git a/README.md b/README.md index 1c97c01..7cc6c34 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,30 @@ -[![Build Status](https://travis-ci.org/aiidateam/aiida-diff.svg?branch=master)](https://travis-ci.org/aiidateam/aiida-diff) -[![Coverage Status](https://coveralls.io/repos/github/aiidateam/aiida-diff/badge.svg?branch=master)](https://coveralls.io/github/aiidateam/aiida-diff?branch=master) -[![Docs status](https://readthedocs.org/projects/aiida-diff/badge)](http://aiida-diff.readthedocs.io/) +[![Build Status](https://travis-ci.org/aiidateam/aiida-diff.svg?branch=master)](https://travis-ci.org/aiidateam/aiida-diff) +[![Coverage Status](https://coveralls.io/repos/github/aiidateam/aiida-diff/badge.svg?branch=master)](https://coveralls.io/github/aiidateam/aiida-diff?branch=master) +[![Docs status](https://readthedocs.org/projects/aiida-diff/badge)](http://aiida-diff.readthedocs.io/) [![PyPI version](https://badge.fury.io/py/aiida-diff.svg)](https://badge.fury.io/py/aiida-diff) # aiida-diff AiiDA demo plugin that wraps the `diff` executable for computing the difference between two files. -This plugin is the default output of the +This plugin is the default output of the [AiiDA plugin cutter](https://github.com/aiidateam/aiida-plugin-cutter), intended to help developers get started with their AiiDA plugins. +Plugins templated using the plugin cutter + +* include a calculation, parser and data type as well as an example of + how to submit a calculation +* include basic regression tests using the [pytest](https://docs.pytest.org/en/latest/) framework ( (submitting a calculation, ...) +* can be directly pip-installed (and are prepared for submisson to [PyPI](https://pypi.org/) +* include a documentation template ready for [Read the Docs](http://aiida-diff.readthedocs.io/en/latest/) +* come with [Travis CI](https://travis-ci.org) configuration - enable it to run tests and check test coverage at every commit +* come with pre-commit hooks that sanitize coding style and check for syntax errors - enable via `pre-commit install` + +For more information on how to take advantage of these features, +see the [developer guide](https://aiida-diff.readthedocs.io/en/latest/developer_guide) of your plugin. + + ## Features * Add input files using `SinglefileData`: @@ -42,6 +56,7 @@ verdi quicksetup # better to set up a new profile verdi plugin list aiida.calculations # should now show your calclulation plugins ``` + ## Usage Here goes a complete example of how to submit a test calculation using this plugin. diff --git a/aiida_diff/calculations.py b/aiida_diff/calculations.py index 0c840bd..cc5a7dc 100644 --- a/aiida_diff/calculations.py +++ b/aiida_diff/calculations.py @@ -21,7 +21,6 @@ class DiffCalculation(CalcJob): Simple AiiDA plugin wrapper for 'diffing' two files. """ - @classmethod def define(cls, spec): """Define inputs and outputs of the calculation.""" diff --git a/aiida_diff/cli.py b/aiida_diff/cli.py index 030bfba..1acdb28 100644 --- a/aiida_diff/cli.py +++ b/aiida_diff/cli.py @@ -18,9 +18,6 @@ @verdi_data.group('diff') def data_cli(): """Command line interface for aiida-diff""" - pass - - @data_cli.command('list') @decorators.with_dbenv() def list_(): # pylint: disable=redefined-builtin diff --git a/aiida_diff/parsers.py b/aiida_diff/parsers.py index 16744f2..397bd02 100644 --- a/aiida_diff/parsers.py +++ b/aiida_diff/parsers.py @@ -17,7 +17,6 @@ class DiffParser(Parser): """ Parser class for parsing output of calculation. """ - def __init__(self, node): """ Initialize Parser instance diff --git a/setup.json b/setup.json index 078bb98..0773c26 100644 --- a/setup.json +++ b/setup.json @@ -31,23 +31,25 @@ "setup_requires": ["reentry"], "reentry_register": true, "install_requires": [ - "aiida-core>=1.0.0b3,<2.0.0", + "aiida-core>=1.0.0b6,<2.0.0", "six", "voluptuous" ], "extras_require": { "testing": [ - "pgtest==1.2.0", + "pgtest==1.3.1", "wheel>=0.31", "coverage", "pytest>=3.6.3,<5.0.0", "pytest-cov>=2.6.1,<5.0.0" ], "pre-commit": [ - "pre-commit==1.11.0", - "yapf==0.27.0", - "prospector==0.12.11", - "pylint==1.9.4" + "pre-commit==1.17.0", + "yapf==0.28.0", + "prospector==1.1.7", + "pylint-django==0.11.1; python_version<'3.0'", + "pylint==1.9.4; python_version<'3.0'", + "pylint==2.3.1; python_version>='3.0'" ], "docs": [ "sphinx" From 0f5c4354306235e3a4e5cf344a76956bb59d9664 Mon Sep 17 00:00:00 2001 From: Leopold Talirz Date: Wed, 25 Sep 2019 12:50:05 +0200 Subject: [PATCH 2/4] fix pylint-django version for py2.7 pre-commit --- setup.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.json b/setup.json index 0773c26..a28b3c3 100644 --- a/setup.json +++ b/setup.json @@ -47,7 +47,7 @@ "pre-commit==1.17.0", "yapf==0.28.0", "prospector==1.1.7", - "pylint-django==0.11.1; python_version<'3.0'", + "pylint-django<0.9; python_version<'3.0'", "pylint==1.9.4; python_version<'3.0'", "pylint==2.3.1; python_version>='3.0'" ], From 504dc9646f8c6da028c315f4a9f33f0fd11faa64 Mon Sep 17 00:00:00 2001 From: Leopold Talirz Date: Fri, 1 Nov 2019 13:41:36 +0100 Subject: [PATCH 3/4] update pytest fixtures --- .pre-commit-config.yaml | 14 ++-- .travis.yml | 6 +- aiida_diff/__init__.py | 2 +- aiida_diff/helpers.py | 108 -------------------------- aiida_diff/tests/test_calculations.py | 4 +- aiida_diff/tests/test_cli.py | 3 +- conftest.py | 61 ++------------- docs/requirements_for_rtd.txt | 1 - setup.json | 11 +-- 9 files changed, 29 insertions(+), 181 deletions(-) delete mode 100644 aiida_diff/helpers.py delete mode 100644 docs/requirements_for_rtd.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 57cc925..90a62fb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,9 +1,9 @@ -# Install pre-commit hooks via +# Install pre-commit hooks via: # pre-commit install # modernizer: make sure our code-base is Python 3 ready - repo: https://github.com/python-modernize/python-modernize.git - sha: a234ce4e185cf77a55632888f1811d83b4ad9ef2 + rev: b8e29d95ed6e0f03ab82280ec0ab36136472e9c4 hooks: - id: python-modernize exclude: ^docs/ @@ -11,16 +11,16 @@ - --write - --nobackups -- repo: local +# yapf = yet another python formatter +- repo: https://github.com/pre-commit/mirrors-yapf + rev: v0.28.0 hooks: - # yapf = yet another python formatter - id: yapf name: yapf - entry: yapf - language: system - types: [python] args: ["-i"] +- repo: local + hooks: # prospector: collection of linters - id: prospector language: system diff --git a/.travis.yml b/.travis.yml index 2e2525f..0c52340 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ addons: env: global: - - TEST_AIIDA_BACKEND: django + - AIIDA_TEST_BACKEND: django # show timings of tests - PYTEST_ADDOPTS: --durations=0 @@ -27,7 +27,7 @@ matrix: python: 2.7 env: TEST_TYPE: tests - TEST_AIIDA_BACKEND: sqlalchemy + AIIDA_TEST_BACKEND: sqlalchemy - name: "python-2.7 (pre-commit)" python: 2.7 env: @@ -43,7 +43,7 @@ matrix: python: 3.6 env: TEST_TYPE: tests - TEST_AIIDA_BACKEND: sqlalchemy + AIIDA_TEST_BACKEND: sqlalchemy - name: "python-3.6 (docs)" python: 3.6 env: diff --git a/aiida_diff/__init__.py b/aiida_diff/__init__.py index 1d2d562..a0590bb 100644 --- a/aiida_diff/__init__.py +++ b/aiida_diff/__init__.py @@ -6,4 +6,4 @@ from __future__ import absolute_import -__version__ = "1.0.0b1" +__version__ = "1.0.0" diff --git a/aiida_diff/helpers.py b/aiida_diff/helpers.py deleted file mode 100644 index 2a56649..0000000 --- a/aiida_diff/helpers.py +++ /dev/null @@ -1,108 +0,0 @@ -""" Helper functions for automatically setting up computer & code. - -Helper functions for setting up - - 1. An AiiDA localhost computer - 2. A "diff" code on localhost - -Note: Point 2 is made possible by the fact that the ``diff`` executable is -available in the PATH on almost any UNIX system. -""" -from __future__ import absolute_import -from __future__ import print_function -import tempfile - -LOCALHOST_NAME = 'localhost-test' - -executables = { - 'diff': 'diff', -} - - -def get_path_to_executable(executable): - """ Get path to local executable. - - :param executable: Name of executable in the $PATH variable - :type executable: str - - :return: path to executable - :rtype: str - """ - # pylint issue https://github.com/PyCQA/pylint/issues/73 - import distutils.spawn # pylint: disable=no-name-in-module,import-error - path = distutils.spawn.find_executable(executable) - if path is None: - raise ValueError("{} executable not found in PATH.".format(executable)) - - return path - - -def get_computer(name=LOCALHOST_NAME, workdir=None): - """Get AiiDA computer. - - Loads computer 'name' from the database, if exists. - Sets up local computer 'name', if it isn't found in the DB. - - :param name: Name of computer to load or set up. - :param workdir: path to work directory - Used only when creating a new computer. - - :return: The computer node - :rtype: :py:class:`aiida.orm.Computer` - """ - from aiida.orm import Computer - from aiida.common.exceptions import NotExistent - - try: - computer = Computer.objects.get(name=name) - except NotExistent: - if workdir is None: - workdir = tempfile.mkdtemp() - - computer = Computer( - name=name, - description='localhost computer set up by aiida_diff tests', - hostname=name, - workdir=workdir, - transport_type='local', - scheduler_type='direct') - computer.store() - computer.configure() - - return computer - - -def get_code(entry_point, computer): - """Get local code. - - Sets up code for given entry point on given computer. - - :param entry_point: Entry point of calculation plugin - :param computer: (local) AiiDA computer - - :return: The code node - :rtype: :py:class:`aiida.orm.Code` - """ - from aiida.orm import Code - from aiida.common.exceptions import NotExistent - - try: - executable = executables[entry_point] - except KeyError: - raise KeyError( - "Entry point {} not recognized. Allowed values: {}".format( - entry_point, list(executables.keys()))) - - try: - code = Code.get_from_string('{}@{}'.format(executable, - computer.get_name())) - except NotExistent: - path = get_path_to_executable(executable) - code = Code( - input_plugin_name=entry_point, - remote_computer_exec=[computer, path], - ) - code.label = executable - code.store() - - return code diff --git a/aiida_diff/tests/test_calculations.py b/aiida_diff/tests/test_calculations.py index bfe1ec3..8ded688 100644 --- a/aiida_diff/tests/test_calculations.py +++ b/aiida_diff/tests/test_calculations.py @@ -8,7 +8,7 @@ from aiida_diff import tests -def test_process(aiida_code): +def test_process(diff_code): """Test running a calculation note this does not test that the expected outputs are created of output parsing""" from aiida.plugins import DataFactory, CalculationFactory @@ -26,7 +26,7 @@ def test_process(aiida_code): # set up calculation inputs = { - 'code': aiida_code, + 'code': diff_code, 'parameters': parameters, 'file1': file1, 'file2': file2, diff --git a/aiida_diff/tests/test_cli.py b/aiida_diff/tests/test_cli.py index 4bbe8ef..749dd56 100644 --- a/aiida_diff/tests/test_cli.py +++ b/aiida_diff/tests/test_cli.py @@ -4,10 +4,11 @@ from __future__ import print_function from __future__ import absolute_import -from aiida.manage.fixtures import PluginTestCase +from aiida.manage.tests.unittest_classes import PluginTestCase class TestDataCli(PluginTestCase): + """Test verdi data cli plugin.""" def setUp(self): from click.testing import CliRunner from aiida.plugins import DataFactory diff --git a/conftest.py b/conftest.py index b29b2d1..ae707bb 100644 --- a/conftest.py +++ b/conftest.py @@ -1,60 +1,15 @@ -""" -For pytest -initialise a text database and profile -""" +"""pytest fixtures for simplified testing.""" from __future__ import absolute_import -import tempfile -import shutil import pytest - -from aiida.manage.fixtures import fixture_manager - - -@pytest.fixture(scope='session', autouse=True) -def aiida_profile(): - """Set up a test profile for the duration of the tests""" - with fixture_manager() as fixture_mgr: - yield fixture_mgr +pytest_plugins = ['aiida.manage.tests.pytest_fixtures'] @pytest.fixture(scope='function', autouse=True) -def clear_database(aiida_profile): - """Clear the database after each test""" - yield - aiida_profile.reset_db() - - -@pytest.fixture(scope='function') -def new_workdir(): - """Get a temporary folder to use as the computer's work directory.""" - dirpath = tempfile.mkdtemp() - yield dirpath - shutil.rmtree(dirpath) - - -@pytest.fixture(scope='function') -def aiida_localhost_computer(new_workdir): - """Get an AiiDA computer for localhost. - - :return: The computer node - :rtype: :py:class:`aiida.orm.Computer` - """ - from aiida_diff.helpers import get_computer - - computer = get_computer(workdir=new_workdir) - - return computer - - +def clear_database_auto(clear_database): # pylint: disable=unused-argument + """Automatically clear database in between tests.""" @pytest.fixture(scope='function') -def aiida_code(aiida_localhost_computer): - """Get an AiiDA code. - - :return: The code node - :rtype: :py:class:`aiida.orm.Code` +def diff_code(aiida_local_code_factory): + """Get a diff code. """ - from aiida_diff.helpers import get_code - - code = get_code(entry_point='diff', computer=aiida_localhost_computer) - - return code + diff_code = aiida_local_code_factory(executable='diff', entry_point='diff') + return diff_code diff --git a/docs/requirements_for_rtd.txt b/docs/requirements_for_rtd.txt deleted file mode 100644 index 142b6ca..0000000 --- a/docs/requirements_for_rtd.txt +++ /dev/null @@ -1 +0,0 @@ --e .[docs] diff --git a/setup.json b/setup.json index a28b3c3..76eebf2 100644 --- a/setup.json +++ b/setup.json @@ -12,7 +12,7 @@ "Natural Language :: English", "Framework :: AiiDA" ], - "version": "1.0.0b1", + "version": "1.0.0", "entry_points": { "aiida.data": [ "diff = aiida_diff.data:DiffParameters" @@ -31,7 +31,7 @@ "setup_requires": ["reentry"], "reentry_register": true, "install_requires": [ - "aiida-core>=1.0.0b6,<2.0.0", + "aiida-core>=1.0.0,<2.0.0", "six", "voluptuous" ], @@ -44,10 +44,11 @@ "pytest-cov>=2.6.1,<5.0.0" ], "pre-commit": [ - "pre-commit==1.17.0", - "yapf==0.28.0", + "astroid==1.6.6; python_version<'3.0'", + "astroid==2.2.5; python_version>='3.0'", + "pre-commit==1.20.0", "prospector==1.1.7", - "pylint-django<0.9; python_version<'3.0'", + "pylint-django==0.11.1; python_version<'3.0'", "pylint==1.9.4; python_version<'3.0'", "pylint==2.3.1; python_version>='3.0'" ], From c42662b4bde7ca95a7c19ec67c38a70db49b4838 Mon Sep 17 00:00:00 2001 From: Leopold Talirz Date: Fri, 1 Nov 2019 13:48:43 +0100 Subject: [PATCH 4/4] try fixing pylint-django --- setup.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.json b/setup.json index 76eebf2..55f9cc7 100644 --- a/setup.json +++ b/setup.json @@ -48,7 +48,7 @@ "astroid==2.2.5; python_version>='3.0'", "pre-commit==1.20.0", "prospector==1.1.7", - "pylint-django==0.11.1; python_version<'3.0'", + "pylint-django<0.9; python_version<'3.0'", "pylint==1.9.4; python_version<'3.0'", "pylint==2.3.1; python_version>='3.0'" ],