Remove python2 binding and create python3 one (RHBZ#1738025)

epel9
Robin Lee 6 years ago
parent 52f723f28b
commit e01ff40e35

@ -0,0 +1,41 @@
From 9025eeb2bf2cba851073cb4178fd71f71c74391d Mon Sep 17 00:00:00 2001
From: Robin Lee <cheeselee@fedoraproject.org>
Date: Thu, 8 Aug 2019 17:16:21 +0800
Subject: [PATCH] chewing.py supports platforms with 64bit pointer
The old code will segfault on platforms with 64bit pointer like x86_64.
---
contrib/python/chewing.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/contrib/python/chewing.py b/contrib/python/chewing.py
index a9f17ec..acf000b 100644
--- a/contrib/python/chewing.py
+++ b/contrib/python/chewing.py
@@ -19,6 +19,8 @@ _libchewing.chewing_cand_String.restype = c_char_p
_libchewing.chewing_zuin_String.restype = c_char_p
_libchewing.chewing_aux_String.restype = c_char_p
_libchewing.chewing_get_KBString.restype = c_char_p
+_libchewing.chewing_new.restype = c_void_p
+_libchewing.chewing_new2.restype = c_void_p
def Init(datadir, userdir):
@@ -39,12 +41,12 @@ class ChewingContext:
None)
def __del__(self):
- _libchewing.chewing_delete(self.ctx)
+ _libchewing.chewing_delete(c_void_p(self.ctx))
def __getattr__(self, name):
func = 'chewing_' + name
if hasattr(_libchewing, func):
- wrap = partial(getattr(_libchewing, func), self.ctx)
+ wrap = partial(getattr(_libchewing, func), c_void_p(self.ctx))
setattr(self, name, wrap)
return wrap
else:
--
2.21.0

@ -1,58 +0,0 @@
from ctypes import *
from functools import partial
import sys
_libchewing = None
if sys.platform == "win32": # Windows
import os.path
# find in current dir first
dll_path = os.path.join(os.path.dirname(__file__), "chewing.dll")
if not os.path.exists(dll_path):
dll_path = "chewing.dll" # search in system path
_libchewing = CDLL(dll_path)
else: # UNIX-like systems
_libchewing = CDLL('libchewing.so.3')
_libchewing.chewing_commit_String.restype = c_char_p
_libchewing.chewing_buffer_String.restype = c_char_p
_libchewing.chewing_cand_String.restype = c_char_p
_libchewing.chewing_zuin_String.restype = c_char_p
_libchewing.chewing_aux_String.restype = c_char_p
_libchewing.chewing_get_KBString.restype = c_char_p
def Init(datadir, userdir):
return _libchewing.chewing_Init(datadir, userdir)
class ChewingContext:
def __init__(self, **kwargs):
if not kwargs:
self.ctx = _libchewing.chewing_new()
else:
syspath = kwargs.get("syspath", None)
userpath = kwargs.get("userpath", None)
self.ctx = _libchewing.chewing_new2(
syspath,
userpath,
None,
None)
def __del__(self):
_libchewing.chewing_delete(self.ctx)
def __getattr__(self, name):
func = 'chewing_' + name
if hasattr(_libchewing, func):
wrap = partial(getattr(_libchewing, func), self.ctx)
setattr(self, name, wrap)
return wrap
else:
raise AttributeError(name)
def Configure(self, cpp, maxlen, direction, space, kbtype):
self.set_candPerPage(cpp)
self.set_maxChiSymbolLen(maxlen)
self.set_addPhraseDirection(direction)
self.set_spaceAsSelection(space)
self.set_KBType(kbtype)

@ -1,25 +1,28 @@
%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
%global libchewing_python_dir %{python_sitearch}/libchewing
%global libchewing_python_dir %{python3_sitelib}
%global im_name_zh_TW 新酷音輸入法
%global name_zh_TW %{im_name_zh_TW}函式庫
Name: libchewing
Version: 0.5.1
Release: 12%{?dist}
Release: 13%{?dist}
Summary: Intelligent phonetic input method library for Traditional Chinese
Summary(zh_TW): %{name_zh_TW}
License: LGPLv2+
URL: http://chewing.csie.net/
Source0: https://github.com/chewing/%{name}/archive/v%{version}.tar.gz
Source1: https://raw.githubusercontent.com/chewing/%{name}/v%{version}/contrib/python/chewing.py
# https://github.com/chewing/libchewing/pull/310
Patch0: 0001-chewing.py-supports-platforms-with-64bit-pointer.patch
BuildRequires: autoconf automake libtool pkgconfig texinfo
BuildRequires: sqlite-devel
BuildRequires: python3-devel
Requires: sqlite
Requires(post): info
Requires(preun): info
# since f31
Obsoletes: python2-libchewing < 0.5.1-13
%description
libchewing is an intelligent phonetic input method library for Chinese.
@ -48,28 +51,21 @@ library.
像是標頭檔(header files),以及函式庫。
%package -n python2-%{name}
%package -n python3-%{name}
Summary: Python binding for libchewing
BuildArch: noarch
Summary(zh_TW): %{name_zh_TW} python 綁定
BuildRequires: python2-devel
Requires: %{name}%{?_isa} = %{version}-%{release}
Requires: python2
%{?python_provide:%python_provide python2-%{name}}
# Remove before F30
Provides: %{name}-python = %{version}-%{release}
Provides: %{name}-python%{?_isa} = %{version}-%{release}
Obsoletes: %{name}-python < %{version}-%{release}
%description -n python2-%{name}
%description -n python3-%{name}
Python binding of libchewing.
%description -l zh_TW -n python2-%{name}
%description -l zh_TW -n python3-%{name}
%{name_zh_TW} python 綁定
%prep
%setup -q
mkdir -p contrib/python
cp -p %SOURCE1 contrib/python
%patch0 -p1
%build
CFLAGS="%{optflags} -g -DLIBINSTDIR='%{_libdir}'"
@ -84,16 +80,11 @@ rm %{buildroot}%{_libdir}/libchewing.la
mkdir -p %{buildroot}%{libchewing_python_dir}
cp -p contrib/python/chewing.py %{buildroot}%{libchewing_python_dir}
mkdir -p %{buildroot}%{_libdir}/chewing
touch %{buildroot}%{libchewing_python_dir}/__init__.py
rm -f %{buildroot}/%{_infodir}/dir
%ldconfig_scriptlets
%files
%doc README.md AUTHORS COPYING NEWS TODO
%{_datadir}/%{name}/*
%{_datadir}/%{name}/
%{_libdir}/*.so.*
%{_infodir}/%{name}.info.*
@ -103,10 +94,14 @@ rm -f %{buildroot}/%{_infodir}/dir
%{_libdir}/pkgconfig/chewing.pc
%{_libdir}/*.so
%files -n python2-%{name}
%{libchewing_python_dir}
%files -n python3-%{name}
%{libchewing_python_dir}/chewing.py
%{libchewing_python_dir}/__pycache__/*
%changelog
* Thu Aug 8 2019 Robin Lee <cheeselee@fedoraproject.org> - 0.5.1-13
- Remove python2 binding and create python3 one (RHBZ#1738025)
* Thu Jul 25 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.5.1-12
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild

Loading…
Cancel
Save