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

Set up CI, linters, tests #1

Merged
merged 8 commits into from
Nov 20, 2023
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
60 changes: 60 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Tests

on:
push:
branches: [main]
pull_request:
# Run for all PRs

jobs:
tests:
runs-on: ${{ matrix.os }}
name: Test on ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-20.04
- os: macos-11
- os: windows-2019
steps:
- uses: actions/checkout@v3

- name: setup Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: install tests dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox

- name: run Python tests
run: python -m tox
env:
PIP_EXTRA_INDEX_URL: https://download.pytorch.org/whl/cpu

# check that we can build Python wheels on any Python version
python-build:
runs-on: ubuntu-20.04
name: check Python build
strategy:
matrix:
python-version: ['3.7', '3.11']
steps:
- uses: actions/checkout@v3

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

- name: install python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox wheel

- name: python build tests
run: tox -e build-python
env:
PIP_EXTRA_INDEX_URL: https://download.pytorch.org/whl/cpu
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include pyproject.toml
include LICENSE
include VERSION
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from setuptools import setup

ROOT = os.path.realpath(os.path.dirname(__file__))
Expand Down
79 changes: 79 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
[tox]
min_version = 4.0
# these are the default environments, i.e. the list of tests running when you
# execute `tox` in the command-line without anything else
envlist =
lint
python-tests

[testenv]
passenv = *
lint_folders = "{toxinidir}/metatensor_models" "{toxinidir}/setup.py"

[testenv:lint]
# this environement lints the Python code with flake8 (code linter), black (code
# formatter), and isort (sorting of imports)
package = skip
deps =
flake8
flake8-bugbear
black
blackdoc
isort

commands =
flake8 {[testenv]lint_folders}
black --check --diff {[testenv]lint_folders}
blackdoc --check --diff {[testenv]lint_folders}
isort --check-only --diff {[testenv]lint_folders}

[testenv:format]
# this environement abuses tox to do actual formatting
#
# Users can run `tox -e format` to run formatting on all files
package = skip
deps =
black
blackdoc
isort
commands =
isort {[testenv]lint_folders}
black {[testenv]lint_folders}
blackdoc {[testenv]lint_folders}

[testenv:python-tests]
passenv = *
deps =
pytest

commands =
pytest --import-mode=append {posargs}

[testenv:build-python]
# this environement makes sure one can build sdist and wheels for Python
deps =
setuptools
wheel
cmake
twine

allowlist_externals =
bash

commands =
# check building sdist and wheels from a checkout
python setup.py sdist
python setup.py bdist_wheel
twine check dist/*.tar.gz
twine check dist/*.whl

# check building wheels from the sdist
bash -c "python -m pip wheel --verbose dist/metatensor-models-*.tar.gz -w dist/test"

[flake8]
# longer lines for compatibility with other linters
max_line_length = 88
extend-ignore = E203

[isort]
profile = black