Skip to content

Commit

Permalink
py39
Browse files Browse the repository at this point in the history
  • Loading branch information
JaskRendix committed Jan 16, 2024
1 parent 145a52e commit 91e22e6
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 86 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ jobs:
runs-on: [ubuntu-latest]
strategy:
matrix:
python-version:
- 3.7
- 3.8
- 3.9
python-version: ['3.9', '3.10', '3.11', '3.12']
dependencies:
- pygame pyglet
- pygame
Expand Down
2 changes: 1 addition & 1 deletion apps/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
This is tested on pygame 1.9 and python 2.7 and 3.3+.
Leif Theden "bitcraft", 2012-2022
Leif Theden "bitcraft", 2012-2024
Rendering demo for the TMXLoader.
Expand Down
2 changes: 1 addition & 1 deletion apps/pygame_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
This is tested on pygame 1.9 and python 2.7 and 3.3+.
Leif Theden "bitcraft", 2012-2023
Leif Theden "bitcraft", 2012-2024
Rendering demo for the TMXLoader.
Expand Down
2 changes: 1 addition & 1 deletion apps/pygame_sdl2_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
This is tested on pygame 2.0.1 and python 3.9.6.
Leif Theden "bitcraft", 2012-2022
Leif Theden "bitcraft", 2012-2024
Rendering demo for the TMXLoader.
Expand Down
2 changes: 1 addition & 1 deletion apps/pyglet_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
This is tested on pyglet 1.2 and python 2.7.
Leif Theden "bitcraft", 2012-2022
Leif Theden "bitcraft", 2012-2024
Rendering demo for the TMXLoader.
Expand Down
2 changes: 1 addition & 1 deletion apps/pysdl2_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
This is tested on pysdl2 1.2 and python 2.7.
Leif Theden "bitcraft", 2012-2022
Leif Theden "bitcraft", 2012-2024
Rendering demo for the TMXLoader.
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@


# -- Project information -----------------------------------------------------
from typing import Any, List
from typing import Any

project = "pytmx"
copyright = "2012-2021, Leif Theden"
copyright = "2012-2024, Leif Theden"
author = "Leif Theden"

# The full version, including alpha/beta/rc tags
Expand Down Expand Up @@ -72,7 +72,7 @@
# Apidoc call to generate automatic reference docs. Taken from
# https://github.com/readthedocs/readthedocs.org/issues/1139#issuecomment-398083449
def run_apidoc(_: Any) -> None:
ignore_paths: List[str] = []
ignore_paths: list[str] = []

argv = ["-f", "-e", "-M", "-o", "autogen", ".."] + ignore_paths

Expand Down
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ classifiers = [
"Intended Audience :: Developers",
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand All @@ -25,7 +23,7 @@ classifiers = [
"Topic :: Multimedia :: Graphics",
"Topic :: Software Development :: Libraries :: pygame",
]
requires-python = ">=3.7"
requires-python = ">=3.9"

[project.urls]
source = "https://github.com/bitcraft/PyTMX"
Expand All @@ -39,7 +37,7 @@ pygame-ce = ["pygame-ce>=2.1.3"]

[tool.black]
line-length = 88
target-version = ["py37"]
target-version = ["py39"]

[tool.isort]
line_length = 88
Expand Down
5 changes: 1 addition & 4 deletions pytmx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Copyright (C) 2012-2023, Leif Theden <[email protected]>
Copyright (C) 2012-2024, Leif Theden <[email protected]>
This file is part of pytmx.
Expand Down Expand Up @@ -28,6 +28,3 @@
logger.debug("cannot import pygame tools")

__version__ = (3, 32)
__author__ = "bitcraft"
__author_email__ = "[email protected]"
__description__ = "Map loader for TMX Files - Python 3.3 +"
51 changes: 25 additions & 26 deletions pytmx/pytmx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Copyright (C) 2012-2023, Leif Theden <[email protected]>
Copyright (C) 2012-2024, Leif Theden <[email protected]>
This file is part of pytmx.
Expand Down Expand Up @@ -27,11 +27,12 @@
import zlib
from base64 import b64decode
from collections import defaultdict, namedtuple
from collections.abc import Iterable, Sequence
from copy import deepcopy
from itertools import chain, product
from math import cos, radians, sin
from operator import attrgetter
from typing import Dict, Iterable, List, Optional, Sequence, Tuple, Union
from typing import Optional, Union
from xml.etree import ElementTree

# for type hinting
Expand Down Expand Up @@ -79,17 +80,17 @@
Point = namedtuple("Point", ["x", "y"])
TileFlags = namedtuple("TileFlags", flag_names)
empty_flags = TileFlags(False, False, False)
ColorLike = Union[Tuple[int, int, int, int], Tuple[int, int, int], int, str]
MapPoint = Tuple[int, int, int]
ColorLike = Union[tuple[int, int, int, int], tuple[int, int, int], int, str]
MapPoint = tuple[int, int, int]
TiledLayer = Union[
"TiledTileLayer", "TiledImageLayer", "TiledGroupLayer", "TiledObjectGroup"
]

# need a more graceful way to handle annotations for optional dependencies
if pygame:
PointLike = Union[Tuple[int, int], pygame.Vector2, Point]
PointLike = Union[tuple[int, int], pygame.Vector2, Point]
else:
PointLike = Union[Tuple[int, int], Point]
PointLike = Union[tuple[int, int], Point]


def default_image_loader(filename: str, flags, **kwargs):
Expand All @@ -112,7 +113,7 @@ def load(rect=None, flags=None):
return load


def decode_gid(raw_gid: int) -> Tuple[int, TileFlags]:
def decode_gid(raw_gid: int) -> tuple[int, TileFlags]:
"""Decode a GID from TMX data.
Args:
Expand All @@ -136,9 +137,9 @@ def decode_gid(raw_gid: int) -> Tuple[int, TileFlags]:


def reshape_data(
gids: List[int],
gids: list[int],
width: int,
) -> List[List[int]]:
) -> list[list[int]]:
"""Change 1D list to 2d list
Args:
Expand All @@ -156,7 +157,7 @@ def unpack_gids(
text: str,
encoding: Optional[str] = None,
compression: Optional[str] = None,
) -> List[int]:
) -> list[int]:
"""Return all gids from encoded/compressed layer data
Args:
Expand Down Expand Up @@ -184,7 +185,7 @@ def unpack_gids(
raise ValueError(f"layer encoding {encoding} is not supported.")


def convert_to_bool(value: str) -> bool:
def convert_to_bool(value: Optional[Union[str, int, float]] = None) -> bool:
"""Convert a few common variations of "true" and "false" to boolean
Args:
Expand Down Expand Up @@ -230,7 +231,7 @@ def rotate(
points: Sequence[Point],
origin: Point,
angle: Union[int, float],
) -> List[Point]:
) -> list[Point]:
"""Rotate a sequence of points around an axis.
Args:
Expand Down Expand Up @@ -330,7 +331,7 @@ def rotate(
}


def parse_properties(node: ElementTree.Element, customs: dict = None) -> Dict:
def parse_properties(node: ElementTree.Element, customs: dict = None) -> dict:
"""Parse a Tiled xml node and return a dict.
Args:
Expand Down Expand Up @@ -458,7 +459,7 @@ def __repr__(self):
class TiledClassType:
"""Contains custom Tiled types."""

def __init__(self, name: str, members: List[dict]) -> None:
def __init__(self, name: str, members: list[dict]) -> None:
"""Creates the TiledClassType.
Args:
Expand All @@ -477,7 +478,7 @@ class TiledMap(TiledElement):
def __init__(
self,
filename: Optional[str] = None,
custom_property_filename: Optional[List[str]] = None,
custom_property_filename: Optional[list[str]] = None,
image_loader=default_image_loader,
**kwargs,
) -> None:
Expand Down Expand Up @@ -809,7 +810,7 @@ def get_tile_gid(self, x: int, y: int, layer: int) -> int:
logger.debug(msg.format(x, y, layer))
raise ValueError(msg.format(x, y, layer))

def get_tile_properties(self, x: int, y: int, layer: int) -> Optional[Dict]:
def get_tile_properties(self, x: int, y: int, layer: int) -> Optional[dict]:
"""Return the tile image GID for this location.
Args:
Expand Down Expand Up @@ -864,7 +865,7 @@ def get_tile_locations_by_gid(self, gid: int) -> Iterable[MapPoint]:
for x, y, _gid in [i for i in self.layers[l].iter_data() if i[2] == gid]:
yield x, y, l

def get_tile_properties_by_gid(self, gid: int) -> Optional[Dict]:
def get_tile_properties_by_gid(self, gid: int) -> Optional[dict]:
"""Get the tile properties of a tile GID.
Args:
Expand Down Expand Up @@ -1009,7 +1010,7 @@ def get_tileset_from_gid(self, gid: int) -> TiledTileset:

raise ValueError("Tileset not found")

def get_tile_colliders(self) -> Iterable[Tuple[int, List[Dict]]]:
def get_tile_colliders(self) -> Iterable[tuple[int, list[dict]]]:
"""Return iterator of (gid, dict) pairs of tiles with colliders.
Returns:
Expand All @@ -1021,7 +1022,7 @@ def get_tile_colliders(self) -> Iterable[Tuple[int, List[Dict]]]:
if colliders:
yield gid, colliders

def pixels_to_tile_pos(self, position: Tuple[int, int]) -> Tuple[int, int]:
def pixels_to_tile_pos(self, position: tuple[int, int]) -> tuple[int, int]:
return int(position[0] / self.tilewidth), int(position[1] / self.tileheight)

@property
Expand Down Expand Up @@ -1138,7 +1139,7 @@ def register_gid_check_flags(
else:
return self.register_gid(*decode_gid(tiled_gid))

def map_gid(self, tiled_gid: int) -> Optional[List[int]]:
def map_gid(self, tiled_gid: int) -> Optional[list[int]]:
"""Used to lookup a GID read from a TMX file's data.
Args:
Expand All @@ -1157,7 +1158,7 @@ def map_gid(self, tiled_gid: int) -> Optional[List[int]]:
logger.debug(msg)
raise TypeError(msg)

def map_gid2(self, tiled_gid: int) -> List[Tuple[int, Optional[int]]]:
def map_gid2(self, tiled_gid: int) -> list[tuple[int, Optional[int]]]:
"""WIP. need to refactor the gid code"""
tiled_gid = int(tiled_gid)

Expand Down Expand Up @@ -1375,7 +1376,7 @@ def __init__(self, parent, node) -> None:
def __iter__(self):
return self.iter_data()

def iter_data(self) -> Iterable[Tuple[int, int, int]]:
def iter_data(self) -> Iterable[tuple[int, int, int]]:
"""Yields X, Y, GID tuples for each tile in the layer.
Returns:
Expand Down Expand Up @@ -1574,17 +1575,15 @@ def read_points(text):

return self

def apply_transformations(self) -> List[Point]:
def apply_transformations(self) -> list[Point]:
"""Return all points for object, taking in account rotation."""
if hasattr(self, "points"):
return rotate(self.points, self, self.rotation)
else:
return rotate(self.as_points, self, self.rotation)

@property
def as_points(
self,
) -> List[Point]:
def as_points(self) -> list[Point]:
return [
Point(*i)
for i in [
Expand Down
10 changes: 5 additions & 5 deletions pytmx/util_pygame.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
Copyright (C) 2012-2023, Leif Theden <[email protected]>
Copyright (C) 2012-2024, Leif Theden <[email protected]>
This file is part of pytmx.
Expand All @@ -19,7 +19,7 @@
"""
import itertools
import logging
from typing import List, Optional, Union
from typing import Optional, Union

import pytmx
from pytmx.pytmx import ColorLike, PointLike
Expand Down Expand Up @@ -188,7 +188,7 @@ def build_rects(
layer: Union[int, str],
tileset: Optional[Union[int, str]],
real_gid: Optional[int],
) -> List[pygame.Rect]:
) -> list[pygame.Rect]:
"""
Generate a set of non-overlapping rects that represents the distribution of the specified gid.
Expand Down Expand Up @@ -258,10 +258,10 @@ def build_rects(


def simplify(
all_points: List[PointLike],
all_points: list[PointLike],
tilewidth: int,
tileheight: int,
) -> List[pygame.Rect]:
) -> list[pygame.Rect]:
"""Given a list of points, return list of rects that represent them
kludge:
Expand Down
12 changes: 7 additions & 5 deletions pytmx/util_pygame_sdl2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Copyright (C) 2012-2022, Leif Theden <[email protected]>
Copyright (C) 2012-2024, Leif Theden <[email protected]>
This file is part of pytmx.
Expand All @@ -19,7 +19,7 @@
import dataclasses
import logging
from functools import partial
from typing import Tuple
from typing import Any, Optional

from pygame.rect import Rect

Expand All @@ -39,14 +39,14 @@
class PygameSDL2Tile:
texture: Texture
srcrect: Rect
size: Tuple[int, int]
size: tuple[int, int]
angle: float = 0.0
center: None = None
flipx: bool = False
flipy: bool = False


def handle_flags(flags: pytmx.TileFlags):
def handle_flags(flags: Optional[pytmx.TileFlags]) -> tuple[float, bool, bool]:
"""
Return angle and flip values for the SDL2 renderer
Expand Down Expand Up @@ -94,7 +94,9 @@ def load_image(rect=None, flags=None) -> PygameSDL2Tile:
return load_image


def load_pygame_sdl2(renderer: Renderer, filename: str, *args, **kwargs):
def load_pygame_sdl2(
renderer: Renderer, filename: str, *args: Any, **kwargs: Any
) -> pytmx.TiledMap:
"""
Load a TMX file, images, and return a TiledMap class
Expand Down
Loading

0 comments on commit 91e22e6

Please sign in to comment.