Skip to content

Commit 1d58ded

Browse files
committed
Modernize tox config and write MMDB files with a Python script
1 parent ccef26b commit 1d58ded

File tree

6 files changed

+77
-112
lines changed

6 files changed

+77
-112
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ check:
1414
python -Wd example/manage.py check
1515

1616
generate-mmdb-fixtures:
17-
docker --context=default buildx build -f tests/Dockerfile --tag test-mmdb-maker tests
18-
docker run --rm --volume $$(pwd)/tests:/data test-mmdb-maker
17+
[ -e tests/test_city.mmdb ] || python3 generate_mmdb.py
1918

2019
test: generate-mmdb-fixtures
2120
DJANGO_SETTINGS_MODULE=tests.settings PYTHONPATH=. \

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ dev = [
5858
# Build
5959
"bumpversion",
6060
"twine",
61+
"mmdb-writer",
6162
]
6263

6364
[tool.ruff]

tests/Dockerfile

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/generate_mmdb.pl

Lines changed: 0 additions & 89 deletions
This file was deleted.

tests/generate_mmdb.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from netaddr import IPSet
2+
3+
from mmdb_writer import MMDBWriter
4+
5+
6+
city_writer = MMDBWriter()
7+
8+
city_writer.insert_network(
9+
IPSet(["44.55.66.77/32"]),
10+
{
11+
"city": {
12+
"names": {
13+
"en": "San Diego",
14+
},
15+
},
16+
"continent": {
17+
"code": "NA",
18+
"names": {
19+
"en": "North America",
20+
},
21+
},
22+
"country": {
23+
"iso_code": "US",
24+
"names": {
25+
"en": "United States",
26+
},
27+
},
28+
"is_in_european_union": False,
29+
"location": {
30+
"latitude": 37.751,
31+
"longitude": -97.822,
32+
"metro_code": "custom metro code",
33+
"time_zone": "America/Los Angeles",
34+
},
35+
"postal": {
36+
"code": "custom postal code",
37+
},
38+
"subdivisions": [
39+
{
40+
"iso_code": "ABC",
41+
"names": {
42+
"en": 'Absolute Basic Class',
43+
},
44+
},
45+
],
46+
},
47+
)
48+
49+
city_writer.to_db_file("tests/test_city.mmdb")
50+
51+
# country_writer = MMDBWriter(
52+
# IPSet(["8.8.8.8/32"]),
53+
# {
54+
# "country": {
55+
# "iso_code": "US",
56+
# "names": {
57+
# "en": "United States",
58+
# },
59+
# },
60+
# },
61+
# )
62+
63+
# country_writer.to_db_file("tests/test_country.mmdb")

tox.ini

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@
22
; Minimum version of Tox
33
minversion = 1.8
44
envlist =
5-
; https://docs.djangoproject.com/en/4.2/faq/install/#what-python-version-can-i-use-with-django
6-
py{37}-dj32
7-
py{38,39,310}-dj32
8-
py{311,312}-dj{42,main}
5+
; https://docs.djangoproject.com/en/6.0/faq/install/#what-python-version-can-i-use-with-django
6+
py3{10,11,12,13,14}-dj52
7+
py3{12,13,14}-dj{60,main}
98

109
[gh-actions]
1110
python =
12-
3.8: py38
13-
3.9: py39
1411
3.10: py310
1512
3.11: py311
1613
3.12: py312
14+
3.13: py313
15+
3.14: py314
1716

1817
[gh-actions:env]
1918
DJANGO =
20-
3.2: dj32
21-
4.2: dj42
19+
5.2: dj52
20+
6.0: dj60
2221
main: djmain
2322

2423
[testenv]
2524
commands =
26-
make generate-mmdb-fixtures
25+
python3 tests/generate_mmdb.py
2726
coverage run {envbindir}/django-admin test -v 2 --pythonpath=./ --settings=tests.settings
2827
coverage report
2928
coverage xml
3029
deps =
3130
coverage
32-
dj32: Django>=3.2,<4.0
33-
dj42: Django>=4.2,<4.3
31+
dj52: Django>=5.2,<6.0
32+
dj60: Django>=6.0,<6.1
3433
djmain: https://github.com/django/django/archive/main.tar.gz
3534
geoip2
35+
mmdb-writer
36+
netaddr
3637
ignore_outcome =
3738
djmain: True
38-
allowlist_externals = make

0 commit comments

Comments
 (0)