diff --git a/.github/workflows/check_pylint_diff.sh b/.github/workflows/check_pylint_diff.sh deleted file mode 100755 index 0306be4e8..000000000 --- a/.github/workflows/check_pylint_diff.sh +++ /dev/null @@ -1,205 +0,0 @@ -#!/usr/bin/env bash -# Copyright (C) 2016 Kernc, Google Inc., authors, and contributors -# Licensed under http://www.apache.org/licenses/LICENSE-2.0 -# Created By: miha@reciprocitylabs.com - -set -o pipefail -set -o nounset -set -o errexit - -ARG1=${1:-} -GIT_REPO="$(pwd)" -TMP_REPO="$GIT_REPO/$(mktemp -d pylint_diff.XXXXXXX)" -CACHE_DIR="$GIT_REPO/.pylint_cache" -UNCOMMITED_PATCH="$TMP_REPO/uncommited.patch" -SCRIPT=$(basename "$0") -PYLINT="$(command -v pylint 2>/dev/null || true)" -RADON="$(command -v radon 2>/dev/null || true)" -PYLINT_ARGS="--output-format=parseable" -RADON_ARGS='cc --min C --no-assert --show-closures --show-complexity --average' - -trap "status=\$?; cd '$GIT_REPO'; rm -rf '$TMP_REPO'; exit \$status" EXIT -mkdir -p "$CACHE_DIR" - - -print_help () -{ - echo " -Usage: $SCRIPT [TEST_COMMIT | -h] - -This script will compare pylint error count from two different commits. -Note: all changes that are not committed will be ignored. - -The script will work only if the current commit is a merge commit, or if the -second test_commit argument is provided. - -Given the commit tree: - - D---E---F---G---H - \\ / - A---B---C - -- Running '$SCRIPT' on H will check the diff between G and H. -- Running '$SCRIPT F' on H will check the diff between F and H. -- Running '$SCRIPT F' on C will check the diff between E and C. The E commit is - set by the merge base of the current head and the specified commit F. -" - exit 0 -} - -case $ARG1 in -h|--help) print_help ; esac - -if [ ! "$PYLINT$RADON" ]; then - echo 'Error: pylint and/or radon required' - exit 3 -fi - -# Make a local clone: prevents copying of objects -# Handle shallow git clones -is_shallow=$([ -f "$GIT_REPO/.git/shallow" ] && echo true || echo) -if [ "$is_shallow" ]; then - mv "$GIT_REPO/.git/shallow" "$GIT_REPO/.git/shallow-bak" -fi -git clone -q --local --depth=50 "$GIT_REPO" "$TMP_REPO" 2>/dev/null -if [ "$is_shallow" ]; then - mv "$GIT_REPO/.git/shallow-bak" "$GIT_REPO/.git/shallow" - cp "$GIT_REPO/.git/shallow" "$TMP_REPO/.git/shallow" -fi - -# Move over any modified but uncommited files ... -if ! git diff-index --quiet HEAD; then - git stash save -q --keep-index - git stash show -p stash@\{0\} > "$UNCOMMITED_PATCH" - git stash pop -q --index -fi - -cd "$TMP_REPO" - -# ... and commit them -if [ "$(cat "$UNCOMMITED_PATCH" 2>/dev/null || true)" ]; then - git apply "$UNCOMMITED_PATCH" - git commit -a -m 'Commit changed files' - was_dirty='+' -fi >/dev/null 2>&1 - -git reset --hard -q HEAD - -CURRENT_COMMIT=$(git rev-parse HEAD) -if [ "$ARG1" ]; then - PREVIOUS_COMMIT=$(git merge-base HEAD "$ARG1") -else - PREVIOUS_COMMIT=$(git show --pretty=raw HEAD | - awk '/^parent /{ print $2; exit }') -fi - -echo -echo "Comparing commits ${CURRENT_COMMIT:0:10}${was_dirty:-} and ${PREVIOUS_COMMIT:0:10}" - -CHANGED_FILES=$(git diff --name-only $CURRENT_COMMIT $PREVIOUS_COMMIT | - grep "\.py$" || true ) -[ ! "$(command -v md5sum 2>/dev/null)" ] && md5sum() { md5; } # for OS X -CHANGED_FILES_HASH=$(echo "$CHANGED_FILES" | md5sum | cut -d ' ' -f 1) -if [ ! "$CHANGED_FILES" ]; then - echo "No python files changed. Skipping lint checks." - exit 0 -fi - -echo -echo "Comparing files" -echo "===============" -echo "$CHANGED_FILES" -echo - -# Run pylint on the old and new code, to compare the quality. -# If pylint is run multiple times it will store the previous results and show -# the change in quality with a non-negative number if code was improved or not -# changed, and a negative number if more code issues have been introduced. - -checkout () -{ - { git checkout -q "$1" - git reset --hard -q HEAD - } 2>/dev/null -} - -Number_of_issues () -{ - cached="$1" - { cat "$cached" 2>/dev/null || - echo "$CHANGED_FILES" | - xargs "$PYLINT" $PYLINT_ARGS | - tee "$cached" - } | awk -F'[\\. ]' '/^Your code has been rated at /{ print $7 }' || true -} - -Cyclomatic_complexity () -{ - cached="$1" - { cat "$cached" 2>/dev/null || - echo "$CHANGED_FILES" | - xargs "$RADON" $RADON_ARGS | - tee "$cached" - } | awk -F'[()]' '/ .+\([0-9]+\)$/ { tot += $2 } END { print tot }' || true -} - -Get_diffable () -{ - sed -E "/$diff_block_end/,\$d" | - sort | - sed -E "s/$match_line_num/$replace_line_num/" -} - -for check in \ - 'Pylint,Number_of_issues,^Report$,^([^:]+:)[0-9]+:,\\1,^\\+' \ - 'radon,Cyclomatic_complexity,^[0-9]+ blocks,^( +[MCF]) [0-9:]+,\\1:,^[+-]' -do - IFS=',' read check \ - func \ - diff_block_end \ - match_line_num \ - replace_line_num \ - show_diff_lines < <(echo "$check") - # If command not available, skip it - if [ ! "$(eval echo \$$(echo $check | tr '[:lower:]' '[:upper:]') )" ]; then - continue - fi - - cached_previous="$CACHE_DIR/previous.$check.$PREVIOUS_COMMIT.$CHANGED_FILES_HASH" - cached_current="$CACHE_DIR/current.$check.$CURRENT_COMMIT.$CHANGED_FILES_HASH" - [ -f "$cached_previous" ] || rm -r "$CACHE_DIR/previous."* 2>/dev/null || true - [ -f "$cached_current" ] || rm -r "$CACHE_DIR/current."* 2>/dev/null || true - - [ -f "$cached_previous" ] || checkout $PREVIOUS_COMMIT - RESULT_PARENT=$($func "$cached_previous") - [ -f "$cached_current" ] || checkout $CURRENT_COMMIT - RESULT_CURRENT=$($func "$cached_current") - - echo - echo "$check result" - echo "=================================================================" - cat "$cached_current" - echo - - echo - echo "$check diff" - echo "=================================================================" - diff --unified=0 --minimal \ - <(Get_diffable < "$cached_previous") \ - <(Get_diffable < "$cached_current") | - grep -E "$show_diff_lines" | tail -n +3 || true - echo - - echo - echo "$check results" - echo "=================================================================" - echo "${func//_/ } on parent commit: $RESULT_PARENT" - echo "${func//_/ } on the pull request: $RESULT_CURRENT ($(printf "%+d" $((RESULT_CURRENT - RESULT_PARENT))))" - echo - - if awk "BEGIN { exit ${RESULT_CURRENT:-0} > ${RESULT_PARENT:-0} ? 0 : 1 }"; then - echo "FAIL: ${func//_/ } got worse" - exit 1 - fi -done - -echo "OK" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..6822b13af --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +name: Lint + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.11] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install pre-commit + + - name: Lint + run: pre-commit run --all-files --show-diff-on-failure \ No newline at end of file diff --git a/.github/workflows/lint_workflow.yml b/.github/workflows/lint_workflow.yml deleted file mode 100644 index 65b8c62d6..000000000 --- a/.github/workflows/lint_workflow.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Lint workflow - -on: - # Trigger the workflow on push or pull request, but only for the master branch - push: - branches: - - master - pull_request: - branches: - - master - -jobs: - build: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: False - matrix: - python: [3.8] - os: [ubuntu-20.04] - - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: '2' - - name: Setup Python - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python }} - - - name: Install Tox - run: pip install tox - - - name: Run Pylint - run: tox -e pylint-ci diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b23ba0a03..d83b78c15 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,104 +7,7 @@ on: pull_request: branches: - master - workflow_dispatch: - schedule: - - cron: '0 6 1 * *' jobs: - build: - runs-on: ${{ matrix.os }} - continue-on-error: ${{ matrix.experimental }} - timeout-minutes: 20 - name: ${{ matrix.name }} (${{ matrix.os }}, ${{ matrix.python-version }}) - strategy: - fail-fast: false - matrix: - os: [ubuntu-20.04, macos-11, windows-2019] - python-version: [3.8, 3.9] - tox_env: [py-orange-released] - experimental: [false] - name: [Released] - include: - - os: ubuntu-20.04 - python-version: 3.9 - tox_env: py-orange-dask - name: Dask - experimental: false - - - os: windows-2019 - python-version: 3.8 - tox_env: py-orange-oldest - experimental: false - name: Oldest - - os: macos-11 - python-version: 3.8 - tox_env: py-orange-oldest - name: Oldest - experimental: false - - os: ubuntu-20.04 - python-version: 3.8 - tox_env: py-orange-oldest - name: Oldest - experimental: false - - - os: windows-2019 - python-version: 3.9 - tox_env: py-orange-latest - experimental: false - name: Latest - - os: macos-11 - python-version: 3.9 - tox_env: py-orange-latest - experimental: false - name: Latest - - os: ubuntu-20.04 - python-version: 3.9 - tox_env: py-orange-latest - experimental: false - name: Latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - name: Install linux system dependencies - if: | - matrix.os == 'ubuntu-20.04' - run: | - sudo apt-get update - sudo apt-get install -y libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0 libegl1-mesa libxcb-shape0 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install --upgrade tox - - - name: Set environment variable - # this step sets QT_QPA_PLATFORM env which is required on Ubuntu and - # it is skipped on Windows - QLabel font issues - if: runner.os != 'Windows' - run: | - echo "QT_QPA_PLATFORM=offscreen" >> $GITHUB_ENV - - - name: Test with Tox - run: | - tox -e ${{ matrix.tox_env }} - env: - # Raise deprecations as errors in our tests only when testing orange-oldest and orange-released. - ORANGE_DEPRECATIONS_ERROR: "${{ matrix.tox_env != 'py-orange-latest' && '1' || '' }}" - # Need this otherwise unittest installs a warning filter that overrides - # our desire to have OrangeDeprecationWarnings raised - PYTHONWARNINGS: module - - - name: Upload code coverage - if: | - matrix.python-version == '3.9' && - matrix.os == 'ubuntu-20.04' && - matrix.tox_env == 'py-orange-dask' - uses: codecov/codecov-action@v3 - with: - fail_ci_if_error: true + test: + uses: biolab/orange-ci-cd/.github/workflows/test-addons.yml@master \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..f260f0604 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,26 @@ +repos: + - repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 + hooks: + - id: pyupgrade + args: ["--py39-plus"] + - repo: https://github.com/psf/black + rev: 23.1.0 + hooks: + - id: black + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-ast + - id: trailing-whitespace + - id: end-of-file-fixer + - id: mixed-line-ending + - repo: https://github.com/pycqa/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + additional_dependencies: + - flake8-bugbear + - flake8-comprehensions + - pep8-naming + - flake8-black diff --git a/tox.ini b/tox.ini index 9e59a56a4..9b9e80a88 100644 --- a/tox.ini +++ b/tox.ini @@ -1,14 +1,12 @@ [tox] envlist = - py{38,39}-orange-{oldest, latest, released} + orange-{oldest, latest, released} pylint-ci skip_missing_interpreters = true isolated_build = true -toxworkdir={env:TOX_WORK_DIR:.tox} [testenv] -# must use latest pip (version 20.3.1 enables Big Sur support - https://github.com/pypa/pip/issues/9138) -pip_version = pip +download = true extras = test passenv = * # we MUST changedir to avoid installed being shadowed by working dir @@ -21,8 +19,8 @@ setenv = COVERAGE_FILE = {toxinidir}/.coverage COVERAGE_RCFILE = {toxinidir}/.coveragerc deps = - pyqt5==5.12.* - pyqtwebengine==5.12.* + {env:PYQT_PYPI_NAME:PyQt5}=={env:PYQT_PYPI_VERSION:5.15.*} + {env:WEBENGINE_PYPI_NAME:PyQtWebEngine}=={env:WEBENGINE_PYPI_VERSION:5.15.*} oldest: orange3==3.34.0 oldest: orange-canvas-core==0.1.28 oldest: orange-widget-base==4.19.0 @@ -37,10 +35,10 @@ deps = latest: https://github.com/biolab/orange-canvas-core/archive/refs/heads/master.zip#egg=orange-canvas-core latest: https://github.com/biolab/orange-widget-base/archive/refs/heads/master.zip#egg=orange-widget-base opusFC - # temporary util the new Orange is released - pandas<2.1 dask: https://github.com/biolab/orange3/archive/refs/heads/dask.zip#egg=orange3 commands_pre = + # check pip version in virtualenv + pip --version # Verify installed packages have compatible dependencies pip check # freeze environment @@ -49,11 +47,3 @@ commands = coverage run -m unittest orangecontrib.spectroscopy.tests coverage report coverage xml -o {toxinidir}/coverage.xml - -[testenv:pylint-ci] -changedir = {toxinidir} -skip_install = true -allowlist_externals = bash -deps = pylint -commands = - bash .github/workflows/check_pylint_diff.sh