Skip to content

Commit

Permalink
Fix: compatibility with aiida-core 2.0.0 (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastonero committed Nov 23, 2022
2 parents 35b3885 + e7ca7ba commit de2235e
Show file tree
Hide file tree
Showing 14 changed files with 268 additions and 155 deletions.
128 changes: 128 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: cd

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

jobs:

validate-release-tag:

if: github.repository == 'aiida-phonopy/aiida-phonopy'
runs-on: ubuntu-latest

steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Validate the tag version against the package version
run: python .github/workflows/validate_release_tag.py $GITHUB_REF

pre-commit:

needs: [validate-release-tag]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Cache Python dependencies
uses: actions/cache@v1
with:
path: ~/.cache/pip
key: pip-pre-commit-${{ hashFiles('**/setup.json') }}
restore-keys:
pip-pre-commit-

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Install Python dependencies
run: pip install -e .[pre-commit,tests]

- name: Run pre-commit
run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )

tests:

needs: [validate-release-tag]
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- python-version: '3.8'
phonopy-version: '2.14.0'
- python-version: '3.9'
phonopy-version: '2.15.0'
- python-version: '3.10'
phonopy-version: '2.16.3'
- python-version: '3.11'
phonopy-version: '2.16.3'

services:
postgres:
image: postgres:12
rabbitmq:
image: rabbitmq:latest
ports:
- 5672:5672

steps:
- uses: actions/checkout@v2

- name: Cache Python dependencies
uses: actions/cache@v1
with:
path: ~/.cache/pip
key: pip-${{ matrix.python-version }}-tests-${{ hashFiles('**/setup.json') }}
restore-keys:
pip-${{ matrix.python-version }}-tests

- name: Setup Conda
uses: s-weigand/setup-conda@v1
with:
python-version: ${{ matrix.python-version }}
conda-channels: conda-forge

- name: Set up Phonopy ${{ matrix.phonopy-version }}
run: conda install -y phonopy==${{ matrix.phonopy-version }}

- name: Install Python dependencies
run: pip install -e .[tests]

- name: Run pytest
run: pytest -sv tests

publish:

name: Publish to PyPI
needs: [pre-commit, tests]
runs-on: ubuntu-latest

steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Install flit
run: pip install flit~=3.4

- name: Build and publish
run: flit publish
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.PYPI_KEY }}
28 changes: 19 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ jobs:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9']
include:
- python-version: '3.8'
phonopy-version: '2.14.0'
- python-version: '3.9'
phonopy-version: '2.15.0'
- python-version: '3.10'
phonopy-version: '2.16.3'

services:
rabbitmq:
Expand All @@ -57,19 +64,22 @@ jobs:
restore-keys:
pip-${{ matrix.python-version }}-tests

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- name: Setup Conda
uses: s-weigand/setup-conda@v1
with:
python-version: ${{ matrix.python-version }}
conda-channels: conda-forge

- name: Set up Phonopy ${{ matrix.phonopy-version }}
run: conda install -y phonopy==${{ matrix.phonopy-version }}

- name: Install system dependencies
run: sudo apt update && sudo apt install postgresql
# - name: Set up Phonopy ${{ matrix.phonopy-version }}
# run: pip install phonopy==${{ matrix.phonopy-version }}

- name: Install python dependencies
run: |
pip install --upgrade setuptools
pip install -e .[tests]
reentry scan
run: pip install -e .[tests]

- name: Run pytest
env:
AIIDA_WARN_v3: 1
run: pytest -sv tests
35 changes: 35 additions & 0 deletions .github/workflows/validate_release_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
"""Validate that the version in the tag label matches the version of the package."""
import argparse
import ast
from pathlib import Path


def get_version_from_module(content: str) -> str:
"""Get the ``__version__`` attribute from a module.
.. note:: This has been adapted from :mod:`setuptools.config`.
"""
try:
module = ast.parse(content)
except SyntaxError as exception:
raise IOError('Unable to parse module.') from exception

try:
return next(
ast.literal_eval(statement.value) for statement in module.body if isinstance(statement, ast.Assign)
for target in statement.targets if isinstance(target, ast.Name) and target.id == '__version__'
)
except StopIteration as exception:
raise IOError('Unable to find the `__version__` attribute in the module.') from exception


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('GITHUB_REF', help='The GITHUB_REF environmental variable')
args = parser.parse_args()
assert args.GITHUB_REF.startswith('refs/tags/v'), f'GITHUB_REF should start with "refs/tags/v": {args.GITHUB_REF}'
tag_version = args.GITHUB_REF[11:]
package_version = get_version_from_module(Path('src/aiida_phonopy/__init__.py').read_text(encoding='utf-8'))
error_message = f'The tag version `{tag_version}` is different from the package version `{package_version}`'
assert tag_version == package_version, error_message
4 changes: 2 additions & 2 deletions docs/phonopy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ aiida-phonopy calculation of rocksalt NaCl.
PhononPhonopy = WorkflowFactory('phonopy.phonopy')
builder = PhononPhonopy.get_builder()
builder.structure = structure
builder.calculator_settings = Dict(dict={'forces': forces_config,
builder.calculator_settings = Dict({'forces': forces_config,
'nac': nac_config})
builder.run_phonopy = Bool(True)
builder.remote_phonopy = Bool(True)
Expand All @@ -95,7 +95,7 @@ aiida-phonopy calculation of rocksalt NaCl.
'distance': 0.01,
'is_nac': True})
builder.symmetry_tolerance = Float(1e-5)
builder.options = Dict(dict=base_config['options'])
builder.options = Dict(base_config['options'])
builder.metadata.label = "NaCl 2x2x2 phonon example"
builder.metadata.description = "NaCl 2x2x2 phonon example"
Expand Down
2 changes: 1 addition & 1 deletion examples/BaTiO3/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main():

inputs = {
'code': code,
'parameters': orm.Dict(dict=parameters),
'parameters': orm.Dict(parameters),
'phonopy_data': phonopy_data,
'metadata': {
'options': {
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
keywords = ['aiida', 'workflows']
requires-python = '>=3.8'
dependencies = [
"aiida-core>=1.6.0,<2.0.0",
"aiida-core>=2.0.0",
"phonopy>=2.14,<3.0.0",
]

Expand Down Expand Up @@ -126,7 +126,6 @@ max-line-length = 120
[tool.pylint.messages_control]
disable = [
'protected-access',
'bad-continuation',
'duplicate-code',
'import-outside-toplevel',
'inconsistent-return-statements',
Expand Down
2 changes: 1 addition & 1 deletion src/aiida_phonopy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
"""The official AiiDA plugin for Phonopy."""
__version__ = '0.7.0'
__version__ = '1.0.0'
6 changes: 3 additions & 3 deletions src/aiida_phonopy/data/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(
def displacement_dataset(self):
"""Get the dispacement dataset in a readible format for phonopy."""
try:
the_displacement_dataset = self.get_attribute('displacement_dataset')
the_displacement_dataset = self.base.attributes.get('displacement_dataset')
except AttributeError:
the_displacement_dataset = None
return the_displacement_dataset
Expand Down Expand Up @@ -107,7 +107,7 @@ def set_displacements(
except ValueError as err:
raise ValueError('one or more input types are not accepted') from err

self.set_attribute('displacement_dataset', copy.deepcopy(ph.dataset))
self.base.attributes.set('displacement_dataset', copy.deepcopy(ph.dataset))

def set_displacements_from_dataset(self, dataset):
"""Set displacements for frozen phonon calculation from a dataset.
Expand Down Expand Up @@ -135,7 +135,7 @@ def set_displacements_from_dataset(self, dataset):
else:
raise ValueError('type not accepted')

self.set_attribute('displacement_dataset', copy.deepcopy(ph.dataset))
self.base.attributes.set('displacement_dataset', copy.deepcopy(ph.dataset))

def get_supercells_with_displacements(self):
"""Get the supercells with displacements for frozen phonon calculation.
Expand Down

0 comments on commit de2235e

Please sign in to comment.