Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Python and Django #45

Merged
merged 27 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a294600
chore: Run pyupgrade --py38-plus **/*.py
jpmckinney Dec 10, 2023
3219d8e
chore: Run django-upgrade --target-version 4.2
jpmckinney Dec 10, 2023
62f127d
chore: Remove python_2_unicode_compatible
jpmckinney Dec 10, 2023
544b412
chore: Convert setup.py to setup.cfg
jpmckinney Dec 10, 2023
7497546
chore: Move .coveragerc and tox.ini into setup.cfg
jpmckinney Dec 10, 2023
1e11615
chore: flake8 (E127, E303, E741, W391)
jpmckinney Dec 10, 2023
606f159
chore: isort
jpmckinney Dec 10, 2023
6ae8b3a
chore: Fix E124
jpmckinney Dec 10, 2023
62e27d2
chore: F403 not raised
jpmckinney Dec 10, 2023
8eee192
chore: Use f-strings
jpmckinney Dec 10, 2023
0c443d9
chore: Fix E128
jpmckinney Dec 10, 2023
4f9bb2f
chore: Add /build to .gitignore
jpmckinney Dec 10, 2023
0b3a979
chore: Fix E501
jpmckinney Dec 10, 2023
0c0a98f
build: Add tests and changelog to package
jpmckinney Dec 10, 2023
4205244
ci: Add lint workflow
jpmckinney Dec 10, 2023
4ab03c4
ci: Add test workflow
jpmckinney Dec 10, 2023
790bbb7
settings: Make it easier to run in development on macOS
jpmckinney Dec 10, 2023
fa3e03d
docs: Fix CI badge
jpmckinney Dec 10, 2023
7b18cc1
ci: Set PYTHONPATH and install GDAL
jpmckinney Dec 10, 2023
85bda7a
settings: Add CI defaults
jpmckinney Dec 10, 2023
85758b8
fix: Fix error introduced in 0b3a9799
jpmckinney Dec 10, 2023
fff54c9
test: Fix models.W042 warning
jpmckinney Dec 10, 2023
193e969
test: Update comparisons for different WKT point orders
jpmckinney Dec 10, 2023
16b9b36
settings: Set DEFAULT_AUTO_FIELD to AutoField to avoid migration
jpmckinney Dec 10, 2023
8aced1a
migrations: Add no-op JSONField migration
jpmckinney Dec 10, 2023
def6119
feat: Replace n-dashes and m-dashes in boundary set slugs with hyphens
jpmckinney Jun 26, 2024
2823010
ci: Add pypi and automerge workflows
jpmckinney Jun 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .coveragerc

This file was deleted.

6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
35 changes: 35 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# The pull_request_target workflow trigger is dangerous. Do not add unrelated logic to this workflow.
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
name: Auto-merge
on: pull_request_target
permissions:
pull-requests: write # to approve the PR
contents: write # to merge the PR
jobs:
dependabot:
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- id: dependabot-metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' || steps.dependabot-metadata.outputs.package-ecosystem == 'github_actions' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr review --approve ${{ github.event.pull_request.html_url }}
- if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' || steps.dependabot-metadata.outputs.package-ecosystem == 'github_actions' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr merge --auto --squash ${{ github.event.pull_request.html_url }}
precommit:
if: ${{ github.event.pull_request.user.login == 'pre-commit-ci[bot]' }}
runs-on: ubuntu-latest
steps:
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr review --approve ${{ github.event.pull_request.html_url }}
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr merge --auto --squash ${{ github.event.pull_request.html_url }}
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI
on: [push, pull_request]
jobs:
build:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
django-version: ['Django>=3.2,<4', 'Django>=4.2,<5']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: setup.cfg
# https://docs.djangoproject.com/en/4.2/ref/contrib/gis/install/geolibs/
- run: |
sudo apt update
sudo apt install binutils libproj-dev gdal-bin
- run: pip install .[test] '${{ matrix.django-version }}' psycopg2-binary
- env:
PORT: ${{ job.services.postgres.ports[5432] }}
DJANGO_SETTINGS_MODULE: settings
run: env PYTHONPATH=$PYTHONPATH:$PWD django-admin migrate --noinput
- env:
PORT: ${{ job.services.postgres.ports[5432] }}
run: coverage run --source=boundaries runtests.py
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: coveralls --service=github
services:
postgres:
image: postgis/postgis:15-3.4
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432/tcp
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Lint
on: [push, pull_request]
jobs:
build:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: pip install --upgrade check-manifest flake8 isort
- run: flake8 .
- run: isort .
- run: check-manifest --ignore-bad-ideas '*.mo'
22 changes: 22 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish to PyPI
on: push
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: pip install --upgrade build
- run: python -m build --sdist --wheel
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.pyc
*.egg-info
*_cleaned_*
/build
/dist
/.coverage
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.9.5 (Unreleased)

* Replace n-dashes and m-dashes in boundary set slugs with hyphens.
* Add support for Django 2.2.
* Drop support for Python 2.7 and 3.4.

Expand Down
9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
include CHANGELOG.md
recursive-include boundaries/locale *
recursive-include boundaries/static *
recursive-include boundaries/templates *
recursive-include boundaries/tests *.dbf
recursive-include boundaries/tests *.prj
recursive-include boundaries/tests *.py
recursive-include boundaries/tests *.shp
recursive-include boundaries/tests *.shx
recursive-include boundaries/tests *.txt
recursive-include boundaries/tests *.zip
exclude *.py
14 changes: 6 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Represent Boundaries
====================

|PyPI version| |Build Status| |Dependency Status| |Coverage Status|
|PyPI version| |Build Status| |Coverage Status|

Represent Boundaries is a web API to geographic areas, like electoral
districts. It allows you to easily find the areas that cover your users'
Expand Down Expand Up @@ -52,9 +52,9 @@ Testing

::

createdb travis_ci_test
psql travis_ci_test -c 'CREATE EXTENSION postgis;'
django-admin.py migrate --settings settings --noinput
createdb represent_boundaries_test
psql represent_boundaries_test -c 'CREATE EXTENSION postgis;'
env DJANGO_SETTINGS_MODULE=settings django-admin migrate --noinput
python runtests.py

Acknowledgements
Expand All @@ -67,9 +67,7 @@ Released under the MIT license

.. |PyPI version| image:: https://badge.fury.io/py/represent-boundaries.svg
:target: https://badge.fury.io/py/represent-boundaries
.. |Build Status| image:: https://secure.travis-ci.org/opennorth/represent-boundaries.png
:target: https://travis-ci.org/opennorth/represent-boundaries
.. |Dependency Status| image:: https://gemnasium.com/opennorth/represent-boundaries.png
:target: https://gemnasium.com/opennorth/represent-boundaries
.. |Build Status| image:: https://github.com/opennorth/represent-boundaries/actions/workflows/ci.yml/badge.svg
:target: https://github.com/opennorth/represent-boundaries/actions/workflows/ci.yml
.. |Coverage Status| image:: https://coveralls.io/repos/opennorth/represent-boundaries/badge.png?branch=master
:target: https://coveralls.io/r/opennorth/represent-boundaries
18 changes: 7 additions & 11 deletions boundaries/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# coding: utf-8
from __future__ import unicode_literals

import logging
import os
import re
import sys

from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

log = logging.getLogger(__name__)
registry = {}
Expand Down Expand Up @@ -78,15 +75,14 @@ def import_file(path):
# The module object is returned, but this return value is unused by this
# package.

if sys.version_info > (3, 3):
"""
"""
If we're in Python 3, we'll use the PEP 302 import loader.
"""
import importlib.machinery
loader = importlib.machinery.SourceFileLoader(module, path)
obj = loader.load_module()
sys.modules.pop(module)
return obj
import importlib.machinery
loader = importlib.machinery.SourceFileLoader(module, path)
obj = loader.load_module()
sys.modules.pop(module)
return obj

"""
If we're in Python 2, we'll use the `imp` module.
Expand Down
10 changes: 3 additions & 7 deletions boundaries/admin.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
from django.contrib import admin
from django.contrib.gis.admin import OSMGeoAdmin

from boundaries.models import BoundarySet, Boundary
from boundaries.models import Boundary, BoundarySet


@admin.register(BoundarySet)
class BoundarySetAdmin(admin.ModelAdmin):
list_filter = ('authority', 'domain')


admin.site.register(BoundarySet, BoundarySetAdmin)


@admin.register(Boundary)
class BoundaryAdmin(OSMGeoAdmin):
list_display = ('name', 'external_id', 'set')
list_display_links = ('name', 'external_id')
list_filter = ('set',)


admin.site.register(Boundary, BoundaryAdmin)
Loading