Skip to content

Commit eceecf1

Browse files
committed
Fix setup.py for the changes
fix compiling of colours module raise DeprecationWarning when something from old API is called. Signed-off-by: Naveen M K <[email protected]>
1 parent d38c7ae commit eceecf1

File tree

11 files changed

+63
-24
lines changed

11 files changed

+63
-24
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ docs/_build
88
*.c
99
# C extensions
1010
*.so
11-
manimpango/*.dll
11+
*.dll
1212
# Distribution / packaging
1313
.Python
1414
build/

manimpango/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
f"{os.environ['PATH']}"
1111
)
1212
try:
13-
from .cmanimpango import * # noqa: F403,F401
13+
from ._deprecated.cmanimpango import * # noqa: F403,F401
1414
from .enums import * # noqa: F403,F401
1515
from .register_font import * # noqa: F403,F401
16+
from ._cutils import * # noqa: F403,F401
1617
except ImportError: # pragma: no cover
1718
raise ImportError("Couldn't load the necessary Shared Libraries.")

manimpango/_cutils.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from pango cimport *
2+
from cairo cimport *
3+
4+
cpdef str pango_version():
5+
return pango_version_string().decode('utf-8')
6+
7+
cpdef str cairo_version():
8+
return cairo_version_string().decode('utf-8')

manimpango/_depreciated/cmanimpango.pyx renamed to manimpango/_deprecated/cmanimpango.pyx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
from xml.sax.saxutils import escape
2-
from .utils import *
3-
from .enums import Alignment
2+
from ..utils import *
3+
from ..enums import Alignment
44
import warnings
5+
from glib cimport *
6+
from cairo cimport *
7+
from pango cimport *
8+
import warnings
9+
10+
def raise_deprecation_warning(name):
11+
msg = (
12+
"`manimpango.{n}` is a deprecated. "
13+
"This warning may have happen because you have used newer "
14+
"version of manimpango with older version of Manim. "
15+
"Either upgrade Manim or downgrade ManimPango."
16+
).format(n=name)
17+
warnings.warn(msg, DeprecationWarning, stacklevel=2)
518

619
class TextSetting:
720
"""Formatting for slices of a :class:`manim.mobject.svg.text_mobject.Text` object."""
@@ -14,6 +27,7 @@ class TextSetting:
1427
weight,
1528
line_num=-1
1629
):
30+
raise_deprecation_warning("TextSetting")
1731
self.start = start
1832
self.end = end
1933
self.font = font.encode('utf-8')
@@ -34,6 +48,7 @@ def text2svg(
3448
orig_text:str
3549
) -> int:
3650
"""Render an SVG file from a :class:`manim.mobject.svg.text_mobject.Text` object."""
51+
raise_deprecation_warning("text2svg")
3752
cdef cairo_surface_t* surface
3853
cdef cairo_t* cr
3954
cdef PangoFontDescription* font_desc
@@ -130,6 +145,7 @@ def text2svg(
130145
class MarkupUtils:
131146
@staticmethod
132147
def validate(text: str) -> bool:
148+
raise_deprecation_warning("MarkupUtils.validate")
133149
text_bytes = text.encode("utf-8")
134150
return pango_parse_markup(text_bytes, -1, 0, NULL, NULL, NULL, NULL)
135151

@@ -154,6 +170,7 @@ class MarkupUtils:
154170
alignment: Alignment = None
155171
) -> int:
156172
"""Render an SVG file from a :class:`manim.mobject.svg.text_mobject.MarkupText` object."""
173+
raise_deprecation_warning("MarkupUtils.text2svg")
157174
cdef cairo_surface_t* surface
158175
cdef cairo_t* context
159176
cdef PangoFontDescription* font_desc
@@ -251,9 +268,3 @@ class MarkupUtils:
251268
cairo_surface_destroy(surface)
252269
g_object_unref(layout)
253270
return file_name
254-
255-
cpdef str pango_version():
256-
return pango_version_string().decode('utf-8')
257-
258-
cpdef str cairo_version():
259-
return cairo_version_string().decode('utf-8')

manimpango/_depreciated/cmanimpango.pxd

Lines changed: 0 additions & 3 deletions
This file was deleted.

manimpango/colours.pxd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from pango import *
1+
from pango cimport *
2+
23
cdef class Color:
34
cdef int red
45
cdef int green
56
cdef int blue
67
cdef PangoColor* color
78
cpdef Color copy(self)
8-
cpdef void* parse_color(self, char* spec)
9+
cpdef void parse_color(self, char* spec)
910
cpdef str to_string(self)

manimpango/colours.pyx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
# attributes.
44

55
import copy
6+
67
cdef class Color:
7-
cdef int red
8-
cdef int green
9-
cdef int blue
10-
cdef PangoColor* color = NULL
118
def __init__(self, red: int, green: int, blue: int):
129
self.red = red
1310
self.green = green
1411
self.blue = blue
15-
12+
1613
cpdef Color copy(self):
1714
"""
1815
Make a deep copy of the ``Color`` structure.
@@ -59,7 +56,7 @@ cdef class Color:
5956
self._blue = int(blue)
6057
self.color.blue = blue
6158

62-
cpdef void* parse_color(self, char* spec):
59+
cpdef void parse_color(self, char* spec):
6360
"""
6461
Fill in the fields of a color from a string
6562
specification. The string can either one of

manimpango/glib.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ cdef extern from "glib.h":
44
ctypedef unsigned int guint
55
ctypedef gint gboolean
66
ctypedef unsigned short guint16
7+
ctypedef char gchar
78
void g_object_unref(gpointer object)
89
void g_free(gpointer mem)

manimpango/layout.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
# gets a bit easy.
88

99
cdef class Layout:
10+
1011
def __init__(self):
1112
pass

manimpango/pango.pxd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ cdef extern from "pango/pangocairo.h":
4141
PANGO_ALIGN_LEFT
4242
PANGO_ALIGN_CENTER
4343
PANGO_ALIGN_RIGHT
44+
ctypedef struct PangoColor:
45+
guint16 red
46+
guint16 green
47+
guint16 blue
4448
PangoLayout* pango_cairo_create_layout(cairo_t* cr)
4549
void pango_cairo_show_layout(
4650
cairo_t* cr,
@@ -137,6 +141,13 @@ cdef extern from "pango/pangocairo.h":
137141
PangoLayout *layout,
138142
PangoAlignment alignment
139143
)
144+
bint pango_color_parse(
145+
PangoColor *color,
146+
const char *spec
147+
)
148+
gchar* pango_color_to_string(
149+
const PangoColor *color
150+
)
140151

141152
cdef extern from *:
142153
"""

setup.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ def update_dict(dict1: dict, dict2: dict):
207207

208208
ext_modules = [
209209
Extension(
210-
"manimpango.cmanimpango",
211-
[str(base_file / ("cmanimpango" + ext))],
210+
"manimpango._deprecated.cmanimpango",
211+
[str(base_file / "_deprecated" / ("cmanimpango" + ext))],
212212
**returns,
213213
),
214214
Extension(
@@ -221,12 +221,23 @@ def update_dict(dict1: dict, dict2: dict):
221221
[str(base_file / ("register_font" + ext))],
222222
**returns,
223223
),
224+
# New one's here
225+
Extension(
226+
"manimpango._cutils",
227+
[str(base_file / ("_cutils" + ext))],
228+
**returns,
229+
),
230+
Extension(
231+
"manimpango.colours",
232+
[str(base_file / ("colours" + ext))],
233+
**returns,
234+
),
224235
]
225236
if USE_CYTHON:
226237
ext_modules = cythonize(
227238
ext_modules,
228239
language_level=3,
229-
include_path=["manimpango"],
240+
include_path=["manimpango","manimpango/_deprecated"],
230241
gdb_debug=DEBUG,
231242
compiler_directives={"linetrace": coverage},
232243
)

0 commit comments

Comments
 (0)