diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 491deae0..b9fb8a6e 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,7 +1,11 @@ version: 2 updates: -- package-ecosystem: pip - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 + - package-ecosystem: pip + directory: "/" + schedule: + interval: daily + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d64a4aca..0dab2e22 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,20 +21,15 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: 3.8 - - name: Cache PyPI - uses: actions/cache@v2 - with: - key: pip-lint-${{ hashFiles('requirements-dev.txt') }} - path: ~/.cache/pip - restore-keys: | - pip-lint- + cache: 'pip' + cache-dependency-path: '**/requirements*.txt' - name: Pre-Commit hooks - uses: pre-commit/action@v2.0.0 + uses: pre-commit/action@v3.0.0 - name: Install dependencies - uses: py-actions/py-dependency-install@v3.0.0 + uses: py-actions/py-dependency-install@v3 with: path: requirements-dev.txt - name: Install itself @@ -65,35 +60,25 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Setup Python ${{ matrix.pyver }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.pyver }} - - name: Get pip cache dir - id: pip-cache - run: | - echo "::set-output name=dir::$(pip cache dir)" # - name: Cache - - name: Cache PyPI - uses: actions/cache@v2 - with: - key: pip-ci-${{ runner.os }}-${{ matrix.pyver }}-${{ hashFiles('requirements-dev.txt') }} - path: ${{ steps.pip-cache.outputs.dir }} - restore-keys: | - pip-ci-${{ runner.os }}-${{ matrix.pyver }}- + cache: 'pip' + cache-dependency-path: '**/requirements*.txt' - name: Install dependencies - uses: py-actions/py-dependency-install@v3.0.0 + uses: py-actions/py-dependency-install@v3 with: path: requirements-dev.txt - name: Run unittests - run: pytest --cov=aiohttp_debugtoolbar --cov-report xml --cov-report html --cov-report term + run: pytest --cov-report=xml tests env: COLOR: 'yes' - run: python -m coverage xml - name: Upload coverage - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 with: file: ./coverage.xml flags: unit - fail_ci_if_error: false check: # This job does nothing and is only used for the branch protection if: always() @@ -118,18 +103,23 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: 3.8 - name: Install dependencies run: - python -m pip install -U build pip wheel twine + python -m pip install -U build setuptools wheel twine - name: Make dists run: python -m build - - name: PyPI upload - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} - run: | - twine upload dist/* + - name: Make Release + uses: aio-libs/create-release@v1.6.6 + with: + changes_file: CHANGES.rst + name: aiohttp-debugtoolbar + version_file: aiohttp_debugtoolbar/__init__.py + github_token: ${{ secrets.GITHUB_TOKEN }} + pypi_token: ${{ secrets.PYPI_API_TOKEN }} + dist_dir: dist + fix_issue_regex: "`#(\\d+) `" + fix_issue_repl: "(#\\1)" diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..08fa6192 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,41 @@ +name: "CodeQL" + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + schedule: + - cron: "33 2 * * 2" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ python ] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + queries: +security-and-quality + + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{ matrix.language }}" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f1d8fd0..de8638dd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,48 +1,29 @@ repos: -- repo: local - hooks: - - id: changelogs-rst - name: changelog filenames - language: fail - entry: >- - Changelog files must be named - ####.(bugfix|feature|removal|doc|misc)(.#)?(.rst)? - exclude: >- - ^CHANGES/(\.TEMPLATE\.rst|\.gitignore|\d+\.(bugfix|feature|removal|doc|misc)(\.\d+)?(\.rst)?|README\.rst)$ - files: ^CHANGES/ - - id: changelogs-user-role - name: Changelog files should use a non-broken :user:`name` role - language: pygrep - entry: :user:([^`]+`?|`[^`]+[\s,]) - pass_filenames: true - types: [file, rst] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 'v4.0.1' + rev: 'v4.4.0' hooks: - id: check-merge-conflict - repo: https://github.com/asottile/yesqa - rev: v1.3.0 + rev: v1.5.0 hooks: - id: yesqa additional_dependencies: - - flake8-bandit==3.0.0 - - flake8-bugbear==22.1.11 - - flake8-import-order==0.18.1 - - flake8-requirements==1.5.1 + - flake8-bandit==4.1.1 + - flake8-bugbear==23.7.10 + - flake8-import-order==0.18.2 + - flake8-requirements==1.7.8 - repo: https://github.com/psf/black - rev: '22.1.0' + rev: '23.7.0' hooks: - id: black - language_version: python3 + language_version: python3 # Should be a command that runs python - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 'v4.0.1' + rev: 'v4.4.0' hooks: - id: end-of-file-fixer exclude: >- ^docs/[^/]*\.svg$ - id: requirements-txt-fixer - exclude: >- - ^requirements/constraints[.]txt$ - id: trailing-whitespace - id: file-contents-sorter files: | @@ -55,37 +36,34 @@ repos: - id: check-xml - id: check-executables-have-shebangs - id: check-toml + - id: check-xml - id: check-yaml - id: debug-statements - id: check-added-large-files - id: check-symlinks - - id: fix-byte-order-marker - - id: fix-encoding-pragma - args: ['--remove'] + - id: debug-statements - id: detect-aws-credentials args: ['--allow-missing-credentials'] - id: detect-private-key exclude: ^examples/ -- repo: https://github.com/asottile/pyupgrade - rev: 'v2.29.0' - hooks: - - id: pyupgrade - args: ['--py36-plus'] - repo: https://github.com/PyCQA/flake8 - rev: '4.0.1' + rev: '6.1.0' hooks: - id: flake8 - additional_dependencies: - - flake8-bandit==3.0.0 - - flake8-bugbear==22.1.11 - - flake8-import-order==0.18.1 - - flake8-requirements==1.5.1 exclude: "^docs/" -- repo: git://github.com/Lucas-C/pre-commit-hooks-markup + additional_dependencies: + - flake8-bandit==4.1.1 + - flake8-bugbear==23.7.10 + - flake8-import-order==0.18.2 + - flake8-requirements==1.7.8 +- repo: https://github.com/asottile/pyupgrade + rev: 'v3.10.1' + hooks: + - id: pyupgrade + args: ['--py36-plus'] +- repo: https://github.com/Lucas-C/pre-commit-hooks-markup rev: v1.0.1 hooks: - id: rst-linter files: >- ^[^/]+[.]rst$ - exclude: >- - ^CHANGES\.rst$ diff --git a/aiohttp_debugtoolbar/main.py b/aiohttp_debugtoolbar/main.py index 68c004e2..2c9ed999 100644 --- a/aiohttp_debugtoolbar/main.py +++ b/aiohttp_debugtoolbar/main.py @@ -6,7 +6,7 @@ if sys.version_info >= (3, 8): from typing import Literal, TypedDict else: - from typing_extensions import Literal, TypedDict # noqa: I900 + from typing_extensions import Literal, TypedDict import aiohttp_jinja2 import jinja2 diff --git a/aiohttp_debugtoolbar/middlewares.py b/aiohttp_debugtoolbar/middlewares.py index ae3db432..11544c7e 100644 --- a/aiohttp_debugtoolbar/middlewares.py +++ b/aiohttp_debugtoolbar/middlewares.py @@ -148,7 +148,6 @@ async def middleware(request: web.Request, handler: Handler) -> web.StreamRespon # Intercept http redirect codes and display an html page with a # link to the target. if response.status in REDIRECT_CODES and getattr(response, "location", None): - context = { "redirect_to": response.location, "redirect_code": response.status, diff --git a/aiohttp_debugtoolbar/panels/base.py b/aiohttp_debugtoolbar/panels/base.py index 48d40759..1180fbca 100644 --- a/aiohttp_debugtoolbar/panels/base.py +++ b/aiohttp_debugtoolbar/panels/base.py @@ -102,11 +102,11 @@ def dom_id(self): Javascript to implement custom styles and actions.""" return "pDebug%sPanel" % (self.name.replace(" ", "")) - async def process_response(self, response): + async def process_response(self, response): # noqa: B027 """Receives the response generated by the request. - Override this method to track properties of the response.""" - pass + Override this method to track properties of the response. + """ def wrap_handler(self, handler, context_switcher): """May be overridden to monitor the entire lifecycle of the request. diff --git a/aiohttp_debugtoolbar/panels/logger.py b/aiohttp_debugtoolbar/panels/logger.py index 8b6e8f8e..2a9f3c44 100644 --- a/aiohttp_debugtoolbar/panels/logger.py +++ b/aiohttp_debugtoolbar/panels/logger.py @@ -20,7 +20,6 @@ def emit(self, record): class LoggingPanel(DebugPanel): - name = "logging" template = "logger.jinja2" title = "Log Messages" diff --git a/aiohttp_debugtoolbar/utils.py b/aiohttp_debugtoolbar/utils.py index c4269e1d..849f4b8c 100644 --- a/aiohttp_debugtoolbar/utils.py +++ b/aiohttp_debugtoolbar/utils.py @@ -70,7 +70,6 @@ def replace_insensitive(string, target, replacement): def render(template_name, app, context, *, app_key=TEMPLATE_KEY, **kw): - lookup = app[app_key] template = lookup.get_template(template_name) c = context.copy() diff --git a/examples/extra_panels/server.py b/examples/extra_panels/server.py index 61e67751..12a20758 100644 --- a/examples/extra_panels/server.py +++ b/examples/extra_panels/server.py @@ -39,7 +39,7 @@ async def basic_handler(request): # testing for Redis if "redis" in request.app: - with (await request.app["redis"]) as redis: + with await request.app["redis"] as redis: await redis.set("TEST", "VAR", expire=5) assert b"VAR" == (await redis.get("TEST")) # noqa: S101 diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..b5346019 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,17 @@ +[pytest] +addopts = + # show 10 slowest invocations: + --durations=10 + # a bit of verbosity doesn't hurt: + -v + # report all the things == -rxXs: + -ra + # show values of the local vars in errors: + --showlocals + # coverage reports + --cov=aiohttp_debugtoolbar/ --cov=tests/ --cov-report term +asyncio_mode = auto +filterwarnings = + error +testpaths = tests/ +xfail_strict = true diff --git a/requirements-dev.txt b/requirements-dev.txt index 15648062..0d188361 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -14,4 +14,5 @@ pytest-aiohttp==1.0.4 pytest-cov==3.0.0 pytest-sugar==0.9.4 pytest-timeout==2.1.0 +typing_extensions>=3.8; python_version<"3.8" yarl==1.7.2 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 01e3a30b..00000000 --- a/setup.cfg +++ /dev/null @@ -1,9 +0,0 @@ -[tool:pytest] -asyncio_mode = auto -testpaths = tests/ -timeout = 4 -minversion = 4.6 -filterwarnings = - error -junit_family=xunit2 -xfail_strict = true diff --git a/tests/test_middleware.py b/tests/test_middleware.py index 066004ac..e5de4efe 100644 --- a/tests/test_middleware.py +++ b/tests/test_middleware.py @@ -145,7 +145,6 @@ async def handler(request): async def test_setup_not_called_exception(): - request = make_mocked_request("GET", "/path") with pytest.raises(RuntimeError): await aiohttp_debugtoolbar.middleware(request, lambda r: r)