Skip to content

Commit

Permalink
Move to Github actions (#102)
Browse files Browse the repository at this point in the history
* Add GitHub actions workflow
* Make tests executable from top-level directory.
* Add codecov to install script.
* Remove Travis configuration file.
  • Loading branch information
greschd committed Nov 8, 2020
1 parent b5c4263 commit 4b255c8
Show file tree
Hide file tree
Showing 22 changed files with 338 additions and 55 deletions.
9 changes: 6 additions & 3 deletions .travis-data/install_script.sh → .ci/install_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
# Be verbose, and stop with error as soon there's one
set -ev

cd ${TRAVIS_BUILD_DIR}

pip install -U pip
pip install codecov
pip install -U pip setuptools wheel

case "$INSTALL_TYPE" in
dev)
Expand All @@ -17,4 +16,8 @@ case "$INSTALL_TYPE" in
python setup.py sdist
ls -1 dist/ | xargs -I % pip install dist/%[dev]
;;
dev_bdist_wheel)
python setup.py bdist_wheel
ls -1 dist/ | xargs -I % pip install dist/%[dev]
;;
esac
File renamed without changes.
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[run]
source = z2pack

[report]
exclude_lines =
# Ignore lines used only for mypy runs
if ty\.TYPE_CHECKING:
121 changes: 121 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Continuous Integration

on: [push, pull_request]
jobs:
docs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
install-type: [dev]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install apt dependencies
run: |
sudo apt update -qq
sudo apt install -qq graphviz
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: pip-${{ matrix.python-version }}-${{ matrix.install-type }}-${{ hashFiles('**/setup.json')
}}
restore-keys: pip-${{ matrix.python-version }}-${{ matrix.install-type }}

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install the python project
env:
INSTALL_TYPE: ${{ matrix.install-type }}
run: .ci/install_script.sh

- name: Build documentation
env:
READTHEDOCS: 'True'
run: SPHINXOPTS='-nW' make -C doc html
- uses: actions/upload-artifact@v2
with:
name: doc-build
path: doc/build/html

pre-commit:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
install-type: [dev]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install apt dependencies
run: |
sudo apt update -qq
sudo apt install -qq graphviz
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: pip-${{ matrix.python-version }}-${{ matrix.install-type }}-${{ hashFiles('**/setup.json')
}}
restore-keys: pip-${{ matrix.python-version }}-${{ matrix.install-type }}

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install the python project
env:
INSTALL_TYPE: ${{ matrix.install-type }}
run: .ci/install_script.sh

- name: Run pre-commit
run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1
)
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
install-type: [dev]
include:
- python-version: 3.8
install-type: dev_sdist
- python-version: 3.8
install-type: dev_bdist_wheel
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install apt dependencies
run: |
sudo apt update -qq
sudo apt install -qq graphviz
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: pip-${{ matrix.python-version }}-${{ matrix.install-type }}-${{ hashFiles('**/setup.json')
}}
restore-keys: pip-${{ matrix.python-version }}-${{ matrix.install-type }}

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install the python project
env:
INSTALL_TYPE: ${{ matrix.install-type }}
run: .ci/install_script.sh

- name: Run pytest
run: pytest --cov=z2pack --cov-config=.coveragerc
- name: Run codecov
run: codecov
91 changes: 91 additions & 0 deletions .github/workflows_source/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Continuous Integration

on: [push, pull_request]

_anchors:
checkout: &CHECKOUT
name: Checkout code
uses: actions/checkout@v2

apt-dependencies: &APT_DEPENDENCIES
name: Install apt dependencies
run: |
sudo apt update -qq
sudo apt install -qq graphviz
pip-cache: &PIP_CACHE
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: pip-${{ matrix.python-version }}-${{ matrix.install-type }}-${{ hashFiles('**/setup.json') }}
restore-keys: pip-${{ matrix.python-version }}-${{ matrix.install-type }}

python-setup: &PYTHON_SETUP
name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

install-project: &INSTALL_PROJECT
name: Install the python project
env:
INSTALL_TYPE: ${{ matrix.install-type }}
run: .ci/install_script.sh

jobs:
docs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
install-type: [dev]
steps:
- *CHECKOUT
- *APT_DEPENDENCIES
- *PIP_CACHE
- *PYTHON_SETUP
- *INSTALL_PROJECT
- name: Build documentation
env:
READTHEDOCS: "True"
run: SPHINXOPTS='-nW' make -C doc html
- uses: actions/upload-artifact@v2
with:
name: doc-build
path: doc/build/html

pre-commit:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
install-type: [dev]
steps:
- *CHECKOUT
- *APT_DEPENDENCIES
- *PIP_CACHE
- *PYTHON_SETUP
- *INSTALL_PROJECT
- name: Run pre-commit
run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
install-type: [dev]
include:
- python-version: 3.8
install-type: dev_sdist
- python-version: 3.8
install-type: dev_bdist_wheel
steps:
- *CHECKOUT
- *APT_DEPENDENCIES
- *PIP_CACHE
- *PYTHON_SETUP
- *INSTALL_PROJECT
- name: Run pytest
run: pytest --cov=z2pack --cov-config=.coveragerc
- name: Run codecov
run: codecov
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ tests/.pytest_cache
.pytest_cache/v/cache
.coverage
.coverage*
!.coveragerc
htmlcov

# editors
Expand Down
21 changes: 17 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,22 @@ repos:
- id: yapf
language: system

- repo: git://github.com/guykisel/prospector-mirror
rev: 7ff847e779347033ebbd9e3b88279e7f3a998b45
- repo: local
hooks:
- id: prospector
- id: pylint
name: pylint
entry: pylint
language: system
exclude: '^(doc/)|(examples/)|(futures/)'
types: [python]
exclude: '^(doc/)|(examples/)|(futures/)|(utils/)'

- id: interpolate-workflows
name: Interpolate Github workflows
entry: python ./utils/interpolate_yaml_anchors.py
language: system
files: |
(?x)^(
.github/(.)*|
utils/interpolate_yaml_anchors.py
)$
pass_filenames: false
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=too-few-public-methods,too-many-public-methods,bad-continuation,wrong-import-position,line-too-long,locally-disabled,wildcard-import,locally-enabled,too-many-instance-attributes,cyclic-import
disable=too-few-public-methods,too-many-public-methods,bad-continuation,wrong-import-position,line-too-long,locally-disabled,wildcard-import,locally-enabled,too-many-instance-attributes,cyclic-import,duplicate-code

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools >= 46.4.0", "wheel"]
build-backend = "setuptools.build_meta"
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
'plot': ['matplotlib'],
'tb': ['tbmodels>=1.1.1'],
'doc': ['sphinx', 'sphinx-rtd-theme', 'sphinx-pyreverse', 'pylint==2.4.4'],
'dev': [
'prospector==1.2.0', 'pytest~=6.0', 'pytest-cov', 'yapf==0.29',
'pre-commit', 'pylint==2.4.4'
],
'dev':
['pytest~=6.0', 'pytest-cov', 'yapf==0.29', 'pre-commit', 'pylint==2.4.4'],
}
EXTRAS['dev'] += EXTRAS['plot'] + EXTRAS['tb'] + EXTRAS['doc']

Expand Down
5 changes: 3 additions & 2 deletions tests/fp/test_vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ def inner(build_dir):


@pytest.fixture
def vasp_system_no_potcar():
def vasp_system_no_potcar(sample):
"""
Create a VASP system without the POTCAR file.
"""
def inner(build_dir):
samples_dir = sample('vasp')
input_files = [
'samples/vasp/' + name
os.path.join(samples_dir, name)
for name in ['CHGCAR', 'INCAR', 'POSCAR', 'wannier90.win']
]
return z2pack.fp.System(
Expand Down
1 change: 1 addition & 0 deletions tests/local_config.yml
2 changes: 1 addition & 1 deletion tests/monkeypatch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def patch_surface_data(monkeypatch):
"""
Monkeypatch the SurfaceData class so that it can be set from a nested list of WCC and list of t-values.
"""
def __init__(self, wcc_list, t_list=None): # noqa
def __init__(self, wcc_list, t_list=None):
if t_list is None:
t_list = np.linspace(0, 1, len(wcc_list))
self.lines = SortedList(key=lambda x: x.t)
Expand Down
6 changes: 5 additions & 1 deletion tests/plottest_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def assert_image_equal(disable_diff_save, pytestconfig):
Save the current figure to a temporary file and check that it's the same as the reference image of the given name.
"""
def inner(name, tol=1e-6):
path = './reference_plots/' + name + '.png'
path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'reference_plots',
name + '.png'
)

if not os.path.exists(path):
plt.savefig(path)
raise ValueError('Reference plot did not exist.')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_read_mmn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import z2pack


def test_read(compare_data):
def test_read(compare_data, sample):
compare_data(
lambda x, y: np.equal(x, y).all(),
z2pack.fp._read_mmn.get_m('samples/mmn/bi.mmn')
z2pack.fp._read_mmn.get_m(sample('mmn/bi.mmn'))
)


Expand Down

0 comments on commit 4b255c8

Please sign in to comment.