Skip to content

Commit

Permalink
Add support for Python 3.13 (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Feb 4, 2024
2 parents eade5a7 + a633bc7 commit 5aaa464
Show file tree
Hide file tree
Showing 20 changed files with 99 additions and 49 deletions.
5 changes: 1 addition & 4 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma:
pragma: no cover

exclude_also =
# Don't complain if non-runnable code isn't run:
if __name__ == .__main__.:
def main
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

11 changes: 7 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ jobs:
# Upload to Test PyPI on every commit on main.
release-test-pypi:
name: Publish in-dev package to test.pypi.org
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
if: |
github.repository_owner == 'hugovk'
&& github.event_name == 'push'
&& github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build-package

permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

steps:
Expand All @@ -53,12 +55,13 @@ jobs:
# Upload to real PyPI on GitHub Releases.
release-pypi:
name: Publish released package to pypi.org
if: github.event.action == 'published'
if: |
github.repository_owner == 'hugovk'
&& github.event.action == 'published'
runs-on: ubuntu-latest
needs: build-package

permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

steps:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/labels.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Sync labels

permissions:
pull-requests: write

on:
push:
branches:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Lint

on: [push, pull_request, workflow_dispatch]

env:
FORCE_COLOR: 1

permissions:
contents: read

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/require-pr-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:

permissions:
issues: write
pull-requests: write

steps:
- uses: mheap/github-action-required-labels@v5
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["pypy3.10", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["pypy3.10", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
os: [macos-latest, ubuntu-latest]

steps:
Expand All @@ -24,7 +24,6 @@ jobs:
allow-prereleases: true
cache: pip


- name: Install dependencies
run: |
python -m pip install -U pip
Expand Down
39 changes: 14 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black
exclude: ^html/

- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies: [flake8-2020, flake8-implicit-str-concat]
exclude: ^html/

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-no-log-warn

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand All @@ -37,16 +19,18 @@ repos:
- id: check-json
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.5.3
rev: 1.7.0
hooks:
- id: pyproject-fmt
additional_dependencies: [tox]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.15
rev: v0.16
hooks:
- id: validate-pyproject

Expand All @@ -55,5 +39,10 @@ repos:
hooks:
- id: tox-ini-fmt

- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes

ci:
autoupdate_schedule: quarterly
2 changes: 2 additions & 0 deletions examples/custom_animations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
on the map.
"""

from __future__ import annotations

import pygame

from osmviz.animation import Simulation, SimViz, TrackingViz
Expand Down
2 changes: 2 additions & 0 deletions examples/multiple_trackvizs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
on a map using TrackingViz objects.
"""

from __future__ import annotations

from osmviz.animation import Simulation, TrackingViz

# The goal is to show 10 trains racing eastward across the US.
Expand Down
2 changes: 2 additions & 0 deletions examples/pil_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
of OSM tiles patched together.
"""

from __future__ import annotations

from PIL import Image

from osmviz.manager import OSMManager, PILImageManager
Expand Down
27 changes: 27 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Documentation",
Expand All @@ -51,5 +52,31 @@ version.source = "vcs"
[tool.hatch.version.raw-options]
local_scheme = "no-local-version"

[tool.ruff.lint]
select = [
"C4", # flake8-comprehensions
"E", # pycodestyle errors
"EM", # flake8-errmsg
"F", # pyflakes errors
"I", # isort
"ISC", # flake8-implicit-str-concat
"LOG", # flake8-logging
"PGH", # pygrep-hooks
"RUF100", # unused noqa (yesqa)
"UP", # pyupgrade
"W", # pycodestyle warnings
"YTT", # flake8-2020
]
extend-ignore = [
"E203", # Whitespace before ':'
"E221", # Multiple spaces before operator
"E226", # Missing whitespace around arithmetic operator
"E241", # Multiple spaces after ','
]

[tool.ruff.lint.isort]
known-first-party = ["osmviz"]
required-imports = ["from __future__ import annotations"]

[tool.pytest.ini_options]
addopts = "-W error::DeprecationWarning"
3 changes: 2 additions & 1 deletion src/osmviz/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Keyboard input is accepted to control the speed of the simulation.
"""

# Copyright (c) 2010 Colin Bick, Robert Damphousse

# Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -48,7 +49,7 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from __future__ import annotations

import time
from functools import reduce
Expand Down
28 changes: 19 additions & 9 deletions src/osmviz/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from __future__ import annotations

import hashlib
import math
Expand Down Expand Up @@ -88,7 +89,8 @@ def prepare_image(self, width, height):
are those specified by width and height.
"""
if self.image:
raise Exception("Image already prepared.")
msg = "Image already prepared."
raise Exception(msg)
self.image = self.create_image(width, height)

def destroy_image(self):
Expand All @@ -107,12 +109,14 @@ def paste_image_file(self, image_file, xy):
of that image, pastes the image into this object's internal image.
"""
if not self.image:
raise Exception("Image not prepared")
msg = "Image not prepared"
raise Exception(msg)

try:
img = self.load_image_file(image_file)
except Exception as e:
raise Exception(f"Could not load image {image_file}\n{e}")
msg = f"Could not load image {image_file}\n{e}"
raise Exception(msg)

self.paste_image(img, xy)
del img
Expand All @@ -135,7 +139,8 @@ def __init__(self):
try:
import pygame
except ImportError:
raise Exception("Pygame could not be imported!")
msg = "Pygame could not be imported!"
raise Exception(msg)
self.pygame = pygame

def create_image(self, width, height):
Expand Down Expand Up @@ -164,7 +169,8 @@ def __init__(self, mode):
try:
import PIL.Image
except ImportError:
raise Exception("PIL could not be imported!")
msg = "PIL could not be imported!"
raise Exception(msg)
self.PILImage = PIL.Image

def create_image(self, width, height):
Expand Down Expand Up @@ -243,7 +249,8 @@ def __init__(self, **kwargs):
print(f"WARNING: Using {self.cache} to cache map tiles.")
if not os.access(self.cache, os.R_OK | os.W_OK):
print(f" ERROR: Insufficient access to {self.cache}.")
raise Exception("Unable to find/create/use map tile cache directory.")
msg = "Unable to find/create/use map tile cache directory."
raise Exception(msg)

# Get URL template, which supports the following fields:
# * {z}: tile zoom level
Expand Down Expand Up @@ -279,7 +286,8 @@ def __init__(self, **kwargs):
if mgr: # Assume it's a valid manager
self.manager = mgr
else:
raise Exception("OSMManager.__init__ requires argument image_manager")
msg = "OSMManager.__init__ requires argument image_manager"
raise Exception(msg)

def get_tile_coord(self, lon_deg, lat_deg, zoom):
"""
Expand Down Expand Up @@ -327,7 +335,8 @@ def retrieve_tile_image(self, tile_coord, zoom):
try:
urlretrieve(url, filename=filename)
except Exception as e:
raise Exception(f"Unable to retrieve URL: {url}\n{e}")
msg = f"Unable to retrieve URL: {url}\n{e}"
raise Exception(msg)
return filename

def tile_nw_lat_lon(self, tile_coord, zoom):
Expand All @@ -354,7 +363,8 @@ def create_osm_image(self, bounds, zoom):
"""
(min_lat, max_lat, min_lon, max_lon) = bounds
if not self.manager:
raise Exception("No ImageManager was specified, cannot create image.")
msg = "No ImageManager was specified, cannot create image."
raise Exception(msg)

topleft = min_x, min_y = self.get_tile_coord(min_lon, max_lat, zoom)
max_x, max_y = self.get_tile_coord(max_lon, min_lat, zoom)
Expand Down
2 changes: 2 additions & 0 deletions test/functional/test_animation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from osmviz.animation import Simulation, TrackingViz

Inf = float("inf")
Expand Down
2 changes: 2 additions & 0 deletions test/functional/test_manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import PIL.Image as Image

from osmviz.manager import OSMManager, PILImageManager
Expand Down
3 changes: 3 additions & 0 deletions test/unit/test_image_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""
Unit tests for ImageManager
"""

from __future__ import annotations

import pytest

from osmviz.manager import ImageManager
Expand Down
3 changes: 3 additions & 0 deletions test/unit/test_osm_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""
Unit tests PILImageManager
"""

from __future__ import annotations

import pytest

from osmviz.manager import OSMManager, PILImageManager
Expand Down
3 changes: 3 additions & 0 deletions test/unit/test_pil_image_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""
Unit tests for PILImageManager
"""

from __future__ import annotations

import pytest

from osmviz.manager import PILImageManager
Expand Down
Loading

0 comments on commit 5aaa464

Please sign in to comment.