Skip to content

Commit

Permalink
Merge pull request #247 from fonttools/drop-py37
Browse files Browse the repository at this point in the history
Drop support Python 3.7, run tests on Python 3.11
  • Loading branch information
khaledhosny authored Dec 2, 2023
2 parents 45597f8 + c06fc18 commit dada466
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 109 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
runs-on: ${{ matrix.platform }}
strategy:
matrix:
python-version: ['3.7', '3.10']
python-version: ['3.8', '3.11']
platform: [ubuntu-latest, windows-latest]

steps:
Expand All @@ -54,7 +54,7 @@ jobs:
- name: Run Tox
run: tox -e py-cov
- name: Re-run Tox without cattrs
if: startsWith(matrix.platform, 'ubuntu-latest') && startsWith(matrix.python-version, '3.10')
if: startsWith(matrix.platform, 'ubuntu-latest') && startsWith(matrix.python-version, '3.11')
run: |
tox -e py-nocattrs
- name: Re-run Tox without msgpack
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[mypy]
python_version = 3.7
python_version = 3.8

# Untyped definitions and calls
disallow_incomplete_defs = True
Expand Down
55 changes: 22 additions & 33 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,55 +1,44 @@
#
# This file is autogenerated by pip-compile with python 3.11
# To update, run:
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --output-file=requirements-dev.txt requirements-dev.in
#
attrs==22.1.0
# via
# -c requirements.txt
# pytest
black==22.1.0
black==23.11.0
# via -r requirements-dev.in
click==8.0.3
click==8.1.7
# via black
coverage==6.3.1
coverage==7.3.2
# via -r requirements-dev.in
flake8==4.0.1
flake8==6.1.0
# via -r requirements-dev.in
iniconfig==1.1.1
iniconfig==2.0.0
# via pytest
isort==5.10.1
isort==5.12.0
# via -r requirements-dev.in
mccabe==0.6.1
mccabe==0.7.0
# via flake8
mypy==0.931
mypy==1.7.1
# via -r requirements-dev.in
mypy-extensions==0.4.3
mypy-extensions==1.0.0
# via
# black
# mypy
packaging==21.3
# via pytest
pathspec==0.9.0
packaging==23.2
# via
# black
# pytest
pathspec==0.11.2
# via black
platformdirs==2.4.1
platformdirs==4.0.0
# via black
pluggy==1.0.0
pluggy==1.3.0
# via pytest
py==1.11.0
# via pytest
pycodestyle==2.8.0
pycodestyle==2.11.1
# via flake8
pyflakes==2.4.0
pyflakes==3.1.0
# via flake8
pyparsing==3.0.7
# via packaging
pytest==7.0.0
pytest==7.4.3
# via -r requirements-dev.in
tomli==2.0.0
# via
# black
# mypy
# pytest
typing-extensions==4.0.1
typing-extensions==4.8.0
# via mypy
24 changes: 12 additions & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#
# This file is autogenerated by pip-compile with python 3.11
# To update, run:
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --extra=converters --extra=json --extra=lxml --extra=msgpack setup.cfg
#
appdirs==1.4.4
# via fs
attrs==22.1.0
attrs==23.1.0
# via
# cattrs
# ufoLib2 (setup.cfg)
cattrs==22.2.0
cattrs==23.2.3
# via ufoLib2 (setup.cfg)
fonttools[ufo]==4.29.1
# via ufoLib2 (setup.cfg)
fs==2.4.15
fonttools[ufo]==4.46.0
# via
# fonttools
# ufoLib2 (setup.cfg)
fs==2.4.16
# via fonttools
lxml==4.9.1
lxml==4.9.3
# via ufoLib2 (setup.cfg)
msgpack==1.0.4
msgpack==1.0.7
# via ufoLib2 (setup.cfg)
orjson==3.7.8 ; platform_python_implementation != "PyPy"
orjson==3.9.10 ; platform_python_implementation != "PyPy"
# via ufoLib2 (setup.cfg)
pytz==2021.3
# via fs
six==1.16.0
# via fs

Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ classifiers =
[options]
package_dir = =src
packages = find:
python_requires = >=3.7
python_requires = >=3.8
install_requires =
attrs >= 22.1.0
fonttools[ufo] >= 4.0.0
typing_extensions ; python_version < "3.8"

# https://www.python.org/dev/peps/pep-0561
[options.package_data]
Expand Down
8 changes: 2 additions & 6 deletions src/ufoLib2/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

from attrs import fields, has, resolve_types
from cattrs import Converter
from cattrs.gen import (
AttributeOverride,
make_dict_structure_fn,
make_dict_unstructure_fn,
override,
)
from cattrs.gen import make_dict_structure_fn, make_dict_unstructure_fn, override
from cattrs.gen._consts import AttributeOverride
from fontTools.misc.transform import Transform

is_py37 = sys.version_info[:2] == (3, 7)
Expand Down
11 changes: 2 additions & 9 deletions src/ufoLib2/objects/contour.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from __future__ import annotations

import warnings
from collections.abc import MutableSequence
from typing import TYPE_CHECKING, Iterable, Iterator, List, Optional, overload
from typing import Iterable, Iterator, List, MutableSequence, Optional, overload

from attrs import define, field
from fontTools.pens.basePen import AbstractPen
Expand All @@ -13,16 +12,10 @@
from ufoLib2.serde import serde
from ufoLib2.typing import GlyphSet

# For Python 3.7 compatibility.
if TYPE_CHECKING:
ContourMapping = MutableSequence[Point]
else:
ContourMapping = MutableSequence


@serde
@define
class Contour(ContourMapping):
class Contour(MutableSequence[Point]):
"""Represents a contour as a list of points.
Behavior:
Expand Down
11 changes: 2 additions & 9 deletions src/ufoLib2/objects/image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, ClassVar, Iterator, Optional, Tuple
from typing import Any, ClassVar, Iterator, Mapping, Optional, Tuple

from attrs import define, field
from fontTools.misc.transform import Identity, Transform
Expand All @@ -10,16 +9,10 @@

from .misc import _convert_transform

# For Python 3.7 compatibility.
if TYPE_CHECKING:
ImageMapping = Mapping[str, Any]
else:
ImageMapping = Mapping


@serde
@define
class Image(ImageMapping):
class Image(Mapping[str, Any]):
"""Represents a background image reference.
See http://unifiedfontobject.org/versions/ufo3/images/ and
Expand Down
26 changes: 6 additions & 20 deletions src/ufoLib2/objects/misc.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from __future__ import annotations

import collections.abc
import uuid
from abc import abstractmethod
from collections.abc import Mapping, MutableMapping
from copy import deepcopy
from functools import lru_cache
from typing import (
TYPE_CHECKING,
Any,
Dict,
Iterator,
Mapping,
MutableMapping,
NamedTuple,
Optional,
Sequence,
Expand Down Expand Up @@ -103,7 +103,7 @@ def _getstate_unlazify_attrs(self: Any) -> Dict[str, Any]:
# Below is adapted from `attrs._make._ClassBuilder._make_getstate_setstate` method:
# https://github.com/python-attrs/attrs/blob/36ed0204/src/attr/_make.py#L931-L937
def _setstate_attrs(self: Any, state: Dict[str, Any]) -> None:
_bound_setattr = _obj_setattr.__get__(self, attrs.Attribute) # type: ignore
_bound_setattr = _obj_setattr.__get__(self, attrs.Attribute)
for a in attrs.fields(self.__class__):
if a.name in state:
_bound_setattr(a.name, state[a.name])
Expand All @@ -121,7 +121,7 @@ def _object_lib(parent_lib: dict[str, Any], obj: HasIdentifier) -> dict[str, Any
object_libs = parent_lib["public.objectLibs"] = {}
else:
object_libs = parent_lib["public.objectLibs"]
assert isinstance(object_libs, collections.abc.MutableMapping)
assert isinstance(object_libs, MutableMapping)

if obj.identifier in object_libs:
object_lib: dict[str, Any] = object_libs[obj.identifier]
Expand Down Expand Up @@ -158,15 +158,8 @@ class DataPlaceholder(bytes):
Tds = TypeVar("Tds", bound="DataStore")


# For Python 3.7 compatibility.
if TYPE_CHECKING:
DataStoreMapping = MutableMapping[str, bytes]
else:
DataStoreMapping = MutableMapping


@define
class DataStore(DataStoreMapping):
class DataStore(MutableMapping[str, bytes]):
"""Represents the base class for ImageSet and DataSet.
Both behave like a dictionary that loads its "values" lazily by default and only
Expand Down Expand Up @@ -353,17 +346,10 @@ def _structure(
return self


# For Python 3.7 compatibility.
if TYPE_CHECKING:
AttrDictMixinMapping = Mapping[str, Any]
else:
AttrDictMixinMapping = Mapping


_T = TypeVar("_T", bound="AttrDictMixin")


class AttrDictMixin(AttrDictMixinMapping):
class AttrDictMixin(Mapping[str, Any]):
"""Read attribute values using mapping interface.
For use with Anchors, Guidelines and WoffMetadata classes, where client code
Expand Down
5 changes: 2 additions & 3 deletions src/ufoLib2/serde/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def serde(cls: Type[T]) -> Type[T]:

supported_formats = []
for fmt in _SERDE_FORMATS_:

try:
serde_submodule = import_module(f"ufoLib2.serde.{fmt}")
except ImportError as exc:
Expand All @@ -85,12 +84,12 @@ def serde(cls: Type[T]) -> Type[T]:
setattr(
cls,
f"{fmt}_loads",
partialmethod(classmethod(_loads), __callback=serde_submodule.loads),
partialmethod(classmethod(_loads), __callback=serde_submodule.loads), # type: ignore[arg-type]
)
setattr(
cls,
f"{fmt}_load",
partialmethod(classmethod(_load), __callback=serde_submodule.load),
partialmethod(classmethod(_load), __callback=serde_submodule.load), # type: ignore[arg-type]
)
setattr(cls, f"{fmt}_dumps", serde_submodule.dumps)
setattr(cls, f"{fmt}_dump", serde_submodule.dump)
Expand Down
9 changes: 1 addition & 8 deletions src/ufoLib2/typing.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
from __future__ import annotations

import os
import sys
from typing import TypeVar, Union
from typing import Protocol, TypeVar, Union

from fontTools.pens.basePen import AbstractPen
from fontTools.pens.pointPen import AbstractPointPen

if sys.version_info >= (3, 8):
from typing import Protocol
else:
from typing_extensions import Protocol


T = TypeVar("T")
"""Generic variable for mypy for trivial generic function signatures."""

Expand Down
1 change: 0 additions & 1 deletion tests/serde/test_msgpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def test_dumps_loads(ufo_UbuTestData: ufoLib2.objects.Font) -> None:


def test_dump_load(tmp_path: Path, ufo_UbuTestData: ufoLib2.objects.Font) -> None:

font = ufo_UbuTestData
with open(tmp_path / "test.msgpack", "wb") as f:
font.msgpack_dump(f) # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion tests/serde/test_serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_msgpack_not_installed() -> None:
@pytest.mark.parametrize(
"object_info",
BASIC_EMPTY_OBJECTS,
ids=lambda x: x["class_name"], # type: ignore
ids=lambda x: x["class_name"],
)
def test_serde_all_objects(fmt: str, object_info: Dict[str, Any]) -> None:
for req in EXTRAS_REQUIREMENTS[fmt]:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ufoLib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

def test_import_version() -> None:
assert hasattr(ufoLib2, "__version__")
assert isinstance(ufoLib2.__version__, str) # type: ignore
assert isinstance(ufoLib2.__version__, str)


def test_LayerSet_load_layers_on_iteration(tmp_path: Path) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = lint, py3{7,8,9,10}-cov, htmlcov
envlist = lint, py3{8,9,10,11}-cov, htmlcov
isolated_build = true

[testenv]
Expand Down

0 comments on commit dada466

Please sign in to comment.