From 2ad4081a351df9aa86125a8812907b0a7e12e07f Mon Sep 17 00:00:00 2001 From: Naveen M K Date: Wed, 11 Sep 2024 21:57:57 +0530 Subject: [PATCH] Linting --- .pre-commit-config.yaml | 9 ++++----- manimpango/__init__.py | 2 +- manimpango/_register_font.pxd | 3 ++- manimpango/_register_font.pyx | 1 - manimpango/cmanimpango.pyx | 2 +- manimpango/pango.pxd | 2 +- manimpango/register_font.py | 4 ++-- manimpango/utils.pxi | 3 ++- tests/test_fonts.py | 3 ++- tests/test_version.py | 4 ++-- 10 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e82a8912e..4b606189a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.6.0 hooks: - id: check-yaml - id: end-of-file-fixer @@ -9,19 +9,18 @@ repos: - id: mixed-line-ending - id: check-merge-conflict - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 24.8.0 hooks: - id: black language_version: python3.11 - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + rev: 7.1.1 hooks: - id: flake8 - additional_dependencies: [flake8-2020, flake8-implicit-str-concat] - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.10.0 diff --git a/manimpango/__init__.py b/manimpango/__init__.py index b826ab853..709874512 100644 --- a/manimpango/__init__.py +++ b/manimpango/__init__.py @@ -11,7 +11,7 @@ f"{os.environ['PATH']}" ) try: - from .register_font import * # noqa: F403,F401 + from .register_font import * # isort:skip # noqa: F403,F401 from .cmanimpango import * # noqa: F403,F401 from .enums import * # noqa: F403,F401 except ImportError as ie: # pragma: no cover diff --git a/manimpango/_register_font.pxd b/manimpango/_register_font.pxd index b6ee44fa4..a5ff3f55d 100644 --- a/manimpango/_register_font.pxd +++ b/manimpango/_register_font.pxd @@ -1,5 +1,6 @@ -from pango cimport * from libc.stddef cimport wchar_t +from pango cimport * + cdef extern from "Python.h": wchar_t* PyUnicode_AsWideCharString( diff --git a/manimpango/_register_font.pyx b/manimpango/_register_font.pyx index 56a7da49c..06d44976e 100644 --- a/manimpango/_register_font.pyx +++ b/manimpango/_register_font.pyx @@ -158,4 +158,3 @@ cpdef list _list_fonts(tuple registered_fonts): g_object_unref(fontmap) family_list.sort() return family_list - diff --git a/manimpango/cmanimpango.pyx b/manimpango/cmanimpango.pyx index dc2ebd632..6369f4dd6 100644 --- a/manimpango/cmanimpango.pyx +++ b/manimpango/cmanimpango.pyx @@ -2,9 +2,9 @@ import typing import warnings from xml.sax.saxutils import escape +from . import registered_fonts from .enums import Alignment from .utils import * -from . import registered_fonts include "utils.pxi" diff --git a/manimpango/pango.pxd b/manimpango/pango.pxd index 6a2291372..75254848e 100644 --- a/manimpango/pango.pxd +++ b/manimpango/pango.pxd @@ -178,7 +178,7 @@ cdef extern from *: return 1; } #endif - + """ # The above docs string is C which is used to # check for the Pango Version there at run time. diff --git a/manimpango/register_font.py b/manimpango/register_font.py index 7485356e4..c06fb3917 100644 --- a/manimpango/register_font.py +++ b/manimpango/register_font.py @@ -1,15 +1,15 @@ +# -*- coding: utf-8 -*- from __future__ import annotations from functools import cache -from dataclasses import dataclass from ._register_font import ( + RegisteredFont, _fc_register_font, _fc_unregister_font, _list_fonts, _register_font, _unregister_font, - RegisteredFont, ) __all__ = [ diff --git a/manimpango/utils.pxi b/manimpango/utils.pxi index 91ee8ba9f..19ed405a2 100644 --- a/manimpango/utils.pxi +++ b/manimpango/utils.pxi @@ -2,6 +2,7 @@ from _register_font cimport * import warnings + cdef inline add_to_fontmap(PangoFontMap* fontmap, str font_path): cdef GError *err = NULL error_message = "" @@ -11,7 +12,7 @@ cdef inline add_to_fontmap(PangoFontMap* fontmap, str font_path): error_message = "Unknown error" else: error_message = err.message.decode('utf-8') - + if not success: warnings.warn( f"Failed to add font at {font_path} to fontmap. Reason: {error_message}", diff --git a/tests/test_fonts.py b/tests/test_fonts.py index 95f3b516f..cc457ea0f 100644 --- a/tests/test_fonts.py +++ b/tests/test_fonts.py @@ -118,9 +118,10 @@ def test_adding_dummy_font(tmpdir): dummy = tmpdir / "font.ttf" with open(dummy, "wb") as f: f.write(b"dummy") - + assert not manimpango.register_font(str(dummy)), "Registered a dummy font?" + def test_simple_fonts_render(tmpdir): filename = str(Path(tmpdir) / "hello.svg") MarkupText("Hello World", filename=filename) diff --git a/tests/test_version.py b/tests/test_version.py index a75047473..1bcc5e1c0 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -3,11 +3,11 @@ def test_pango_version(): import manimpango v = manimpango.pango_version() - assert type(v) == str + assert isinstance(v, str) def test_cairo_version(): import manimpango v = manimpango.cairo_version() - assert type(v) == str + assert isinstance(v, str)