Skip to content

Commit ddb2108

Browse files
authored
Merge pull request #37 from vintasoftware/export-type-hints
Updates supported versions of Python and Django
2 parents 2eda0c0 + b056505 commit ddb2108

File tree

9 files changed

+76
-30
lines changed

9 files changed

+76
-30
lines changed

.github/workflows/pre-commit.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
pre-commit:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
13-
- uses: actions/setup-python@v4
14-
- uses: pre-commit/[email protected].0
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-python@v5
14+
- uses: pre-commit/[email protected].1

.github/workflows/tests.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ jobs:
1212
strategy:
1313
matrix:
1414
os: [ubuntu-latest]
15-
python-version: ['3.8', '3.9', '3.10', '3.11']
16-
django-version: ['3.2', '4.0', '4.1', '4.2']
15+
python-version: ['3.10', '3.11', '3.12', '3.13']
16+
django-version: ['4.2', '5.0', '5.1', '5.2']
1717

1818
steps:
1919
- name: Checkout code
20-
uses: actions/checkout@v3
20+
uses: actions/checkout@v4
2121
- name: Set up Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v4
22+
uses: actions/setup-python@v5
2323
with:
2424
python-version: ${{ matrix.python-version }}
2525
- name: Cache installed requirements
26-
uses: actions/cache@v3
26+
uses: actions/cache@v4
2727
with:
2828
path: ${{ env.pythonLocation }}
2929
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-test-v01
@@ -37,19 +37,19 @@ jobs:
3737
DJANGO: ${{ matrix.django-version }}
3838
run: tox
3939
- name: Run tests for example
40-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.8' && matrix.django-version == '3.2' }}
40+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' && matrix.django-version == '4.2' }}
4141
run: |
4242
python -m pip install .[test,example]
4343
python -m pytest example
4444
- name: Generate coverage.xml
45-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.8' && matrix.django-version == '3.2' }}
46-
uses: actions/upload-artifact@v3
45+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' && matrix.django-version == '4.2' }}
46+
uses: actions/upload-artifact@v4
4747
with:
4848
name: tox-gh-actions-coverage
4949
path: coverage.xml
5050
if-no-files-found: error
5151
- name: Upload coverage.xml to Coveralls
52-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.8' && matrix.django-version == '3.2' }}
52+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' && matrix.django-version == '4.2' }}
5353
run: coveralls --service=github
5454
env:
5555
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.3.0]
8+
9+
- Include `py.typed` file for type hints
10+
- Add support to Python 3.12 and 3.13
11+
- Drop support to Python 3.8 and 3.9
12+
- Add support to Django 5.0, 5.1, and 5.2
13+
- Drop support to Django 3.2, 4.0, and 4.1
14+
715
## [0.2.0]
816

917
- Add support to nested prefetch lookups like `v.VirtualModel(manager=User.objects, lookup="course__facilitators")`

django_virtual_models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Top-level package for django_virtual_models."""
22
import logging
33

4-
__version__ = "0.2.0"
4+
__version__ = "0.3.0"
55

66
# Good practice: https://docs.python-guide.org/writing/logging/#logging-in-a-library
77
logging.getLogger(__name__).addHandler(logging.NullHandler())

django_virtual_models/py.typed

Whitespace-only changes.

django_virtual_models/query_capture/capture.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,27 @@
77
import time
88
import typing
99
from contextlib import ContextDecorator, ExitStack
10-
from distutils.sysconfig import get_python_lib
1110

1211
from django.conf import settings
1312
from django.db import connection
1413

14+
try:
15+
from distutils.sysconfig import get_python_lib
16+
except ImportError:
17+
from sysconfig import get_paths
18+
19+
def get_python_lib(plat_specific=False):
20+
"""
21+
Get the path to the Python library directory.
22+
If plat_specific is True, return platform-specific directory,
23+
otherwise return platform-independent directory.
24+
To match distutils behavior, return both paths when called without arguments.
25+
"""
26+
paths = get_paths()
27+
if plat_specific:
28+
return paths["platlib"]
29+
return [paths["purelib"], paths["platlib"]]
30+
1531

1632
class CapturedQuery(typing.TypedDict):
1733
"""
@@ -79,11 +95,15 @@ def _save_queries(self, execute, sql, params, many, context):
7995
"""
8096
if settings.DEBUG:
8197
# only calculate stack in DEBUG or TEST mode, to avoid production impact
82-
python_library_directory = get_python_lib()
98+
python_lib_paths = get_python_lib()
99+
# Handle both single string and list return values
100+
if isinstance(python_lib_paths, str):
101+
python_lib_paths = [python_lib_paths]
102+
83103
stack = [
84104
stack
85105
for stack in inspect.stack()
86-
if not stack.filename.startswith(python_library_directory)
106+
if not any(stack.filename.startswith(path) for path in python_lib_paths)
87107
and not stack.filename.startswith("/usr/local/lib/")
88108
and not stack.filename.endswith("query_capture/capture.py")
89109
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 5.2 on 2025-05-14 01:36
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("movies", "0001_initial"),
9+
]
10+
11+
operations = [
12+
migrations.RenameIndex(
13+
model_name="persondirector",
14+
new_name="movies_pers_movie_i_957f84_idx",
15+
old_fields=("movie", "order"),
16+
),
17+
]

example/movies/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class PersonDirector(models.Model):
2020
order = models.PositiveSmallIntegerField()
2121

2222
class Meta:
23-
index_together = [("movie", "order")]
23+
indexes = [models.Index(fields=["movie", "order"])]
2424
ordering = ["movie", "order"]
2525

2626

pyproject.toml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ build-backend = "flit_core.buildapi"
44

55
[tool.flit.module]
66
name = "django_virtual_models"
7+
py-typed = true
78

89
[project]
910
name = "django-virtual-models"
@@ -21,13 +22,13 @@ classifiers = [
2122
"License :: OSI Approved :: MIT License",
2223
"Natural Language :: English",
2324
"Programming Language :: Python :: 3",
24-
"Programming Language :: Python :: 3.8",
25-
"Programming Language :: Python :: 3.9",
2625
"Programming Language :: Python :: 3.10",
2726
"Programming Language :: Python :: 3.11",
27+
"Programming Language :: Python :: 3.12",
28+
"Programming Language :: Python :: 3.13",
2829
]
2930
dependencies = [
30-
"django >=3.2",
31+
"django >=4.2",
3132
"djangorestframework >=3.13.1",
3233
"typing-extensions >=4.3.0",
3334
]
@@ -57,7 +58,7 @@ test = [
5758
"model_bakery >=1.11.0,<2.0.0",
5859
]
5960
example = [
60-
"django >= 3.2,<4.0",
61+
"django >= 4.2,<6.0",
6162
"pyyaml >= 6.0,<7.0",
6263
]
6364

@@ -112,31 +113,31 @@ testpaths = [
112113
[tool.tox]
113114
legacy_tox_ini = """
114115
[tox]
115-
envlist = {linux}-py{38,39,310,311}-django{32,40,41,42}
116+
envlist = {linux}-py{310,311,312,313}-django{42,50,51,52}
116117
isolated_build = True
117118
118119
[gh-actions]
119120
python =
120-
3.8: py38
121-
3.9: py39
122121
3.10: py310
123122
3.11: py311
123+
3.12: py312
124+
3.13: py313
124125
125126
[gh-actions:env]
126127
OS =
127128
ubuntu-latest: linux
128129
DJANGO =
129-
3.2: django32
130-
4.0: django40
131-
4.1: django41
132130
4.2: django42
131+
5.0: django50
132+
5.1: django51
133+
5.2: django52
133134
134135
[testenv]
135136
deps =
136-
django32: django~=3.2
137-
django40: django~=4.0
138-
django41: django~=4.1
139137
django42: django~=4.2
138+
django50: django~=5.0
139+
django51: django~=5.1
140+
django52: django~=5.2
140141
.[test]
141142
commands =
142143
coverage run -m pytest --basetemp={envtmpdir}

0 commit comments

Comments
 (0)