diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 87687d5..1962dd1 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,10 +1,8 @@ [bumpversion] -current_version = 0.3.5 +current_version = 0.5.1 commit = True tag = True -[bumpversion:file:__pkginfo__.py] - [bumpversion:file:README.rst] [bumpversion:file:doc-source/index.rst] @@ -22,3 +20,7 @@ replace = : str = "{new_version}" [bumpversion:file:pyproject.toml] search = version = "{current_version}" replace = version = "{new_version}" + +[bumpversion:file:.github/workflows/conda_ci.yml] +search = ={current_version}=py_1 +replace = ={new_version}=py_1 diff --git a/.dependabot/config.yml b/.dependabot/config.yml deleted file mode 100644 index 4584924..0000000 --- a/.dependabot/config.yml +++ /dev/null @@ -1,9 +0,0 @@ -# This file is managed by 'repo_helper'. Don't edit it directly. ---- -version: 1 -update_configs: -- package_manager: python - directory: / - update_schedule: weekly - default_reviewers: - - domdfcoding diff --git a/.github/actions_build_conda.sh b/.github/actions_build_conda.sh deleted file mode 100755 index 01676e9..0000000 --- a/.github/actions_build_conda.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -# This file is managed by 'repo_helper'. Don't edit it directly. - -set -e -x - -python -m mkrecipe --type wheel || exit 1 - -# Switch to miniconda -source "/home/runner/miniconda/etc/profile.d/conda.sh" -hash -r -conda activate base -conda config --set always_yes yes --set changeps1 no -conda update -q conda -conda install conda-build -conda install anaconda-client -conda info -a - -conda config --add channels conda-forge || exit 1 -conda config --add channels domdfcoding || exit 1 - -conda build conda -c conda-forge -c domdfcoding --output-folder conda/dist --skip-existing - -exit 0 diff --git a/.github/actions_deploy_conda.sh b/.github/actions_deploy_conda.sh deleted file mode 100755 index 3aa7e0b..0000000 --- a/.github/actions_deploy_conda.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -# This file is managed by 'repo_helper'. Don't edit it directly. - -set -e -x - -# Switch to miniconda -source "/home/runner/miniconda/etc/profile.d/conda.sh" -hash -r -conda activate base -conda config --set always_yes yes --set changeps1 no -conda update -q conda -conda install anaconda-client -conda info -a - -for f in conda/dist/noarch/flake8-encodings-*.tar.bz2; do - [ -e "$f" ] || continue - echo "$f" - conda install "$f" || exit 1 - echo "Deploying to Anaconda.org..." - anaconda -t "$ANACONDA_TOKEN" upload "$f" || exit 1 - echo "Successfully deployed to Anaconda.org." -done - -exit 0 diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e769ad3..454225a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,5 +6,6 @@ updates: directory: / schedule: interval: weekly + open-pull-requests-limit: 0 reviewers: - domdfcoding diff --git a/.github/milestones.py b/.github/milestones.py new file mode 100755 index 0000000..5e868dc --- /dev/null +++ b/.github/milestones.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +# stdlib +import os +import sys + +# 3rd party +from github3 import GitHub +from github3.repos import Repository +from packaging.version import InvalidVersion, Version + +latest_tag = os.environ["GITHUB_REF_NAME"] + +try: + current_version = Version(latest_tag) +except InvalidVersion: + sys.exit() + +gh: GitHub = GitHub(token=os.environ["GITHUB_TOKEN"]) +repo: Repository = gh.repository(*os.environ["GITHUB_REPOSITORY"].split('/', 1)) + +for milestone in repo.milestones(state="open"): + try: + milestone_version = Version(milestone.title) + except InvalidVersion: + continue + if milestone_version == current_version: + sys.exit(not milestone.update(state="closed")) diff --git a/.github/stale.yml b/.github/stale.yml index bb7ca3f..bb7fa62 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -7,7 +7,7 @@ daysUntilStale: 180 # Number of days of inactivity before an Issue or Pull Request with the stale label is closed. # Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. -daysUntilClose: 180 +daysUntilClose: false # Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled) onlyLabels: [] @@ -28,13 +28,13 @@ exemptMilestones: false exemptAssignees: false # Label to use when marking as stale -staleLabel: wontfix +staleLabel: stale # Comment to post when marking as stale. Set to `false` to disable -markComment: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed if no further activity occurs. Thank you - for your contributions. +markComment: false +# This issue has been automatically marked as stale because it has not had +# recent activity. It will be closed if no further activity occurs. Thank you +# for your contributions. # Comment to post when removing the stale label. # unmarkComment: > diff --git a/.github/workflows/cleanup.yml b/.github/workflows/cleanup.yml deleted file mode 100644 index 741c0bd..0000000 --- a/.github/workflows/cleanup.yml +++ /dev/null @@ -1,14 +0,0 @@ -# This file is managed by 'repo_helper'. Don't edit it directly. ---- -name: Artefact Cleaner -on: - schedule: - - cron: 0 9 1 * * -jobs: - Clean: - runs-on: ubuntu-latest - steps: - - name: cleanup - uses: glassechidna/artifact-cleaner@v2 - with: - minimumAge: 1000000.0 diff --git a/.github/workflows/conda_ci.yml b/.github/workflows/conda_ci.yml index d677f21..9b3fbc7 100644 --- a/.github/workflows/conda_ci.yml +++ b/.github/workflows/conda_ci.yml @@ -12,35 +12,57 @@ permissions: jobs: tests: name: "Conda" - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 + defaults: + run: + shell: bash -l {0} steps: - name: Checkout 🛎️ - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: Setup Python 🐍 - uses: "actions/setup-python@v2" + uses: "actions/setup-python@v5" with: - python-version: "3.8" + python-version: "3.11" + + - name: Setup Conda + uses: conda-incubator/setup-miniconda@v2.1.1 + with: + activate-environment: env + conda-build-version: 3.28.4 + miniconda-version: py311_24.1.2-0 + python-version: "3.11" + miniforge-variant: Mambaforge - name: Install dependencies 🔧 run: | python -VV python -m site python -m pip install --upgrade pip setuptools wheel - python -m pip install --upgrade repo_helper + python -m pip install --upgrade "whey-conda" "whey" # $CONDA is an environment variable pointing to the root of the miniconda directory - $CONDA/bin/conda update -q conda - $CONDA/bin/conda install conda-build=3.21.0 - + $CONDA/bin/conda update -n base conda $CONDA/bin/conda config --add channels conda-forge $CONDA/bin/conda config --add channels domdfcoding - - name: "Build and install package" + - name: "Build and index channel" run: | - # This mess is only necessary because conda won't fix it themselves - # https://github.com/conda/conda/issues/1884 - - python -m repo_helper build --conda --out-dir conda-bld/noarch + python -m whey --builder whey_conda --out-dir conda-bld/noarch $CONDA/bin/conda index ./conda-bld || exit 1 - $CONDA/bin/conda install -c file://$(pwd)/conda-bld flake8-encodings -y || exit 1 + + - name: "Search for package" + run: | + $CONDA/bin/conda search -c file://$(pwd)/conda-bld flake8-encodings + $CONDA/bin/conda search -c file://$(pwd)/conda-bld --override-channels flake8-encodings + + - name: "Install package" + run: | + $CONDA/bin/conda install -c file://$(pwd)/conda-bld flake8-encodings=0.5.1=py_1 -y || exit 1 + + - name: "Run Tests" + run: | + rm -rf flake8_encodings + $CONDA/bin/conda install pytest coincidence || exit 1 + pip install -r tests/requirements.txt + pytest tests/ diff --git a/.github/workflows/docs_test_action.yml b/.github/workflows/docs_test_action.yml index 77fa347..8f60ba5 100644 --- a/.github/workflows/docs_test_action.yml +++ b/.github/workflows/docs_test_action.yml @@ -2,7 +2,12 @@ --- name: "Docs Check" on: - - push + push: + branches-ignore: + - 'repo-helper-update' + - 'pre-commit-ci-update-config' + - 'imgbot' + pull_request: permissions: contents: read @@ -12,7 +17,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout 🛎️ - uses: "actions/checkout@v1" + uses: "actions/checkout@v4" - name: Check for changed files uses: dorny/paths-filter@v2 diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml index 116e13f..5e67c5c 100644 --- a/.github/workflows/flake8.yml +++ b/.github/workflows/flake8.yml @@ -4,6 +4,11 @@ name: Flake8 on: push: + branches-ignore: + - 'repo-helper-update' + - 'pre-commit-ci-update-config' + - 'imgbot' + pull_request: permissions: contents: read @@ -11,11 +16,11 @@ permissions: jobs: Run: name: "Flake8" - runs-on: "ubuntu-18.04" + runs-on: "ubuntu-22.04" steps: - name: Checkout 🛎️ - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: Check for changed files uses: dorny/paths-filter@v2 @@ -28,9 +33,9 @@ jobs: - name: Setup Python 🐍 if: steps.changes.outputs.code == 'true' - uses: "actions/setup-python@v2" + uses: "actions/setup-python@v5" with: - python-version: "3.6" + python-version: "3.9" - name: Install dependencies 🔧 if: steps.changes.outputs.code == 'true' @@ -38,7 +43,7 @@ jobs: python -VV python -m site python -m pip install --upgrade pip setuptools wheel - python -m pip install tox + python -m pip install tox~=3.0 - name: "Run Flake8" if: steps.changes.outputs.code == 'true' diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 5fb5285..4c22a52 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -4,6 +4,11 @@ name: mypy on: push: + branches-ignore: + - 'repo-helper-update' + - 'pre-commit-ci-update-config' + - 'imgbot' + pull_request: permissions: contents: read @@ -15,12 +20,12 @@ jobs: strategy: matrix: - os: ['ubuntu-20.04', 'windows-2019'] + os: ['ubuntu-22.04', 'windows-2022'] fail-fast: false steps: - name: Checkout 🛎️ - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: Check for changed files uses: dorny/paths-filter@v2 @@ -33,16 +38,16 @@ jobs: - name: Setup Python 🐍 if: steps.changes.outputs.code == 'true' - uses: "actions/setup-python@v2" + uses: "actions/setup-python@v5" with: - python-version: "3.6" + python-version: "3.9" - name: Install dependencies 🔧 run: | python -VV python -m site python -m pip install --upgrade pip setuptools wheel - python -m pip install --upgrade tox virtualenv + python -m pip install --upgrade tox~=3.0 virtualenv!=20.16.0 - name: "Run mypy" if: steps.changes.outputs.code == 'true' diff --git a/.github/workflows/octocheese.yml b/.github/workflows/octocheese.yml index 8e54454..fea7cd2 100644 --- a/.github/workflows/octocheese.yml +++ b/.github/workflows/octocheese.yml @@ -3,10 +3,8 @@ name: "GitHub Releases" on: - push: - branches: ["master"] schedule: - - cron: 0 12 * * 2,4,6 + - cron: 0 12 * * * jobs: Run: diff --git a/.github/workflows/python_ci.yml b/.github/workflows/python_ci.yml index fb6e497..ca858d8 100644 --- a/.github/workflows/python_ci.yml +++ b/.github/workflows/python_ci.yml @@ -4,34 +4,44 @@ name: Windows on: push: + branches-ignore: + - 'repo-helper-update' + - 'pre-commit-ci-update-config' + - 'imgbot' + + pull_request: permissions: actions: write + issues: write contents: read jobs: tests: - name: "windows-2019 / Python ${{ matrix.config.python-version }}" - runs-on: "windows-2019" + name: "windows-2022 / Python ${{ matrix.config.python-version }}" + runs-on: "windows-2022" continue-on-error: ${{ matrix.config.experimental }} env: - USING_COVERAGE: '3.6,3.7,3.8,3.9,3.10.0-beta.1,pypy-3.6,pypy-3.7' + USING_COVERAGE: '3.7,3.8,3.9,3.10,3.11,3.12,3.13,pypy-3.7,pypy-3.8,pypy-3.9' strategy: fail-fast: False matrix: config: - - {python-version: "3.6", testenvs: "py36,build", experimental: False} - {python-version: "3.7", testenvs: "py37,build", experimental: False} - {python-version: "3.8", testenvs: "py38,build", experimental: False} - {python-version: "3.9", testenvs: "py39,build", experimental: False} - - {python-version: "3.10.0-beta.1", testenvs: "py310-dev,build", experimental: True} - - {python-version: "pypy-3.6", testenvs: "pypy36,build", experimental: False} - - {python-version: "pypy-3.7", testenvs: "pypy37,build", experimental: True} + - {python-version: "3.10", testenvs: "py310,build", experimental: False} + - {python-version: "3.11", testenvs: "py311,build", experimental: False} + - {python-version: "3.12", testenvs: "py312,build", experimental: False} + - {python-version: "3.13", testenvs: "py313,build", experimental: True} + - {python-version: "pypy-3.7", testenvs: "pypy37,build", experimental: False} + - {python-version: "pypy-3.8", testenvs: "pypy38,build", experimental: False} + - {python-version: "pypy-3.9-v7.3.15", testenvs: "pypy39,build", experimental: True} steps: - name: Checkout 🛎️ - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: Check for changed files if: startsWith(github.ref, 'refs/tags/') != true @@ -46,7 +56,7 @@ jobs: - name: Setup Python 🐍 id: setup-python if: ${{ steps.changes.outputs.code == 'true' || steps.changes.outcome == 'skipped' }} - uses: "actions/setup-python@v2" + uses: "actions/setup-python@v5" with: python-version: "${{ matrix.config.python-version }}" @@ -56,15 +66,16 @@ jobs: python -VV python -m site python -m pip install --upgrade pip setuptools wheel - python -m pip install --upgrade tox virtualenv + python -m pip install --upgrade tox~=3.0 virtualenv!=20.16.0 - name: "Run Tests for Python ${{ matrix.config.python-version }}" if: steps.setup-python.outcome == 'success' run: python -m tox -e "${{ matrix.config.testenvs }}" -s false - name: "Upload Coverage 🚀" - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: ${{ always() && steps.setup-python.outcome == 'success' }} with: name: "coverage-${{ matrix.config.python-version }}" path: .coverage + include-hidden-files: true diff --git a/.github/workflows/python_ci_linux.yml b/.github/workflows/python_ci_linux.yml index 0474e63..01edd6b 100644 --- a/.github/workflows/python_ci_linux.yml +++ b/.github/workflows/python_ci_linux.yml @@ -4,34 +4,45 @@ name: Linux on: push: + branches-ignore: + - 'repo-helper-update' + - 'pre-commit-ci-update-config' + - 'imgbot' + tags: + - '*' + pull_request: permissions: actions: write + issues: write contents: read jobs: tests: - name: "ubuntu-20.04 / Python ${{ matrix.config.python-version }}" - runs-on: "ubuntu-20.04" + name: "ubuntu-22.04 / Python ${{ matrix.config.python-version }}" + runs-on: "ubuntu-22.04" continue-on-error: ${{ matrix.config.experimental }} env: - USING_COVERAGE: '3.6,3.7,3.8,3.9,3.10.0-beta.1,pypy-3.6,pypy-3.7' + USING_COVERAGE: '3.7,3.8,3.9,3.10,3.11,3.12,3.13,pypy-3.7,pypy-3.8,pypy-3.9' strategy: fail-fast: False matrix: config: - - {python-version: "3.6", testenvs: "py36,build", experimental: False} - {python-version: "3.7", testenvs: "py37,build", experimental: False} - {python-version: "3.8", testenvs: "py38,build", experimental: False} - {python-version: "3.9", testenvs: "py39,build", experimental: False} - - {python-version: "3.10.0-beta.1", testenvs: "py310-dev,build", experimental: True} - - {python-version: "pypy-3.6", testenvs: "pypy36,build", experimental: False} - - {python-version: "pypy-3.7", testenvs: "pypy37,build", experimental: True} + - {python-version: "3.10", testenvs: "py310,build", experimental: False} + - {python-version: "3.11", testenvs: "py311,build", experimental: False} + - {python-version: "3.12", testenvs: "py312,build", experimental: False} + - {python-version: "3.13", testenvs: "py313,build", experimental: True} + - {python-version: "pypy-3.7", testenvs: "pypy37,build", experimental: False} + - {python-version: "pypy-3.8", testenvs: "pypy38,build", experimental: False} + - {python-version: "pypy-3.9", testenvs: "pypy39,build", experimental: True} steps: - name: Checkout 🛎️ - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: Check for changed files if: startsWith(github.ref, 'refs/tags/') != true @@ -46,7 +57,7 @@ jobs: - name: Setup Python 🐍 id: setup-python if: ${{ steps.changes.outputs.code == 'true' || steps.changes.outcome == 'skipped' }} - uses: "actions/setup-python@v2" + uses: "actions/setup-python@v5" with: python-version: "${{ matrix.config.python-version }}" @@ -56,7 +67,7 @@ jobs: python -VV python -m site python -m pip install --upgrade pip setuptools wheel - python -m pip install --upgrade tox virtualenv + python -m pip install --upgrade tox~=3.0 virtualenv!=20.16.0 python -m pip install --upgrade coverage_pyver_pragma - name: "Run Tests for Python ${{ matrix.config.python-version }}" @@ -64,22 +75,23 @@ jobs: run: python -m tox -e "${{ matrix.config.testenvs }}" -s false - name: "Upload Coverage 🚀" - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: ${{ always() && steps.setup-python.outcome == 'success' }} with: name: "coverage-${{ matrix.config.python-version }}" path: .coverage + include-hidden-files: true Coverage: needs: tests - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-22.04" steps: - name: Checkout 🛎️ - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: Setup Python 🐍 - uses: "actions/setup-python@v2" + uses: "actions/setup-python@v5" with: python-version: 3.8 @@ -89,26 +101,32 @@ jobs: python -m pip install --upgrade "coveralls>=3.0.0" coverage_pyver_pragma - name: "Download Coverage 🪂" - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: path: coverage - name: Display structure of downloaded files + id: show run: ls -R working-directory: coverage + continue-on-error: true - name: Combine Coverage 👷 + if: ${{ steps.show.outcome != 'failure' }} run: | shopt -s globstar python -m coverage combine coverage/**/.coverage - name: "Upload Combined Coverage Artefact 🚀" - uses: actions/upload-artifact@v2 + if: ${{ steps.show.outcome != 'failure' }} + uses: actions/upload-artifact@v4 with: name: "combined-coverage" path: .coverage + include-hidden-files: true - name: "Upload Combined Coverage to Coveralls" + if: ${{ steps.show.outcome != 'failure' }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | @@ -117,29 +135,29 @@ jobs: Deploy: needs: tests - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-22.04" steps: - name: Checkout 🛎️ - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" if: startsWith(github.ref, 'refs/tags/') - name: Setup Python 🐍 - uses: "actions/setup-python@v2" + uses: "actions/setup-python@v5" + if: startsWith(github.ref, 'refs/tags/') with: python-version: 3.8 - if: startsWith(github.ref, 'refs/tags/') - name: Install dependencies 🔧 + if: startsWith(github.ref, 'refs/tags/') run: | python -m pip install --upgrade pip setuptools wheel - python -m pip install --upgrade tox - if: startsWith(github.ref, 'refs/tags/') + python -m pip install --upgrade tox~=3.0 - name: Build distributions 📦 + if: startsWith(github.ref, 'refs/tags/') run: | tox -e build - if: startsWith(github.ref, 'refs/tags/') - name: Upload distribution to PyPI 🚀 if: startsWith(github.ref, 'refs/tags/') @@ -149,36 +167,73 @@ jobs: password: ${{ secrets.PYPI_TOKEN }} skip_existing: true + - name: Close milestone 🚪 + if: startsWith(github.ref, 'refs/tags/') + run: | + python -m pip install --upgrade github3.py packaging + python .github/milestones.py + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + Conda: needs: deploy - runs-on: "ubuntu-20.04" + runs-on: ubuntu-22.04 if: startsWith(github.ref, 'refs/tags/') || (startsWith(github.event.head_commit.message, 'Bump version') != true) steps: - name: Checkout 🛎️ - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: Setup Python 🐍 - uses: "actions/setup-python@v2" + uses: "actions/setup-python@v5" with: - python-version: 3.8 + python-version: 3.11 + + - name: Setup Conda + uses: conda-incubator/setup-miniconda@v2.1.1 + with: + activate-environment: env + conda-build-version: 3.28.4 + miniconda-version: py311_24.1.2-0 + python-version: "3.11" + miniforge-variant: Mambaforge - name: Install dependencies 🔧 run: | + python -VV + python -m site python -m pip install --upgrade pip setuptools wheel - python -m pip install --upgrade mkrecipe - - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh - bash miniconda.sh -b -p $HOME/miniconda - - - name: Build Conda 📦 + python -m pip install --upgrade "mkrecipe" "whey" + # $CONDA is an environment variable pointing to the root of the miniconda directory + $CONDA/bin/conda config --set always_yes yes --set changeps1 no + $CONDA/bin/conda update -n base conda + $CONDA/bin/conda info -a + $CONDA/bin/conda install conda-forge::py-lief=0.14.1 + $CONDA/bin/conda config --add channels conda-forge + $CONDA/bin/conda config --add channels domdfcoding + + $CONDA/bin/conda config --remove channels defaults + + - name: Build Conda Package 📦 run: | - chmod +x .github/actions_build_conda.sh - bash .github/actions_build_conda.sh + python -m mkrecipe --type wheel || exit 1 + $CONDA/bin/conda build conda -c conda-forge -c domdfcoding --output-folder conda/dist - - name: Deploy Conda 🚀 + - name: Deploy Conda Package 🚀 + if: startsWith(github.ref, 'refs/tags/') run: | - chmod +x .github/actions_deploy_conda.sh - bash .github/actions_deploy_conda.sh + $CONDA/bin/conda config --set always_yes yes --set changeps1 no + $CONDA/bin/conda install anaconda-client + $CONDA/bin/conda info -a + + for f in conda/dist/noarch/flake8-encodings-*.tar.bz2; do + [ -e "$f" ] || continue + echo "$f" + conda install "$f" || exit 1 + echo "Deploying to Anaconda.org..." + $CONDA/bin/anaconda -t "$ANACONDA_TOKEN" upload "$f" || exit 1 + echo "Successfully deployed to Anaconda.org." + done env: ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }} diff --git a/.github/workflows/python_ci_macos.yml b/.github/workflows/python_ci_macos.yml index 0e0af29..280a25b 100644 --- a/.github/workflows/python_ci_macos.yml +++ b/.github/workflows/python_ci_macos.yml @@ -4,34 +4,44 @@ name: macOS on: push: + branches-ignore: + - 'repo-helper-update' + - 'pre-commit-ci-update-config' + - 'imgbot' + + pull_request: permissions: actions: write + issues: write contents: read jobs: tests: - name: "macos-latest / Python ${{ matrix.config.python-version }}" - runs-on: "macos-latest" + name: "macos-${{ matrix.config.os-ver }} / Python ${{ matrix.config.python-version }}" + runs-on: "macos-${{ matrix.config.os-ver }}" continue-on-error: ${{ matrix.config.experimental }} env: - USING_COVERAGE: '3.6,3.7,3.8,3.9,3.10.0-beta.1,pypy-3.6,pypy-3.7' + USING_COVERAGE: '3.7,3.8,3.9,3.10,3.11,3.12,3.13,pypy-3.7,pypy-3.8,pypy-3.9' strategy: fail-fast: False matrix: config: - - {python-version: "3.6", testenvs: "py36,build", experimental: False} - - {python-version: "3.7", testenvs: "py37,build", experimental: False} - - {python-version: "3.8", testenvs: "py38,build", experimental: False} - - {python-version: "3.9", testenvs: "py39,build", experimental: False} - - {python-version: "3.10.0-beta.1", testenvs: "py310-dev,build", experimental: True} - - {python-version: "pypy-3.6", testenvs: "pypy36,build", experimental: False} - - {python-version: "pypy-3.7", testenvs: "pypy37,build", experimental: True} + - {python-version: "3.7", os-ver: "13", testenvs: "py37,build", experimental: False} + - {python-version: "3.8", os-ver: "14", testenvs: "py38,build", experimental: False} + - {python-version: "3.9", os-ver: "14", testenvs: "py39,build", experimental: False} + - {python-version: "3.10", os-ver: "14", testenvs: "py310,build", experimental: False} + - {python-version: "3.11", os-ver: "14", testenvs: "py311,build", experimental: False} + - {python-version: "3.12", os-ver: "14", testenvs: "py312,build", experimental: False} + - {python-version: "3.13", os-ver: "14", testenvs: "py313,build", experimental: True} + - {python-version: "pypy-3.7", os-ver: "13", testenvs: "pypy37,build", experimental: False} + - {python-version: "pypy-3.8", os-ver: "14", testenvs: "pypy38,build", experimental: False} + - {python-version: "pypy-3.9", os-ver: "14", testenvs: "pypy39,build", experimental: True} steps: - name: Checkout 🛎️ - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: Check for changed files if: startsWith(github.ref, 'refs/tags/') != true @@ -46,7 +56,7 @@ jobs: - name: Setup Python 🐍 id: setup-python if: ${{ steps.changes.outputs.code == 'true' || steps.changes.outcome == 'skipped' }} - uses: "actions/setup-python@v2" + uses: "actions/setup-python@v5" with: python-version: "${{ matrix.config.python-version }}" @@ -56,15 +66,16 @@ jobs: python -VV python -m site python -m pip install --upgrade pip setuptools wheel - python -m pip install --upgrade tox virtualenv + python -m pip install --upgrade tox~=3.0 virtualenv!=20.16.0 - name: "Run Tests for Python ${{ matrix.config.python-version }}" if: steps.setup-python.outcome == 'success' run: python -m tox -e "${{ matrix.config.testenvs }}" -s false - name: "Upload Coverage 🚀" - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: ${{ always() && steps.setup-python.outcome == 'success' }} with: name: "coverage-${{ matrix.config.python-version }}" path: .coverage + include-hidden-files: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 495d106..5e5cd22 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,9 +3,12 @@ exclude: ^$ +ci: + autoupdate_schedule: quarterly + repos: - repo: https://github.com/repo-helper/pyproject-parser - rev: v0.2.3 + rev: v0.13.0 hooks: - id: reformat-pyproject @@ -30,7 +33,7 @@ repos: - id: end-of-file-fixer - repo: https://github.com/domdfcoding/pre-commit-hooks - rev: v0.2.1 + rev: v0.4.0 hooks: - id: requirements-txt-sorter args: @@ -39,19 +42,19 @@ repos: exclude: ^(doc-source/conf|__pkginfo__|setup|tests/.*)\.py$ - id: bind-requirements - - repo: https://github.com/domdfcoding/flake8-dunder-all - rev: v0.1.7 + - repo: https://github.com/python-formate/flake8-dunder-all + rev: v0.4.1 hooks: - id: ensure-dunder-all files: ^flake8_encodings/.*\.py$ - repo: https://github.com/domdfcoding/flake2lint - rev: v0.4.0 + rev: v0.4.3 hooks: - id: flake2lint - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.8.0 + rev: v1.10.0 hooks: - id: python-no-eval - id: rst-backticks @@ -67,19 +70,24 @@ repos: - --keep-runtime-typing - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.1.10 + rev: v1.5.1 hooks: - id: remove-crlf - id: forbid-crlf - - repo: https://github.com/repo-helper/formate - rev: v0.4.5 + - repo: https://github.com/python-formate/snippet-fmt + rev: v0.1.5 + hooks: + - id: snippet-fmt + + - repo: https://github.com/python-formate/formate + rev: v0.8.0 hooks: - id: formate exclude: ^(doc-source/conf|__pkginfo__|setup)\.(_)?py$ - - repo: https://github.com/domdfcoding/dep_checker - rev: v0.6.2 + - repo: https://github.com/python-coincidence/dep_checker + rev: v0.8.0 hooks: - id: dep_checker args: diff --git a/.pylintrc b/.pylintrc index a21206a..81ecba0 100644 --- a/.pylintrc +++ b/.pylintrc @@ -66,7 +66,7 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" disable=all -enable=assert-on-tuple,astroid-error,bad-except-order,bad-inline-option,bad-option-value,bad-reversed-sequence,bare-except,binary-op-exception,boolean-datetime,catching-non-exception,cell-var-from-loop,confusing-with-statement,consider-merging-isinstance,consider-using-enumerate,consider-using-ternary,continue-in-finally,cyclic-import,deprecated-pragma,django-not-available,duplicate-except,duplicate-key,eval-used,exec-used,expression-not-assigned,fatal,file-ignored,fixme,global-at-module-level,global-statement,global-variable-not-assigned,global-variable-undefined,http-response-with-content-type-json,http-response-with-json-dumps,invalid-all-object,invalid-characters-in-docstring,len-as-condition,literal-comparison,locally-disabled,locally-enabled,lost-exception,lowercase-l-suffix,misplaced-bare-raise,missing-kwoa,mixed-line-endings,model-has-unicode,model-missing-unicode,model-no-explicit-unicode,model-unicode-not-callable,multiple-imports,new-db-field-with-default,non-ascii-bytes-literals,nonexistent-operator,not-in-loop,notimplemented-raised,overlapping-except,parse-error,pointless-statement,pointless-string-statement,raising-bad-type,raising-non-exception,raw-checker-failed,redefine-in-handler,redefined-argument-from-local,redefined-builtin,redundant-content-type-for-json-response,reimported,relative-import,return-outside-function,simplifiable-if-statement,singleton-comparison,syntax-error,trailing-comma-tuple,trailing-newlines,unbalanced-tuple-unpacking,undefined-all-variable,undefined-loop-variable,unexpected-line-ending-format,unidiomatic-typecheck,unnecessary-lambda,unnecessary-pass,unnecessary-semicolon,unneeded-not,unpacking-non-sequence,unreachable,unrecognized-inline-option,used-before-assignment,useless-else-on-loop,using-constant-test,wildcard-import,yield-outside-function,useless-return +enable=assert-on-tuple,astroid-error,bad-except-order,bad-inline-option,bad-option-value,bad-reversed-sequence,bare-except,binary-op-exception,boolean-datetime,catching-non-exception,cell-var-from-loop,confusing-with-statement,consider-merging-isinstance,consider-using-enumerate,consider-using-ternary,continue-in-finally,deprecated-pragma,django-not-available,duplicate-except,duplicate-key,eval-used,exec-used,expression-not-assigned,fatal,file-ignored,fixme,global-at-module-level,global-statement,global-variable-not-assigned,global-variable-undefined,http-response-with-content-type-json,http-response-with-json-dumps,invalid-all-object,invalid-characters-in-docstring,len-as-condition,literal-comparison,locally-disabled,locally-enabled,lost-exception,lowercase-l-suffix,misplaced-bare-raise,missing-kwoa,mixed-line-endings,model-has-unicode,model-missing-unicode,model-no-explicit-unicode,model-unicode-not-callable,multiple-imports,new-db-field-with-default,non-ascii-bytes-literals,nonexistent-operator,not-in-loop,notimplemented-raised,overlapping-except,parse-error,pointless-statement,pointless-string-statement,raising-bad-type,raising-non-exception,raw-checker-failed,redefine-in-handler,redefined-argument-from-local,redefined-builtin,redundant-content-type-for-json-response,reimported,relative-import,return-outside-function,simplifiable-if-statement,singleton-comparison,syntax-error,trailing-comma-tuple,trailing-newlines,unbalanced-tuple-unpacking,undefined-all-variable,undefined-loop-variable,unexpected-line-ending-format,unidiomatic-typecheck,unnecessary-lambda,unnecessary-pass,unnecessary-semicolon,unneeded-not,unpacking-non-sequence,unreachable,unrecognized-inline-option,used-before-assignment,useless-else-on-loop,using-constant-test,wildcard-import,yield-outside-function,useless-return [REPORTS] diff --git a/.readthedocs.yml b/.readthedocs.yml index 41d2e57..2dee4b5 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -9,9 +9,16 @@ formats: - pdf - htmlzip python: - version: 3.8 install: - requirements: requirements.txt - requirements: doc-source/requirements.txt - - method: pip - path: . +build: + os: ubuntu-22.04 + tools: + python: '3.9' + jobs: + post_create_environment: + - pip install .[classes] + post_install: + - pip install sphinxcontrib-applehelp==1.0.4 sphinxcontrib-devhelp==1.0.2 sphinxcontrib-htmlhelp==2.0.1 + sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.5 diff --git a/LICENSE b/LICENSE index e1de807..74bb4a1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2021 Dominic Davis-Foster +Copyright (c) 2021-2022 Dominic Davis-Foster Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.rst b/README.rst index 5a2e2af..81f8207 100644 --- a/README.rst +++ b/README.rst @@ -34,40 +34,40 @@ flake8-encodings :target: https://flake8-encodings.readthedocs.io/en/latest :alt: Documentation Build Status -.. |docs_check| image:: https://github.com/domdfcoding/flake8-encodings/workflows/Docs%20Check/badge.svg - :target: https://github.com/domdfcoding/flake8-encodings/actions?query=workflow%3A%22Docs+Check%22 +.. |docs_check| image:: https://github.com/python-formate/flake8-encodings/workflows/Docs%20Check/badge.svg + :target: https://github.com/python-formate/flake8-encodings/actions?query=workflow%3A%22Docs+Check%22 :alt: Docs Check Status -.. |actions_linux| image:: https://github.com/domdfcoding/flake8-encodings/workflows/Linux/badge.svg - :target: https://github.com/domdfcoding/flake8-encodings/actions?query=workflow%3A%22Linux%22 +.. |actions_linux| image:: https://github.com/python-formate/flake8-encodings/workflows/Linux/badge.svg + :target: https://github.com/python-formate/flake8-encodings/actions?query=workflow%3A%22Linux%22 :alt: Linux Test Status -.. |actions_windows| image:: https://github.com/domdfcoding/flake8-encodings/workflows/Windows/badge.svg - :target: https://github.com/domdfcoding/flake8-encodings/actions?query=workflow%3A%22Windows%22 +.. |actions_windows| image:: https://github.com/python-formate/flake8-encodings/workflows/Windows/badge.svg + :target: https://github.com/python-formate/flake8-encodings/actions?query=workflow%3A%22Windows%22 :alt: Windows Test Status -.. |actions_macos| image:: https://github.com/domdfcoding/flake8-encodings/workflows/macOS/badge.svg - :target: https://github.com/domdfcoding/flake8-encodings/actions?query=workflow%3A%22macOS%22 +.. |actions_macos| image:: https://github.com/python-formate/flake8-encodings/workflows/macOS/badge.svg + :target: https://github.com/python-formate/flake8-encodings/actions?query=workflow%3A%22macOS%22 :alt: macOS Test Status -.. |actions_flake8| image:: https://github.com/domdfcoding/flake8-encodings/workflows/Flake8/badge.svg - :target: https://github.com/domdfcoding/flake8-encodings/actions?query=workflow%3A%22Flake8%22 +.. |actions_flake8| image:: https://github.com/python-formate/flake8-encodings/workflows/Flake8/badge.svg + :target: https://github.com/python-formate/flake8-encodings/actions?query=workflow%3A%22Flake8%22 :alt: Flake8 Status -.. |actions_mypy| image:: https://github.com/domdfcoding/flake8-encodings/workflows/mypy/badge.svg - :target: https://github.com/domdfcoding/flake8-encodings/actions?query=workflow%3A%22mypy%22 +.. |actions_mypy| image:: https://github.com/python-formate/flake8-encodings/workflows/mypy/badge.svg + :target: https://github.com/python-formate/flake8-encodings/actions?query=workflow%3A%22mypy%22 :alt: mypy status -.. |requires| image:: https://requires.io/github/domdfcoding/flake8-encodings/requirements.svg?branch=master - :target: https://requires.io/github/domdfcoding/flake8-encodings/requirements/?branch=master +.. |requires| image:: https://dependency-dash.repo-helper.uk/github/python-formate/flake8-encodings/badge.svg + :target: https://dependency-dash.repo-helper.uk/github/python-formate/flake8-encodings/ :alt: Requirements Status -.. |coveralls| image:: https://img.shields.io/coveralls/github/domdfcoding/flake8-encodings/master?logo=coveralls - :target: https://coveralls.io/github/domdfcoding/flake8-encodings?branch=master +.. |coveralls| image:: https://img.shields.io/coveralls/github/python-formate/flake8-encodings/master?logo=coveralls + :target: https://coveralls.io/github/python-formate/flake8-encodings?branch=master :alt: Coverage -.. |codefactor| image:: https://img.shields.io/codefactor/grade/github/domdfcoding/flake8-encodings?logo=codefactor - :target: https://www.codefactor.io/repository/github/domdfcoding/flake8-encodings +.. |codefactor| image:: https://img.shields.io/codefactor/grade/github/python-formate/flake8-encodings?logo=codefactor + :target: https://www.codefactor.io/repository/github/python-formate/flake8-encodings :alt: CodeFactor Grade .. |pypi-version| image:: https://img.shields.io/pypi/v/flake8-encodings @@ -94,22 +94,22 @@ flake8-encodings :target: https://anaconda.org/domdfcoding/flake8-encodings :alt: Conda - Platform -.. |license| image:: https://img.shields.io/github/license/domdfcoding/flake8-encodings - :target: https://github.com/domdfcoding/flake8-encodings/blob/master/LICENSE +.. |license| image:: https://img.shields.io/github/license/python-formate/flake8-encodings + :target: https://github.com/python-formate/flake8-encodings/blob/master/LICENSE :alt: License -.. |language| image:: https://img.shields.io/github/languages/top/domdfcoding/flake8-encodings +.. |language| image:: https://img.shields.io/github/languages/top/python-formate/flake8-encodings :alt: GitHub top language -.. |commits-since| image:: https://img.shields.io/github/commits-since/domdfcoding/flake8-encodings/v0.3.5 - :target: https://github.com/domdfcoding/flake8-encodings/pulse +.. |commits-since| image:: https://img.shields.io/github/commits-since/python-formate/flake8-encodings/v0.5.1 + :target: https://github.com/python-formate/flake8-encodings/pulse :alt: GitHub commits since tagged version -.. |commits-latest| image:: https://img.shields.io/github/last-commit/domdfcoding/flake8-encodings - :target: https://github.com/domdfcoding/flake8-encodings/commit/master +.. |commits-latest| image:: https://img.shields.io/github/last-commit/python-formate/flake8-encodings + :target: https://github.com/python-formate/flake8-encodings/commit/master :alt: GitHub last commit -.. |maintained| image:: https://img.shields.io/maintenance/yes/2021 +.. |maintained| image:: https://img.shields.io/maintenance/yes/2025 :alt: Maintenance .. |pypi-downloads| image:: https://img.shields.io/pypi/dm/flake8-encodings @@ -148,6 +148,20 @@ To install with ``conda``: .. end installation + +In version 0.5.1 and above the functionality for checking classes +(``configparser.ConfigParser`` and ``pathlib.Path`` for now) +requires the ``classes`` extra to be installed: + +.. code-block:: bash + + $ python3 -m pip install flake8-encodings[classes] + +The checks for classes are slower and CPU intensive, +so only enable them if you use the classes in question. + + + Motivation ------------- diff --git a/__pkginfo__.py b/__pkginfo__.py index 953a011..2a320ae 100644 --- a/__pkginfo__.py +++ b/__pkginfo__.py @@ -1,20 +1,5 @@ # This file is managed by 'repo_helper'. Don't edit it directly. -# Copyright © 2020 Dominic Davis-Foster -# -# This file is distributed under the same license terms as the program it came with. -# There will probably be a file called LICEN[S/C]E in the same directory as this file. -# -# In any case, this program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# -# This script based on https://github.com/rocky/python-uncompyle6/blob/master/__pkginfo__.py -# -__all__ = [ - "__version__", - "extras_require", - ] +__all__ = ["extras_require"] -__version__ = "0.3.5" -extras_require = {} +extras_require = {"classes": ["jedi>=0.18.0"], "all": ["jedi>=0.18.0"]} diff --git a/doc-source/Source.rst b/doc-source/Source.rst index 14397e4..598d75c 100644 --- a/doc-source/Source.rst +++ b/doc-source/Source.rst @@ -3,13 +3,13 @@ Downloading source code ========================= The ``flake8-encodings`` source code is available on GitHub, -and can be accessed from the following URL: https://github.com/domdfcoding/flake8-encodings +and can be accessed from the following URL: https://github.com/python-formate/flake8-encodings If you have ``git`` installed, you can clone the repository with the following command: .. prompt:: bash - git clone https://github.com/domdfcoding/flake8-encodings + git clone https://github.com/python-formate/flake8-encodings .. parsed-literal:: diff --git a/doc-source/_static/style.css b/doc-source/_static/style.css index 644e48b..a6b8e4d 100644 --- a/doc-source/_static/style.css +++ b/doc-source/_static/style.css @@ -8,3 +8,12 @@ div.highlight { .field-list dt, dl.simple dt { margin-top: 0.5rem; } + +div.versionchanged ul, div.versionremoved ul { + margin-left: 20px; + margin-top: 0; +} + +.longtable.autosummary { + width: 100%; +} diff --git a/doc-source/conf.py b/doc-source/conf.py index 13e8a3f..8eb3017 100644 --- a/doc-source/conf.py +++ b/doc-source/conf.py @@ -27,7 +27,8 @@ slug = re.sub(r'\W+', '-', project.lower()) release = version = config.version -todo_include_todos = bool(os.environ.get("SHOW_TODOS", 0)) +sphinx_builder = os.environ.get("SPHINX_BUILDER", "html").lower() +todo_include_todos = int(os.environ.get("SHOW_TODOS", 0)) and sphinx_builder != "latex" intersphinx_mapping = { "python": ("https://docs.python.org/3/", None), @@ -70,11 +71,39 @@ } +# Fix for pathlib issue with sphinxemoji on Python 3.9 and Sphinx 4.x +def copy_asset_files(app, exc): + # 3rd party + from domdf_python_tools.compat import importlib_resources + from sphinx.util.fileutil import copy_asset + + if exc: + return + + asset_files = ["twemoji.js", "twemoji.css"] + for path in asset_files: + path_str = os.fspath(importlib_resources.files("sphinxemoji") / path) + copy_asset(path_str, os.path.join(app.outdir, "_static")) + + def setup(app): # 3rd party from sphinx_toolbox.latex import better_header_layout + from sphinxemoji import sphinxemoji app.connect("config-inited", lambda app, config: better_header_layout(config)) - - + app.connect("build-finished", copy_asset_files) + app.add_js_file("https://unpkg.com/twemoji@latest/dist/twemoji.min.js") + app.add_js_file("twemoji.js") + app.add_css_file("twemoji.css") + app.add_transform(sphinxemoji.EmojiSubstitutions) + + +needspace_amount = r"5\baselineskip" +favicons = [{ + "rel": "icon", + "href": "https://python-formate.github.io/assets/formate.ico", + "sizes": "48x48", + "type": "image/vnd.microsoft.icon" + }] nitpicky = True diff --git a/doc-source/contributing.rst b/doc-source/contributing.rst deleted file mode 100644 index ec6d84a..0000000 --- a/doc-source/contributing.rst +++ /dev/null @@ -1,73 +0,0 @@ -============== -Contributing -============== - -.. This file based on https://github.com/PyGithub/PyGithub/blob/master/CONTRIBUTING.md - -``flake8-encodings`` uses `tox `_ to automate testing and packaging, -and `pre-commit `_ to maintain code quality. - -Install ``pre-commit`` with ``pip`` and install the git hook: - -.. prompt:: bash - - python -m pip install pre-commit - pre-commit install - - -Coding style --------------- - -`formate `_ is used for code formatting. - -It can be run manually via ``pre-commit``: - -.. prompt:: bash - - pre-commit run formate -a - - -Or, to run the complete autoformatting suite: - -.. prompt:: bash - - pre-commit run -a - - -Automated tests -------------------- - -Tests are run with ``tox`` and ``pytest``. -To run tests for a specific Python version, such as Python 3.6: - -.. prompt:: bash - - tox -e py36 - - -To run tests for all Python versions, simply run: - -.. prompt:: bash - - tox - - -Type Annotations -------------------- - -Type annotations are checked using ``mypy``. Run ``mypy`` using ``tox``: - -.. prompt:: bash - - tox -e mypy - - - -Build documentation locally ------------------------------- - -The documentation is powered by Sphinx. A local copy of the documentation can be built with ``tox``: - -.. prompt:: bash - - tox -e docs diff --git a/doc-source/index.rst b/doc-source/index.rst index e19a982..b436d89 100644 --- a/doc-source/index.rst +++ b/doc-source/index.rst @@ -9,7 +9,9 @@ flake8-encodings .. end short_desc -.. seealso:: :pep:`597` -- Add optional EncodingWarning +.. only:: html + + .. seealso:: :pep:`597` -- Add optional EncodingWarning .. start shields @@ -62,7 +64,8 @@ flake8-encodings :workflow: mypy :alt: mypy status - .. |requires| requires-io-shield:: + .. |requires| image:: https://dependency-dash.repo-helper.uk/github/python-formate/flake8-encodings/badge.svg + :target: https://dependency-dash.repo-helper.uk/github/python-formate/flake8-encodings/ :alt: Requirements Status .. |coveralls| coveralls-shield:: @@ -108,14 +111,14 @@ flake8-encodings :alt: GitHub top language .. |commits-since| github-shield:: - :commits-since: v0.3.5 + :commits-since: v0.5.1 :alt: GitHub commits since tagged version .. |commits-latest| github-shield:: :last-commit: :alt: GitHub last commit - .. |maintained| maintained-shield:: 2021 + .. |maintained| maintained-shield:: 2025 :alt: Maintenance .. |pypi-downloads| pypi-shield:: @@ -138,6 +141,19 @@ Installation .. end installation +.. latex:vspace:: 20px + +In version 0.5.1 and above the functionality for checking classes +(:class:`~configparser.ConfigParser` and :class:`~.pathlib.Path` for now) +requires the ``classes`` extra to be installed: + +.. prompt:: bash + + python3 -m pip install flake8-encodings[classes] + +The checks for classes are slower and CPU intensive, +so only enable them if you use the classes in question. + Motivation ------------- @@ -167,6 +183,9 @@ which can be used in conjunction with this tool to identify issues at runtime. Contents ------------- +.. html-section:: + + .. toctree:: :hidden: @@ -177,14 +196,16 @@ Contents :glob: usage - contributing Source + license .. sidebar-links:: :caption: Links :github: :pypi: flake8-encodings + Contributing Guide + .. start links @@ -192,7 +213,7 @@ Contents View the :ref:`Function Index ` or browse the `Source Code <_modules/index.html>`__. - :github:repo:`Browse the GitHub Repository ` + :github:repo:`Browse the GitHub Repository ` .. end links @@ -200,6 +221,8 @@ Contents Footnotes ------------- +.. html-section:: + .. [1] "Packages can't be installed when encoding is not UTF-8" (https://github.com/methane/pep597-pypi-ascii) diff --git a/doc-source/license.rst b/doc-source/license.rst new file mode 100644 index 0000000..37033a2 --- /dev/null +++ b/doc-source/license.rst @@ -0,0 +1,10 @@ +========= +License +========= + +``flake8-encodings`` is licensed under the :choosealicense:`MIT` + +.. license-info:: MIT + +.. license:: + :py: flake8-encodings diff --git a/doc-source/requirements.txt b/doc-source/requirements.txt index 8538200..3a34638 100644 --- a/doc-source/requirements.txt +++ b/doc-source/requirements.txt @@ -1,19 +1,21 @@ -autodocsumm>=0.2.0 -default-values>=0.4.2 -extras-require>=0.2.0 -furo>=2020.11.19b18 -pyyaml>=5.3.1 -repo-helper-sphinx-theme>=0.0.2 -seed-intersphinx-mapping>=0.3.1 +default-values>=0.6.0 +extras-require>=0.5.0 +furo==2021.06.18b36 +html-section>=0.3.0 +seed-intersphinx-mapping>=1.2.2 sphinx>=3.0.3 sphinx-copybutton>=0.2.12 -sphinx-debuginfo>=0.1.0 -sphinx-notfound-page>=0.5 -sphinx-prompt>=1.1.0 +sphinx-debuginfo>=0.2.2 +sphinx-favicon>=0.2 +sphinx-licenseinfo>=0.3.1 +sphinx-notfound-page>=0.7.1 sphinx-pyproject>=0.1.0 -sphinx-tabs>=1.1.13 -sphinx-toolbox>=2.10.0 -sphinxcontrib-httpdomain>=1.7.0 +sphinx-toolbox>=3.5.0 +sphinxcontrib-applehelp==1.0.4 +sphinxcontrib-devhelp==1.0.2 +sphinxcontrib-htmlhelp==2.0.1 +sphinxcontrib-jsmath==1.0.1 +sphinxcontrib-qthelp==1.0.3 +sphinxcontrib-serializinghtml==1.1.5 sphinxemoji>=0.1.6 -tabulate>=0.8.7 -toctree-plus>=0.1.0 +toctree-plus>=0.6.1 diff --git a/doc-source/usage.rst b/doc-source/usage.rst index db36567..e118e94 100644 --- a/doc-source/usage.rst +++ b/doc-source/usage.rst @@ -8,7 +8,7 @@ This library provides the Flake8 plugin ``flake8-encodings`` to identify incorr Flake8 codes -------------- -**ENC00X**: checks for :func:`open`, :func:`builtins.open ` and :func:`io.open`. +:bold-title:`ENC00X`: checks for :func:`open`, :func:`builtins.open ` and :func:`io.open`. .. flake8-codes:: flake8_encodings @@ -19,7 +19,8 @@ Flake8 codes ``ENC003`` and ``ENC004`` are used in cases where the encoding is omitted (or is explicitly :py:obj:`None`) but the mode cannot be determined. The file might be opened in binary mode, in which case the encoding argument is ignored, or in text mode, in which case an encoding should be given. -**ENC01X**: checks for :meth:`configparser.ConfigParser.read`. + +:bold-title:`ENC01X`: checks for :meth:`configparser.ConfigParser.read`. .. flake8-codes:: flake8_encodings @@ -27,8 +28,10 @@ Flake8 codes ENC012 .. versionadded:: 0.2.0 +.. versionchanged:: 0.4.0 These codes now require the ``classes`` extra to be installed [1]_. + -**ENC02X**: checks for :meth:`pathlib.Path.open`, :meth:`read_text() ` and :meth:`write_text() `. +:bold-title:`ENC02X`: checks for :meth:`pathlib.Path.open`, :meth:`read_text() ` and :meth:`write_text() `. .. flake8-codes:: flake8_encodings @@ -40,12 +43,17 @@ Flake8 codes ENC026 .. versionadded:: 0.3.0 +.. versionchanged:: 0.4.0 These codes now require the ``classes`` extra to be installed [1]_. + +.. [1] Install using ``python3 -m pip install flake8-encodings[classes]`` + Examples ^^^^^^^^^^ .. code-block:: python + # stdlib import configparser open("README.rst").read() # ENC001 no encoding specified for 'open'. @@ -54,9 +62,10 @@ Examples open("README.rst", mode="rb", encoding=None).read() # OK - def foo(mode: str = "r"): + def foo(mode: str = 'r'): open("README.rst", mode=mode).read() # ENC003 no encoding specified for 'open' with unknown mode. - open("README.rst", mode=mode, encoding=None).read() # ENC004 'encoding=None' used for 'open' with unknown mode. + open("README.rst", mode=mode, + encoding=None).read() # ENC004 'encoding=None' used for 'open' with unknown mode. def load_config(filename: str): @@ -64,12 +73,13 @@ Examples cfg.read(filename) # ENC011 # cfg.read(filename, encoding=None) # ENC012 + def manipulate_file(filename): path = pathlib.Path(filename) path.write_text("Hello world") # ENC025 - with path.open("a") as fp: # ENC021 + with path.open('a') as fp: # ENC021 f.write("\nHello everyone") print(path.read_text(encoding=None)) # ENC024 @@ -83,4 +93,4 @@ See `pre-commit `_ for instructions Sample ``.pre-commit-config.yaml``: -.. pre-commit:flake8:: 0.3.5 +.. pre-commit:flake8:: 0.5.1 diff --git a/flake8_encodings/__init__.py b/flake8_encodings/__init__.py index d6fc3cd..76d0317 100644 --- a/flake8_encodings/__init__.py +++ b/flake8_encodings/__init__.py @@ -38,23 +38,28 @@ import ast import configparser import pathlib +import sys import tempfile -from typing import Callable, Iterator, List, Optional, Tuple, Type +from typing import TYPE_CHECKING, Callable, Iterator, List, Optional, Tuple, Type # 3rd party import flake8_helper -import jedi # type: ignore from astatine import get_attribute_name, kwargs_from_node from domdf_python_tools.paths import PathPlus from domdf_python_tools.typing import PathLike +if TYPE_CHECKING: + # 3rd party + from jedi import Script # type: ignore[import-untyped] + from jedi.api.classes import Name # type: ignore[import-untyped] + __author__: str = "Dominic Davis-Foster" __copyright__: str = "2020-2021 Dominic Davis-Foster" __license__: str = "MIT License" -__version__: str = "0.3.5" +__version__: str = "0.5.1" __email__: str = "dominic@davis-foster.co.uk" -__all__ = ["Visitor", "Plugin"] +__all__ = ["Visitor", "ClassVisitor", "Plugin"] ENC001 = "ENC001 no encoding specified for 'open'." ENC002 = "ENC002 'encoding=None' used for 'open'." @@ -71,8 +76,6 @@ ENC025 = "ENC025 no encoding specified for 'pathlib.Path.write_text'." ENC026 = "ENC026 'encoding=None' used for 'pathlib.Path.write_text'." -jedi.settings.fast_parser = False - _configparser_read = configparser.ConfigParser().read _pathlib_open = pathlib.Path().open _pathlib_read_text = pathlib.Path().read_text @@ -90,45 +93,38 @@ def mode_is_binary(mode: ast.AST) -> Optional[bool]: if isinstance(mode, ast.Constant): # pragma: no cover (") - self.jedi_script = jedi.Script('') +if sys.version_info < (3, 12): # pragma: no cover (py312+) + _constant_nameconstant = (ast.Constant, ast.NameConstant) + _skip_312_deprecations = False +else: # pragma: no cover ( None: """ Check the call represented by the given AST node is using encodings correctly. This function checks :func:`open`, :func:`builtins.open ` and :func:`io.open`. - .. versionchanged:: 0.2.0 - - Renamed from ``check_encoding`` + .. versionchanged:: 0.2.0 Renamed from ``check_encoding`` """ kwargs = kwargs_from_node(node, open) @@ -150,13 +146,85 @@ def check_open_encoding(self, node: ast.Call): if "encoding" not in kwargs: self.report_error(node, ENC003 if unknown_mode else ENC001) - elif isinstance(kwargs["encoding"], (ast.Constant, ast.NameConstant)): + elif isinstance(kwargs["encoding"], _constant_nameconstant): if kwargs["encoding"].value is None: self.report_error(node, ENC004 if unknown_mode else ENC002) check_encoding = check_open_encoding # deprecated - def check_configparser_encoding(self, node: ast.Call): + def visit_Call(self, node: ast.Call) -> None: # noqa: D102 + + if isinstance(node.func, ast.Name): + + if node.func.id == "open": + # print(node.func.id) + self.check_encoding(node) + return + + elif isinstance(node.func, ast.Attribute): + if isinstance(node.func.value, ast.Name): + + if node.func.value.id in {"builtins", "io"} and node.func.attr == "open": + self.check_open_encoding(node) + return + + if not _skip_312_deprecations: # pragma: no cover (py312+) + if isinstance(node.func.value, ast.Str): # pragma: no cover + # Attribute on a string + return self.generic_visit(node) + + if isinstance(node.func.value, ast.BinOp): # pragma: no cover + # TODO + # Expressions such as (tmp_pathplus / "code.py").write_text(example_source) + return self.generic_visit(node) + + elif isinstance(node.func.value, ast.Subscript): # pragma: no cover + # TODO + # Expressions such as my_list[0].run() + return self.generic_visit(node) + + self.generic_visit(node) + + +class ClassVisitor(Visitor): # pragma: no cover (py313+) + """ + AST visitor to identify incorrect use of encodings, + with support for :class:`pathlib.Path` and :class:`configparser.ConfigParser`. + + .. versionadded:: 0.4.0 + """ # noqa: D400 + + def __init__(self): + try: + # 3rd party + import jedi + except ImportError as e: + exc = e.__class__("This class requires 'jedi' to be installed but it could not be imported.") + exc.__traceback__ = e.__traceback__ + raise exc from None + + super().__init__() + self.filename = PathPlus("") + self.jedi_script = jedi.Script('') + + def first_visit(self, node: ast.AST, filename: PathPlus) -> None: + """ + Like :meth:`ast.NodeVisitor.visit`, but configures type inference. + + .. versionadded:: 0.2.0 + + :param node: + :param filename: The path to Python source file the AST node was generated from. + """ + + # 3rd party + import jedi # nodep + + self.filename = PathPlus(filename) + self.jedi_script = jedi.Script(self.filename.read_text(), path=self.filename) + self.visit(node) + + def check_configparser_encoding(self, node: ast.Call) -> None: """ Check the call represented by the given AST node is using encodings correctly. @@ -170,11 +238,11 @@ def check_configparser_encoding(self, node: ast.Call): if "encoding" not in kwargs: self.report_error(node, ENC011) - elif isinstance(kwargs["encoding"], (ast.Constant, ast.NameConstant)): + elif isinstance(kwargs["encoding"], _constant_nameconstant): if kwargs["encoding"].value is None: self.report_error(node, ENC012) - def check_pathlib_encoding(self, node: ast.Call, method_name: str): + def check_pathlib_encoding(self, node: ast.Call, method_name: str) -> None: """ Check the call represented by the given AST node is using encodings correctly. @@ -219,11 +287,11 @@ def check_pathlib_encoding(self, node: ast.Call, method_name: str): if "encoding" not in kwargs: self.report_error(node, no_encoding) - elif isinstance(kwargs["encoding"], (ast.Constant, ast.NameConstant)): + elif isinstance(kwargs["encoding"], _constant_nameconstant): if kwargs["encoding"].value is None: self.report_error(node, encoding_none) - def visit_Call(self, node: ast.Call): # noqa: D102 + def visit_Call(self, node: ast.Call) -> None: # noqa: D102 if isinstance(node.func, ast.Name): @@ -239,11 +307,12 @@ def visit_Call(self, node: ast.Call): # noqa: D102 self.check_open_encoding(node) return - if isinstance(node.func.value, ast.Str): # pragma: no cover - # Attribute on a string - return self.generic_visit(node) + if not _skip_312_deprecations: # pragma: no cover (py312+) + if isinstance(node.func.value, ast.Str): # pragma: no cover + # Attribute on a string + return self.generic_visit(node) - elif isinstance(node.func.value, ast.BinOp): # pragma: no cover + if isinstance(node.func.value, ast.BinOp): # pragma: no cover # TODO # Expressions such as (tmp_pathplus / "code.py").write_text(example_source) return self.generic_visit(node) @@ -292,21 +361,34 @@ def __init__(self, tree: ast.AST, filename: PathLike): def run(self) -> Iterator[Tuple[int, int, str, Type["Plugin"]]]: # noqa: D102 - original_cache_dir = jedi.settings.cache_directory + try: # pragma: no cover (py313+) + # 3rd party + import jedi + + # jedi.settings.fast_parser = False - with tempfile.TemporaryDirectory() as cache_directory: - jedi.settings.cache_directory = cache_directory + original_cache_dir = jedi.settings.cache_directory + with tempfile.TemporaryDirectory() as cache_directory: + jedi.settings.cache_directory = cache_directory + + class_visitor = ClassVisitor() + class_visitor.first_visit(self._tree, self.filename) + + for line, col, msg in class_visitor.errors: + yield line, col, msg, type(self) + + jedi.settings.cache_directory = original_cache_dir + + except ImportError: visitor = Visitor() - visitor.first_visit(self._tree, self.filename) + visitor.visit(self._tree) for line, col, msg in visitor.errors: yield line, col, msg, type(self) - jedi.settings.cache_directory = original_cache_dir - -def is_configparser_read(class_name: str, method_name: str) -> bool: +def is_configparser_read(class_name: str, method_name: str) -> bool: # pragma: no cover (py313+) """ Returns :py:obj:`True` if method is :meth:`configparser.ConfigParser.read` or :meth:`configparser.RawConfigParser.read`. @@ -326,7 +408,7 @@ def is_configparser_read(class_name: str, method_name: str) -> bool: return True -def is_pathlib_method(class_name: str, method_name: str) -> bool: +def is_pathlib_method(class_name: str, method_name: str) -> bool: # pragma: no cover (py313+) """ Returns :py:obj:`True` if method is :meth:`pathlib.Path.open`, :meth:`read_text() ` or :meth:`write_text() `. @@ -346,7 +428,7 @@ def is_pathlib_method(class_name: str, method_name: str) -> bool: return True -def get_inferred_types(jedi_script: jedi.Script, node: ast.Call) -> List[str]: +def get_inferred_types(jedi_script: "Script", node: ast.Call) -> List[str]: # pragma: no cover (py313+) """ Returns a list of types inferred by ``jedi`` for the given call node. @@ -357,7 +439,7 @@ def get_inferred_types(jedi_script: jedi.Script, node: ast.Call) -> List[str]: attr_names = tuple(get_attribute_name(node.func)) inferred_types = set() - inferred_name: jedi.api.classes.Name + inferred_name: "Name" for inferred_name in jedi_script.infer(node.lineno, node.func.col_offset): inferred_types.add(inferred_name.full_name) diff --git a/formate.toml b/formate.toml index d85fcd5..a2e27c5 100644 --- a/formate.toml +++ b/formate.toml @@ -6,21 +6,17 @@ noqa-reformat = 60 ellipsis-reformat = 70 squish_stubs = 80 -[config] -indent = "\t" -line_length = 115 - [hooks.yapf] priority = 30 -[hooks.isort] -priority = 50 - [hooks.yapf.kwargs] yapf_style = ".style.yapf" +[hooks.isort] +priority = 50 + [hooks.isort.kwargs] -indent = "\t\t" +indent = " " multi_line_output = 8 import_heading_stdlib = "stdlib" import_heading_thirdparty = "3rd party" @@ -52,4 +48,8 @@ known_third_party = [ "pytest_timeout", "requests", ] -known_first_party = "flake8_encodings" +known_first_party = [ "flake8_encodings",] + +[config] +indent = " " +line_length = 115 diff --git a/justfile b/justfile new file mode 100644 index 0000000..e8ed871 --- /dev/null +++ b/justfile @@ -0,0 +1,22 @@ +default: lint + +pdf-docs: latex-docs + make -C doc-source/build/latex/ + +latex-docs: + SPHINX_BUILDER=latex tox -e docs + +unused-imports: + tox -e lint -- --select F401 + +incomplete-defs: + tox -e lint -- --select MAN + +vdiff: + git diff $(repo-helper show version -q)..HEAD + +bare-ignore: + greppy '# type:? *ignore(?!\[|\w)' -s + +lint: unused-imports incomplete-defs bare-ignore + tox -n qa diff --git a/pyproject.toml b/pyproject.toml index c7afe30..4858e2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,26 +4,32 @@ build-backend = "whey" [project] name = "flake8-encodings" -version = "0.3.5" +version = "0.5.1" description = "A Flake8 plugin to identify incorrect use of encodings." readme = "README.rst" keywords = [ "encodings", "flake8", "pep597", "unicode",] dynamic = [ "requires-python", "classifiers", "dependencies",] +[project.license] +file = "LICENSE" + [[project.authors]] name = "Dominic Davis-Foster" email = "dominic@davis-foster.co.uk" - -[project.license] -file = "LICENSE" - [project.urls] -Homepage = "https://github.com/domdfcoding/flake8-encodings" -"Issue Tracker" = "https://github.com/domdfcoding/flake8-encodings/issues" -"Source Code" = "https://github.com/domdfcoding/flake8-encodings" +Homepage = "https://github.com/python-formate/flake8-encodings" +"Issue Tracker" = "https://github.com/python-formate/flake8-encodings/issues" +"Source Code" = "https://github.com/python-formate/flake8-encodings" Documentation = "https://flake8-encodings.readthedocs.io/en/latest" +[project.entry-points."flake8.extension"] +ENC0 = "flake8_encodings:Plugin" + +[project.optional-dependencies] +classes = [ "jedi>=0.18.0",] +all = [ "jedi>=0.18.0",] + [tool.whey] base-classifiers = [ "Development Status :: 4 - Beta", @@ -32,7 +38,7 @@ base-classifiers = [ "Topic :: Utilities", "Typing :: Typed", ] -python-versions = [ "3.6", "3.7", "3.8", "3.9",] +python-versions = [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13",] python-implementations = [ "CPython", "PyPy",] platforms = [ "Windows", "macOS", "Linux",] license-key = "MIT" @@ -43,11 +49,11 @@ conda-channels = [ "conda-forge", "domdfcoding",] extras = "all" [tool.sphinx-pyproject] -github_username = "domdfcoding" +github_username = "python-formate" github_repository = "flake8-encodings" author = "Dominic Davis-Foster" project = "flake8-encodings" -copyright = "2020-2021 Dominic Davis-Foster" +copyright = "2020-2022 Dominic Davis-Foster" language = "en" package_root = "flake8_encodings" extensions = [ @@ -56,24 +62,24 @@ extensions = [ "sphinx_toolbox.more_autosummary", "sphinx_toolbox.documentation_summary", "sphinx_toolbox.tweaks.param_dash", + "sphinxcontrib.toctree_plus", "sphinx_toolbox.tweaks.latex_layout", "sphinx_toolbox.tweaks.latex_toc", "sphinx.ext.intersphinx", "sphinx.ext.mathjax", - "sphinxcontrib.httpdomain", "sphinxcontrib.extras_require", "sphinx.ext.todo", - "sphinxemoji.sphinxemoji", "notfound.extension", "sphinx_copybutton", "sphinxcontrib.default_values", - "sphinxcontrib.toctree_plus", "sphinx_debuginfo", + "sphinx_licenseinfo", "seed_intersphinx_mapping", + "html_section", "sphinx_toolbox.pre_commit", "sphinx_toolbox.flake8", + "sphinx_favicon", ] -sphinxemoji_style = "twemoji" gitstamp_fmt = "%d %b %Y" templates_path = [ "_templates",] html_static_path = [ "_static",] @@ -102,6 +108,7 @@ add_module_names = false hide_none_rtype = true all_typevars = true overloads_location = "bottom" +html_codeblock_linenos_style = "table" autodoc_exclude_members = [ "__dict__", "__class__", @@ -121,5 +128,34 @@ autodoc_exclude_members = [ "__hash__", ] -[project.entry-points."flake8.extension"] -ENC0 = "flake8_encodings:Plugin" +[tool.mypy] +python_version = "3.9" +namespace_packages = true +check_untyped_defs = true +warn_unused_ignores = true +no_implicit_optional = true +show_error_codes = true + +[tool.snippet-fmt] +directives = [ "code-block",] + +[tool.snippet-fmt.languages.python] +reformat = true + +[tool.snippet-fmt.languages.TOML] +reformat = true + +[tool.snippet-fmt.languages.ini] + +[tool.snippet-fmt.languages.json] + +[tool.dependency-dash."requirements.txt"] +order = 10 + +[tool.dependency-dash."tests/requirements.txt"] +order = 20 +include = false + +[tool.dependency-dash."doc-source/requirements.txt"] +order = 30 +include = false diff --git a/repo_helper.yml b/repo_helper.yml index befb025..cfba98e 100644 --- a/repo_helper.yml +++ b/repo_helper.yml @@ -1,32 +1,40 @@ # Configuration for 'repo_helper' (https://github.com/domdfcoding/repo_helper) --- modname: flake8-encodings -copyright_years: "2020-2021" +copyright_years: "2020-2022" author: "Dominic Davis-Foster" email: "dominic@davis-foster.co.uk" -version: "0.3.5" -username: "domdfcoding" +version: "0.5.1" +username: "python-formate" +assignee: "domdfcoding" +primary_conda_channel: "domdfcoding" license: 'MIT' short_desc: "A Flake8 plugin to identify incorrect use of encodings." -min_coverage: 100 +min_coverage: 94 use_whey: true -python_deploy_version: 3.6 +mypy_version: 1.16 +python_deploy_version: 3.9 docs_fail_on_warning: true -mypy_version: "0.812" +tox_testenv_extras: classes +sphinx_html_theme: furo conda_channels: - conda-forge # Versions to run tests for python_versions: - - '3.6' - - '3.7' - - '3.8' - - '3.9' - - 3.10-dev - - pypy36 - - pypy37 + 3.7: + 3.8: + 3.9: + "3.10": + 3.11: + 3.12: + 3.13: + experimental: true + pypy37: + pypy38: + pypy39: classifiers: - 'Development Status :: 4 - Beta' @@ -37,14 +45,12 @@ classifiers: extra_sphinx_extensions: - sphinx_toolbox.pre_commit - sphinx_toolbox.flake8 + - sphinx_favicon entry_points: flake8.extension: - ENC0=flake8_encodings:Plugin -sphinx_html_theme: furo -standalone_contrib_guide: true - keywords: - flake8 - encodings @@ -52,4 +58,17 @@ keywords: - unicode sphinx_conf_epilogue: + - needspace_amount = r"5\baselineskip" + - 'favicons = [{"rel": "icon", "href": "https://python-formate.github.io/assets/formate.ico", "sizes": "48x48", "type": "image/vnd.microsoft.icon"}]' - nitpicky = True + +extras_require: + classes: + - jedi>=0.18.0 + +tox_unmanaged: + - testenv + - testenv:py313 + +exclude_files: + - contributing diff --git a/requirements.txt b/requirements.txt index ebf1a7f..f6dcd87 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ astatine>=0.3.1 domdf-python-tools>=2.8.1 -flake8>=3.7 +flake8>=3.8.4 flake8-helper>=0.1.1 -jedi>=0.18.0 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 18c9c04..0000000 --- a/setup.cfg +++ /dev/null @@ -1,16 +0,0 @@ -# This file is managed by 'repo_helper'. -# You may add new sections, but any changes made to the following sections will be lost: -# * metadata -# * options -# * options.packages.find -# * mypy -# * options.entry_points - -[mypy] -python_version = 3.6 -namespace_packages = True -check_untyped_defs = True -warn_unused_ignores = True - -[options.entry_points] -flake8.extension = ENC0=flake8_encodings:Plugin diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 45a47f3..e940c0f 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -2,6 +2,7 @@ import ast # 3rd party +import pytest from coincidence.regressions import AdvancedDataRegressionFixture from domdf_python_tools.paths import PathPlus @@ -9,8 +10,28 @@ from flake8_encodings import Plugin from tests.example_source import example_source +try: + # 3rd party + import jedi # type: ignore[import-untyped] # noqa: F401 + has_jedi = True +except ImportError: + has_jedi = False -def test_plugin(tmp_pathplus: PathPlus, advanced_data_regression: AdvancedDataRegressionFixture): +skip_reason = "Output differs depending on jedi availability" + + +@pytest.mark.parametrize( + "has_jedi", + [ + pytest.param(True, id="has_jedi", marks=pytest.mark.skipif(not has_jedi, reason=skip_reason)), + pytest.param(False, id="no_jedi", marks=pytest.mark.skipif(has_jedi, reason=skip_reason)), + ] + ) +def test_plugin( + tmp_pathplus: PathPlus, + advanced_data_regression: AdvancedDataRegressionFixture, + has_jedi: bool, + ): (tmp_pathplus / "code.py").write_text(example_source) plugin = Plugin(ast.parse(example_source), filename=str(tmp_pathplus / "code.py")) diff --git a/tests/test_plugin_/test_plugin.yml b/tests/test_plugin_/test_plugin_has_jedi_.yml similarity index 100% rename from tests/test_plugin_/test_plugin.yml rename to tests/test_plugin_/test_plugin_has_jedi_.yml diff --git a/tests/test_plugin_/test_plugin_no_jedi_.yml b/tests/test_plugin_/test_plugin_no_jedi_.yml new file mode 100644 index 0000000..1852d01 --- /dev/null +++ b/tests/test_plugin_/test_plugin_no_jedi_.yml @@ -0,0 +1,5 @@ +- '6:9: ENC001 no encoding specified for ''open''.' +- '11:10: ENC001 no encoding specified for ''open''.' +- '12:10: ENC001 no encoding specified for ''open''.' +- '13:10: ENC002 ''encoding=None'' used for ''open''.' +- '23:11: ENC003 no encoding specified for ''open'' with unknown mode.' diff --git a/tests/test_visitor.py b/tests/test_visitor.py index 3975a58..3d21116 100644 --- a/tests/test_visitor.py +++ b/tests/test_visitor.py @@ -2,13 +2,21 @@ import ast # 3rd party +import pytest from coincidence.regressions import AdvancedDataRegressionFixture from domdf_python_tools.paths import PathPlus # this package -from flake8_encodings import Visitor +from flake8_encodings import ClassVisitor, Visitor from tests.example_source import example_source +try: + # 3rd party + import jedi # type: ignore[import-untyped] # noqa: F401 + has_jedi = True +except ImportError: + has_jedi = False + def test_visitor(advanced_data_regression: AdvancedDataRegressionFixture): visitor = Visitor() @@ -17,9 +25,34 @@ def test_visitor(advanced_data_regression: AdvancedDataRegressionFixture): def test_visitor_with_jedi(tmp_pathplus: PathPlus, advanced_data_regression: AdvancedDataRegressionFixture): - visitor = Visitor() + pytest.importorskip("jedi") + + visitor = ClassVisitor() (tmp_pathplus / "code.py").write_text(example_source) visitor.first_visit(ast.parse(example_source), filename=tmp_pathplus / "code.py") advanced_data_regression.check(visitor.errors) + + +def test_visitor_with_jedi_visit_method( + tmp_pathplus: PathPlus, advanced_data_regression: AdvancedDataRegressionFixture + ): + pytest.importorskip("jedi") + + visitor = ClassVisitor() + + (tmp_pathplus / "code.py").write_text(example_source) + + visitor.visit(ast.parse(example_source)) + advanced_data_regression.check(visitor.errors) + + +def test_classvisitor_importerror(): + if has_jedi: + pytest.skip(reason="Requires that jedi isn't installed") + + with pytest.raises( + ImportError, match="This class requires 'jedi' to be installed but it could not be imported." + ): + ClassVisitor() diff --git a/tests/test_visitor_/test_visitor_with_jedi_visit_method.yml b/tests/test_visitor_/test_visitor_with_jedi_visit_method.yml new file mode 100644 index 0000000..e69b377 --- /dev/null +++ b/tests/test_visitor_/test_visitor_with_jedi_visit_method.yml @@ -0,0 +1,15 @@ +- - 6 + - 9 + - ENC001 no encoding specified for 'open'. +- - 11 + - 10 + - ENC001 no encoding specified for 'open'. +- - 12 + - 10 + - ENC001 no encoding specified for 'open'. +- - 13 + - 10 + - ENC002 'encoding=None' used for 'open'. +- - 23 + - 11 + - ENC003 no encoding specified for 'open' with unknown mode. diff --git a/tox.ini b/tox.ini index 1c31466..cab0e44 100644 --- a/tox.ini +++ b/tox.ini @@ -2,10 +2,14 @@ # You may add new sections, but any changes made to the following sections will be lost: # * tox # * envlists -# * testenv +# * testenv:.package +# * testenv:py313-dev +# * testenv:py312-dev +# * testenv:py312 # * testenv:docs # * testenv:build # * testenv:lint +# * testenv:perflint # * testenv:mypy # * testenv:pyup # * testenv:coverage @@ -16,92 +20,130 @@ # * pytest [tox] -envlist = py36, py37, py38, py39, py310-dev, pypy36, pypy37, mypy, build +envlist = + py37 + py38 + py39 + py310 + py311 + py312 + py313 + pypy37 + pypy38 + pypy39 + mypy + build skip_missing_interpreters = True isolated_build = True requires = - pip>=20.3.3 + pip>=21,!=22.2 tox-envlist>=0.2.1 - tox-pip-version>=0.0.7 + tox~=3.0 + virtualenv!=20.16.0 [envlists] -test = py36, py37, py38, py39, py310-dev, pypy36, pypy37 +test = py37, py38, py39, py310, py311, py312, py313, pypy37, pypy38, pypy39 qa = mypy, lint -cov = py36, coverage +cov = py39, coverage -[testenv] -setenv = PYTHONDEVMODE = 1 -deps = -r{toxinidir}/tests/requirements.txt -commands = - python --version - python -m pytest --cov=flake8_encodings -r aR tests/ {posargs} +[testenv:.package] +setenv = + PYTHONDEVMODE=1 + PIP_DISABLE_PIP_VERSION_CHECK=1 + +[testenv:py312] +download = True +setenv = + PYTHONDEVMODE=1 + PIP_DISABLE_PIP_VERSION_CHECK=1 [testenv:docs] setenv = SHOW_TODOS = 1 +passenv = SPHINX_BUILDER basepython = python3.8 -pip_version = pip>=21 changedir = {toxinidir}/doc-source +extras = classes deps = -r{toxinidir}/doc-source/requirements.txt commands = sphinx-build -M {env:SPHINX_BUILDER:html} . ./build {posargs} [testenv:build] +setenv = + PYTHONDEVMODE=1 + PIP_DISABLE_PIP_VERSION_CHECK=1 + PIP_PREFER_BINARY=1 + UNSAFE_PYO3_SKIP_VERSION_CHECK=1 skip_install = True changedir = {toxinidir} deps = build[virtualenv]>=0.3.1 check-wheel-contents>=0.1.0 twine>=3.2.0 + cryptography<40; implementation_name == "pypy" and python_version <= "3.7" commands = python -m build --sdist --wheel "{toxinidir}" twine check dist/*.tar.gz dist/*.whl check-wheel-contents dist/ [testenv:lint] -basepython = python3.6 +basepython = python3.9 changedir = {toxinidir} ignore_errors = True skip_install = False deps = - flake8>=3.8.2 + flake8>=3.8.2,<5 flake8-2020>=1.6.0 flake8-builtins>=1.5.3 flake8-docstrings>=1.5.0 flake8-dunder-all>=0.1.1 flake8-encodings>=0.1.0 flake8-github-actions>=0.1.0 - flake8-pyi>=20.10.0 - flake8-pytest-style>=1.3.0 + flake8-noqa>=1.1.0,<=1.2.2 + flake8-pyi>=20.10.0,<=22.8.0 + flake8-pytest-style>=1.3.0,<2 + flake8-quotes>=3.3.0 flake8-slots>=0.1.0 flake8-sphinx-links>=0.0.4 flake8-strftime>=0.1.1 flake8-typing-imports>=1.10.0 - git+https://github.com/domdfcoding/flake8-quotes.git git+https://github.com/domdfcoding/flake8-rst-docstrings-sphinx.git git+https://github.com/domdfcoding/flake8-rst-docstrings.git - pydocstyle>=6.0.0 + git+https://github.com/python-formate/flake8-unused-arguments.git@magic-methods + git+https://github.com/python-formate/flake8-missing-annotations.git + git+https://github.com/domdfcoding/pydocstyle.git@stub-functions pygments>=2.7.1 + importlib_metadata<4.5.0; python_version<'3.8' commands = python3 -m flake8_rst_docstrings_sphinx flake8_encodings tests --allow-toolbox {posargs} +[testenv:perflint] +basepython = python3.9 +changedir = {toxinidir} +ignore_errors = True +skip_install = True +deps = perflint +commands = python3 -m perflint flake8_encodings {posargs} + [testenv:mypy] -basepython = python3.6 +basepython = python3.9 ignore_errors = True changedir = {toxinidir} +extras = classes deps = - mypy==0.812 + mypy==1.16 -r{toxinidir}/tests/requirements.txt -r{toxinidir}/stubs.txt commands = mypy flake8_encodings tests {posargs} [testenv:pyup] -basepython = python3.6 +basepython = python3.9 skip_install = True ignore_errors = True changedir = {toxinidir} deps = pyupgrade-directories +extras = classes commands = pyup_dirs flake8_encodings tests --py36-plus --recursive [testenv:coverage] -basepython = python3.6 +basepython = python3.9 skip_install = True ignore_errors = True whitelist_externals = /bin/bash @@ -109,6 +151,7 @@ passenv = COV_PYTHON_VERSION COV_PLATFORM COV_PYTHON_IMPLEMENTATION + * changedir = {toxinidir} deps = coverage>=5 @@ -120,12 +163,15 @@ commands = [flake8] max-line-length = 120 -select = E111 E112 E113 E121 E122 E125 E127 E128 E129 E131 E133 E201 E202 E203 E211 E222 E223 E224 E225 E225 E226 E227 E228 E231 E241 E242 E251 E261 E262 E265 E271 E272 E303 E304 E306 E402 E502 E703 E711 E712 E713 E714 E721 W291 W292 W293 W391 W504 YTT101 YTT102 YTT103 YTT201 YTT202 YTT203 YTT204 YTT301 YTT302 YTT303 STRFTIME001 STRFTIME002 SXL001 PT001 PT002 PT003 PT006 PT007 PT008 PT009 PT010 PT011 PT012 PT013 PT014 PT015 PT016 PT017 PT018 PT019 PT020 PT021 RST201 RST202 RST203 RST204 RST205 RST206 RST207 RST208 RST210 RST211 RST212 RST213 RST214 RST215 RST216 RST217 RST218 RST219 RST299 RST301 RST302 RST303 RST304 RST305 RST306 RST399 RST401 RST499 RST900 RST901 RST902 RST903 Q001 Q002 Q003 A001 A002 A003 TYP001 TYP002 TYP003 TYP004 TYP005 TYP006 ENC001 ENC002 ENC003 ENC004 ENC011 ENC012 ENC021 ENC022 ENC023 ENC024 ENC025 ENC026 Y001,Y002 Y003 Y004 Y005 Y006 Y007 Y008 Y009 Y010 Y011 Y012 Y013 Y014 Y015 Y090 Y091 E301 E302 E305 D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000 SLOT000 SLOT001 SLOT002 +select = E111 E112 E113 E121 E122 E125 E127 E128 E129 E131 E133 E201 E202 E203 E211 E222 E223 E224 E225 E225 E226 E227 E228 E231 E241 E242 E251 E261 E262 E265 E271 E272 E303 E304 E306 E402 E502 E703 E711 E712 E713 E714 E721 W291 W292 W293 W391 W504 YTT101 YTT102 YTT103 YTT201 YTT202 YTT203 YTT204 YTT301 YTT302 YTT303 STRFTIME001 STRFTIME002 SXL001 PT001 PT002 PT003 PT006 PT007 PT008 PT009 PT010 PT011 PT012 PT013 PT014 PT015 PT016 PT017 PT018 PT019 PT020 PT021 RST201 RST202 RST203 RST204 RST205 RST206 RST207 RST208 RST210 RST211 RST212 RST213 RST214 RST215 RST216 RST217 RST218 RST219 RST299 RST301 RST302 RST303 RST304 RST305 RST306 RST399 RST401 RST499 RST900 RST901 RST902 RST903 Q001 Q002 Q003 A001 A002 TYP001 TYP002 TYP003 TYP004 TYP005 TYP006 ENC001 ENC002 ENC003 ENC004 ENC011 ENC012 ENC021 ENC022 ENC023 ENC024 ENC025 ENC026 Y001,Y002 Y003 Y004 Y005 Y006 Y007 Y008 Y009 Y010 Y011 Y012 Y013 Y014 Y015 Y090 Y091 NQA001 NQA002 NQA003 NQA004 NQA005 NQA102 NQA103 E301 E302 E305 D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000 SLOT000 SLOT001 SLOT002 extend-exclude = doc-source,old,build,dist,__pkginfo__.py,setup.py,venv rst-directives = TODO envvar extras-require + license + license-info +rst-roles = choosealicense per-file-ignores = tests/*: D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000 SLOT000 SLOT001 SLOT002 */*.pyi: E301 E302 E305 D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000 SLOT000 SLOT001 SLOT002 @@ -134,20 +180,25 @@ inline-quotes = " multiline-quotes = """ docstring-quotes = """ count = True -min_python_version = 3.6.1 +min_python_version = 3.7 +unused-arguments-ignore-abstract-functions = True +unused-arguments-ignore-overload-functions = True +unused-arguments-ignore-magic-methods = True +unused-arguments-ignore-variadic-names = True [coverage:run] plugins = coverage_pyver_pragma [coverage:report] -fail_under = 100 +fail_under = 94 +show_missing = True exclude_lines = raise AssertionError raise NotImplementedError if 0: if False: - if TYPE_CHECKING: - if typing.TYPE_CHECKING: + if TYPE_CHECKING + if typing.TYPE_CHECKING if __name__ == .__main__.: [check-wheel-contents] @@ -158,6 +209,35 @@ package = flake8_encodings [pytest] addopts = --color yes --durations 25 timeout = 300 +filterwarnings = + error + ignore:can't resolve package from __spec__ or __package__, falling back on __name__ and __path__:ImportWarning + +[testenv:py313] +download = True +setenv = + PYTHONDEVMODE=1 + PIP_DISABLE_PIP_VERSION_CHECK=1 + UNSAFE_PYO3_SKIP_VERSION_CHECK=1 +commands = + python --version + python -m pip uninstall jedi -y + python -m pytest --cov=flake8_encodings -r aR tests/ --cov-append {posargs} + +[testenv] +setenv = + PYTHONDEVMODE=1 + PIP_DISABLE_PIP_VERSION_CHECK=1 + SETUPTOOLS_USE_DISTUTILS=stdlib +deps = -r{toxinidir}/tests/requirements.txt +ignore_errors = True +commands = + python --version + python -m pip install jedi + python -m pytest --cov=flake8_encodings -r aR tests/ {posargs} + python -m pip uninstall jedi -y + python -m pytest --cov=flake8_encodings -r aR tests/ --cov-append {posargs} + [dep_checker] allowed_unused = flake8