Skip to content

Commit

Permalink
[MAINT] switch to tox (#84)
Browse files Browse the repository at this point in the history
* set up tox

* rm package workflow
  • Loading branch information
Remi-Gau authored May 5, 2024
1 parent 13b71d3 commit cb73a3f
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 167 deletions.
1 change: 0 additions & 1 deletion .codespellrc

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/check_md_links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
push:
branches:
- main
- dev
pull_request:
branches: ['*']

Expand Down
60 changes: 0 additions & 60 deletions .github/workflows/package.yml

This file was deleted.

66 changes: 66 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
name: Python tests

on:
push:
branches:
- main
pull_request: {}
schedule:
# 8am EST / 9am EDT Mondays
- cron: 0 13 * * 1
# Allow job to be triggered manually from GitHub interface
workflow_dispatch:

defaults:
run:
shell: bash

# Force tox and pytest to use color
env:
FORCE_COLOR: true

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
test:
# Check each OS, all supported Python, minimum versions and latest releases
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
fail-fast: false

steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install tox
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Show tox config
run: tox c
- name: Run tox
run: tox run -v --exit-and-dump-after 1200 -e test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: tests
name: codecov-umbrella
fail_ci_if_error: false
48 changes: 0 additions & 48 deletions .github/workflows/test_and_coverage.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ repos:
rev: v1.10.0
hooks:
- id: mypy
additional_dependencies: [types-all, pandas-stubs]
additional_dependencies: [types-all, pandas-stubs, types-requests]
args: [--config-file=pyproject.toml]


Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"esbonio.sphinx.confDir": ""
"esbonio.sphinx.confDir": "",
"circleci.persistedProjectSelection": []
}
43 changes: 1 addition & 42 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean clean-build clean-pyc clean-test coverage dist help install
.PHONY: clean clean-build clean-pyc clean-test coverage help
.DEFAULT_GOAL := help

define BROWSER_PYSCRIPT
Expand Down Expand Up @@ -43,7 +43,6 @@ clean-pyc: ## remove Python file artifacts
find . -name '__pycache__' -exec rm -fr {} +

clean-test: ## remove test and coverage artifacts
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache
Expand All @@ -53,58 +52,18 @@ clean-test: ## remove test and coverage artifacts
rm -f tests/bids/CITATION.cff
rm -rf tests/bids/derivatives

## INSTALL

install: clean ## install the package to the active Python's site-packages
pip install .

release: dist ## package and upload a release
twine upload dist/*

dist: clean ## builds source and wheel package
python setup.py sdist
python setup.py bdist_wheel
ls -l dist

## STYLE

lint/flake8: ## check style with flake8
flake8 bids2cite tests
lint/black: ## check style with black
black bids2cite tests
lint/mypy: ## check style with mypy
mypy bids2cite

lint: lint/black lint/mypy lint/flake8 ## check style

validate_cff: ## Validate the citation file
cffconvert --validate


## DOC
.PHONY: docs

docs: ## generate Sphinx HTML documentation, including API docs
rm -f docs/source/bids2cite.rst
rm -f docs/source/modules.rst
sphinx-apidoc -o docs/source bids2cite
$(MAKE) -C docs clean
$(MAKE) -C docs html
$(BROWSER) docs/_build/html/index.html

servedocs: docs ## compile the docs watching for changes
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .


## TESTS

coverage: ## use coverage
coverage erase
coverage run --source bids2cite -m pytest

test: ## run tests with pytest
pytest

test-cli:
bids2cite tests/bids \
--skip-prompt \
Expand Down
16 changes: 3 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11"
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
]
dependencies = [
"cffconvert",
Expand All @@ -40,18 +41,7 @@ requires-python = ">=3.8"
[project.optional-dependencies]
dev = [
"bids2cite[doc,test]",
"codespell",
"black",
"flake8",
"flake8-docstrings",
"flake8-use-fstring",
"flake8-functions",
"mypy",
"pandas-stubs",
"pre-commit",
"sourcery",
"types-requests",
'tomli'
"sourcery"
]
doc = [
"myst-parser",
Expand Down
90 changes: 90 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[tox]
requires =
tox>=4
skip_missing_interpreters = true

; run lint by default when just calling "tox"
env_list = lint

; ENVIRONMENTS
; ------------
[style]
description = common environment for style checkers (rely on pre-commit hooks)
skip_install = true
deps =
pre-commit

# Configuration that allows us to split tests across GitHub runners effectively
[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311
3.12: py312

; COMMANDS
; --------
[testenv:lint]
description = run all linters and formatters
skip_install = true
deps =
{[style]deps}
commands =
pre-commit run --all-files --show-diff-on-failure {posargs:}

[testenv:test]
description = Pytest with coverage
labels = test
pass_env =
# getpass.getuser() sources for Windows:
LOGNAME
USER
LNAME
USERNAME
# Pass user color preferences through
PY_COLORS
FORCE_COLOR
NO_COLOR
CLICOLOR
CLICOLOR_FORCE
extras = test

commands =
coverage erase
coverage run --source bids2cite -m pytest
coverage xml

[testenv:docs]
description = Build documentation site
labels = docs
allowlist_externals = make
extras = doc
commands =
make -C docs clean
make -C docs html

[testenv:build{,-strict}]
labels =
check
pre-release
allowlist_externals = make
deps =
build
twine
skip_install = true
set_env =
build-strict: PYTHONWARNINGS=error
commands =
make clean-build
python -m build
python -m twine check dist/*

[testenv:publish]
depends = build
labels = release
deps =
twine
skip_install = true
commands =
python -m twine upload dist/*

0 comments on commit cb73a3f

Please sign in to comment.