Skip to content

Commit

Permalink
updates for aiida 1.1.0 (#32)
Browse files Browse the repository at this point in the history
* modify setting of default port values

Reuse existing port definitions so that default validators are reused
without having to specify them again.

* update to aiida 1.1.0 and skip testing on python 2.7

* remove postgresql github action

should not be needed for temporary postgres cluster

* docs: use load_documentation_profile

use new load_documentation_profile function from aiida-core.

 * re-introduce helper scripts (now tested via example)
 * remove python-modernize hook
 * remove python2-compatibility leftovers
 * remove leftover travis setup
  • Loading branch information
ltalirz committed Feb 26, 2020
1 parent 18946f9 commit 0d32aad
Show file tree
Hide file tree
Showing 19 changed files with 191 additions and 190 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ jobs:
timeout-minutes: 30
strategy:
matrix:
python-version: [2.7, 3.7]
python-version: [3.7]
backend: ['django']
steps:
- uses: actions/checkout@v1
- uses: harmon758/postgresql-action@v1
with:
postgresql version: '11'
postgresql db: test_${{ matrix.backend }}
postgresql user: 'postgres'
postgresql password: ''
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
Expand All @@ -32,7 +26,7 @@ jobs:
echo 'deb https://dl.bintray.com/rabbitmq/debian bionic main' | sudo tee -a /etc/apt/sources.list.d/bintray.rabbitmq.list
sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list
sudo apt update
sudo apt install postgresql postgresql-server-dev-all postgresql-client rabbitmq-server graphviz
sudo apt install postgresql-10 rabbitmq-server graphviz
sudo systemctl status rabbitmq-server.service
- name: Install python dependencies
Expand Down
10 changes: 0 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# 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
rev: b8e29d95ed6e0f03ab82280ec0ab36136472e9c4
hooks:
- id: python-modernize
exclude: ^docs/
args:
- --write
- --nobackups

# yapf = yet another python formatter
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.28.0
Expand Down
77 changes: 0 additions & 77 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 The AiiDA Team.
Copyright (c) 2020 The AiiDA Team.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ Here goes a complete example of how to submit a test calculation using this plug

A quick demo of how to submit a calculation:
```shell
verdi daemon start # make sure the daemon is running
verdi daemon start # make sure the daemon is running
cd examples
verdi run submit.py # submit test calculation
verdi process list -a # check status of calculation
./example_01.py # run test calculation
verdi process list -a # check record of calculation
```

The plugin also includes verdi commands to inspect its data types:
Expand Down
2 changes: 0 additions & 2 deletions aiida_diff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@
AiiDA demo plugin that wraps the `diff` executable for computing the difference between two files.
"""

from __future__ import absolute_import

__version__ = "1.0.0"
17 changes: 10 additions & 7 deletions aiida_diff/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
Register calculations via the "aiida.calculations" entry point in setup.json.
"""
from __future__ import absolute_import

import six

from aiida.common import datastructures
from aiida.engine import CalcJob
from aiida.orm import SinglefileData
Expand All @@ -26,9 +22,16 @@ def define(cls, spec):
"""Define inputs and outputs of the calculation."""
# yapf: disable
super(DiffCalculation, cls).define(spec)
spec.input('metadata.options.resources', valid_type=dict, default={'num_machines': 1, 'num_mpiprocs_per_machine': 1})
spec.input('metadata.options.parser_name', valid_type=six.string_types, default='diff')
spec.input('metadata.options.output_filename', valid_type=six.string_types, default='patch.diff')

# set default values for AiiDA options
spec.inputs['metadata']['options']['resources'].default = {
'num_machines': 1,
'num_mpiprocs_per_machine': 1,
}
spec.inputs['metadata']['options']['parser_name'].default = 'diff'

# new ports
spec.input('metadata.options.output_filename', valid_type=str, default='patch.diff')
spec.input('parameters', valid_type=DiffParameters, help='Command line parameters for diff')
spec.input('file1', valid_type=SinglefileData, help='First file to be compared.')
spec.input('file2', valid_type=SinglefileData, help='Second file to be compared.')
Expand Down
1 change: 0 additions & 1 deletion aiida_diff/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"aiida.cmdline.data" (both in the setup.json file).
"""

from __future__ import absolute_import
import sys
import click
from aiida.cmdline.utils import decorators
Expand Down
1 change: 0 additions & 1 deletion aiida_diff/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

# You can directly use or subclass aiida.orm.data.Data
# or any other data type listed under 'verdi data'
from __future__ import absolute_import
from aiida.orm import Dict
from voluptuous import Schema, Optional

Expand Down
96 changes: 96 additions & 0 deletions aiida_diff/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
""" 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.
"""
import tempfile
import shutil

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
"""
path = shutil.which(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.set_minimum_job_poll_interval(0.)
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

try:
executable = executables[entry_point]
except KeyError:
raise KeyError(
"Entry point '{}' not recognized. Allowed values: {}".format(
entry_point, list(executables.keys())))

codes = Code.objects.find(filters={'label': executable}) # pylint: disable=no-member
if codes:
return codes[0]

path = get_path_to_executable(executable)
code = Code(
input_plugin_name=entry_point,
remote_computer_exec=[computer, path],
)
code.label = executable
return code.store()
3 changes: 0 additions & 3 deletions aiida_diff/parsers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
"""
Parsers provided by aiida_diff.
Register parsers via the "aiida.parsers" entry point in setup.json.
"""
from __future__ import absolute_import

from aiida.engine import ExitCode
from aiida.parsers.parser import Parser
from aiida.plugins import CalculationFactory
Expand Down
2 changes: 0 additions & 2 deletions aiida_diff/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Includes both tests written in unittest style (test_cli.py) and tests written
in pytest style (test_calculations.py).
"""
from __future__ import absolute_import
from __future__ import print_function
import os

TEST_DIR = os.path.dirname(os.path.realpath(__file__))
3 changes: 0 additions & 3 deletions aiida_diff/tests/test_calculations.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
""" Tests for calculations
"""
from __future__ import print_function
from __future__ import absolute_import

import os
from aiida_diff import tests

Expand Down
3 changes: 0 additions & 3 deletions aiida_diff/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
""" Tests for command line interface.
"""
from __future__ import print_function
from __future__ import absolute_import

from aiida.manage.tests.unittest_classes import PluginTestCase


Expand Down
32 changes: 11 additions & 21 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,26 @@
import time
import aiida_diff

from aiida.manage import configuration
from aiida.manage.manager import get_manager
from aiida.manage.configuration import load_documentation_profile

# -- AiiDA-related setup --------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# Load the dummy profile even if we are running locally, this way the documentation will succeed even if the current
# default profile of the AiiDA installation does not use a Django backend.
load_documentation_profile()

# Enable rtd mode via `export READTHEDOCS=True`
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'

if on_rtd: # let RTD set the theme
pass
else:
# If we are not on READTHEDOCS load the Sphinx theme manually
if not os.environ.get('READTHEDOCS', None):
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# Back-end settings for readthedocs online documentation.
configuration.IN_RT_DOC_MODE = True
configuration.BACKEND = "django"

configuration.reset_config() # empty config was created when importing aiida
configuration.load_profile() # load dummy config for RTD
# load DB backend (no schema check since no DB)
get_manager()._load_backend(schema_check=False) # pylint: disable=protected-access

# -- General configuration ------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

# If your documentation needs a minimal Sphinx version, state it here.
needs_sphinx = '1.5'

Expand Down Expand Up @@ -83,7 +73,7 @@

# General information about the project.
project = u'aiida-diff'
copyright_first_year = "2019"
copyright_first_year = "2020"
copyright_owners = "The AiiDA Team"

current_year = str(time.localtime().tm_year)
Expand Down

0 comments on commit 0d32aad

Please sign in to comment.