From cb73a3f5eca95861e4e3ee9b344ec7b83875e055 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Sun, 5 May 2024 11:02:48 +0200 Subject: [PATCH] [MAINT] switch to tox (#84) * set up tox * rm package workflow --- .codespellrc | 1 - .github/workflows/check_md_links.yml | 1 - .github/workflows/package.yml | 60 ----------------- .github/workflows/test.yml | 66 ++++++++++++++++++ .github/workflows/test_and_coverage.yml | 48 ------------- .pre-commit-config.yaml | 2 +- .vscode/settings.json | 3 +- Makefile | 43 +----------- pyproject.toml | 16 +---- tox.ini | 90 +++++++++++++++++++++++++ 10 files changed, 163 insertions(+), 167 deletions(-) delete mode 100644 .codespellrc delete mode 100644 .github/workflows/package.yml create mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_and_coverage.yml create mode 100644 tox.ini diff --git a/.codespellrc b/.codespellrc deleted file mode 100644 index 60bbe06..0000000 --- a/.codespellrc +++ /dev/null @@ -1 +0,0 @@ -[codespell] diff --git a/.github/workflows/check_md_links.yml b/.github/workflows/check_md_links.yml index fca7b8b..fa9d708 100644 --- a/.github/workflows/check_md_links.yml +++ b/.github/workflows/check_md_links.yml @@ -7,7 +7,6 @@ on: push: branches: - main - - dev pull_request: branches: ['*'] diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml deleted file mode 100644 index 4429ffc..0000000 --- a/.github/workflows/package.yml +++ /dev/null @@ -1,60 +0,0 @@ ---- -name: Packaging - -on: - push: - branches: - - main - tags: - - '*' - -defaults: - run: - shell: bash - -jobs: - package: - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') - - # Build packages and upload - runs-on: ${{ matrix.os }} - strategy: - matrix: - include: - - os: ubuntu-latest - python-version: '3.11' - - 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 }} - - - name: Display Python version - run: python -c "import sys; print(sys.version)" - - - name: Install build - run: python -m pip install build - - - name: Build sdist and wheel - run: python -m build - - - name: Test PyPI upload - uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: __token__ - password: ${{ secrets.TEST_PYPI_API_TOKEN }} - repository_url: https://test.pypi.org/legacy/ - skip_existing: true - - - name: Upload to PyPI (on tags) - uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ebf466e --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/.github/workflows/test_and_coverage.yml b/.github/workflows/test_and_coverage.yml deleted file mode 100644 index 3f1e02a..0000000 --- a/.github/workflows/test_and_coverage.yml +++ /dev/null @@ -1,48 +0,0 @@ ---- -name: Test and coverage - -on: - push: - branches: [main] - pull_request: - branches: ['*'] - -jobs: - test_and_coverage: - - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [macos-latest, ubuntu-latest, windows-latest] - python-version: ['3.8', '3.9', '3.10', '3.11'] - fail-fast: false - - steps: - - - name: Clone repo - uses: actions/checkout@v4 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - allow-prereleases: true - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install .[test] - - - name: Run tests and generate coverage report - run: | - coverage erase - coverage run --source bids2cite -m pytest - coverage xml - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - file: ./coverage.xml - flags: tests - name: codecov-umbrella - fail_ci_if_error: false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b37a8fe..544bda4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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] diff --git a/.vscode/settings.json b/.vscode/settings.json index 3bc9f31..d9ab394 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "esbonio.sphinx.confDir": "" + "esbonio.sphinx.confDir": "", + "circleci.persistedProjectSelection": [] } diff --git a/Makefile b/Makefile index 24a0436..f34eae6 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 @@ -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 \ diff --git a/pyproject.toml b/pyproject.toml index 4551797..fffb15b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -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", diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..ef8fbdc --- /dev/null +++ b/tox.ini @@ -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/*