Skip to content

Commit

Permalink
Merge pull request #18 from conformist-mw/integrate_gh_actions
Browse files Browse the repository at this point in the history
Integrate gh actions
  • Loading branch information
conformist-mw authored Nov 14, 2023
2 parents 5e38383 + 3e87f01 commit ebcc9a1
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 8 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: check

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Test with tox
run: tox
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.4.0

- integrate github actions
- fix py38 support

## 0.3.1

- fix an unclosed curly bracket
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Django Queries Count

[![check](https://github.com/conformist-mw/django-query-counter/actions/workflows/check.yml/badge.svg)](https://github.com/conformist-mw/django-query-counter/actions/workflows/check.yml)
[![PyPI version](https://badge.fury.io/py/django-query-counter.svg)](https://badge.fury.io/py/django-query-counter)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-query-counter)
![PyPI - Versions from Framework Classifiers](https://img.shields.io/pypi/frameworkversions/django/django-query-counter)


The difference between this project and all the others like it is that I needed
to debug management command in Django, but all the others only provided middleware,
which did not solve my problem.
Expand Down
17 changes: 16 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ legacy_tox_ini = """
py311-django{42, 41}
py310-django{42, 41, 40, 32}
py39-django{42, 41, 40, 32}
py38-django{42, 41, 40, 32}
[testenv]
deps =
Expand All @@ -21,11 +22,25 @@ legacy_tox_ini = """
PYTHONDEVMODE = 1
commands = pytest -Wa -r {posargs:.}
[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311
[gh-actions:env]
DJANGO =
3.2: dj32
4.0: dj40
4.1: dj41
4.2: dj42
[testenv:lint]
description = run linters
skip_install = true
deps =
ruff==0.0.275
ruff==0.1.5
commands = ruff {posargs:query_counter}
"""

Expand Down
2 changes: 1 addition & 1 deletion query_counter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.3.1'
__version__ = '0.4.0'

try:
import django
Expand Down
9 changes: 5 additions & 4 deletions query_counter/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
from collections import Counter
from operator import itemgetter
from typing import Dict, List

from django.conf import settings
from django.db import connection
Expand Down Expand Up @@ -89,15 +90,15 @@ def do_count(self) -> Counter:
for q in self.queries if q['sql'].startswith(self.SQL_STATEMENTS)
])

def count_duplicated(self) -> dict[str, int]:
def count_duplicated(self) -> Dict[str, int]:
return {
query: count
for query, count
in Counter([q['sql'] for q in self.queries]).most_common()
if count > 1
}

def get_slowest(self) -> dict[str, float]:
def get_slowest(self) -> Dict[str, float]:
return {
q['sql']: q['duration']
for q in sorted(
Expand Down Expand Up @@ -147,7 +148,7 @@ def get_table(self, stats):
tablefmt=_get_value('DQC_TABULATE_FMT'),
)

def generate_all_queries_lines(self) -> list[str]:
def generate_all_queries_lines(self) -> List[str]:
lines = []
for query, count in Counter(
[q['sql'] for q in self.queries],
Expand All @@ -157,7 +158,7 @@ def generate_all_queries_lines(self) -> list[str]:
)
return lines

def generate_detailed_lines(self) -> list[str]:
def generate_detailed_lines(self) -> List[str]:
lines = []
if self.duplicates:
lines.append(colorize('Duplicate queries:'))
Expand Down
15 changes: 13 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,19 @@ def read_long_description():
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Framework :: Django',
'Topic :: Utilities',
'Framework :: Django',
'Framework :: Django :: 3.2',
'Framework :: Django :: 4.0',
'Framework :: Django :: 4.1',
'Framework :: Django :: 4.2',
'Framework :: Django :: 5.0',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],
)

0 comments on commit ebcc9a1

Please sign in to comment.