extra/opencc to 1.1.8-1

This commit is contained in:
Kevin Mihelich 2024-08-02 10:26:08 +00:00
parent a33af33763
commit b6b1c6eed9
3 changed files with 185 additions and 14 deletions

View file

@ -1,10 +1,11 @@
pkgbase = opencc pkgbase = opencc
pkgdesc = Library for Open Chinese Convert pkgdesc = Library for Open Chinese Convert
pkgver = 1.1.7 pkgver = 1.1.8
pkgrel = 2 pkgrel = 1
url = https://github.com/BYVoid/OpenCC url = https://github.com/BYVoid/OpenCC
arch = x86_64 arch = x86_64
license = Apache license = Apache
makedepends = git
makedepends = chrpath makedepends = chrpath
makedepends = cmake makedepends = cmake
makedepends = darts makedepends = darts
@ -16,8 +17,10 @@ pkgbase = opencc
makedepends = rapidjson makedepends = rapidjson
makedepends = tclap makedepends = tclap
makedepends = gtest makedepends = gtest
source = https://github.com/BYVoid/OpenCC/archive/ver.1.1.7/opencc-1.1.7.tar.gz source = git+https://github.com/BYVoid/OpenCC.git#tag=ver.1.1.8
sha512sums = 26e4b12238f853b0fa91f9f0d9af7985bf04a0763185cc3b50b69ba99a2d80091b8c3160176d0d4cd348fbf1a680bfd80dc740dc60c938a256dc2dac8ef49f15 source = 8f3a5b4b201f091713cb4e2b1b5883a4b12d10b2.patch
sha512sums = c5ffe2223e5cf3c2a3079128e6eefa74db083c32897f46ae58c981f3fe057cff045c4fed22266d4fe9170cf689169d4d8023b35da058c52d3a8f3034ca0ca8b2
sha512sums = febade61cc1734db891234484893128519dffc198f80883fc4838534684f91db2a21641252615820ae9bedffce52451535ea2717a40958b80ea82590850b90ac
pkgname = opencc pkgname = opencc
pkgdesc = Library for Open Chinese Convert pkgdesc = Library for Open Chinese Convert

View file

@ -0,0 +1,162 @@
From 8f3a5b4b201f091713cb4e2b1b5883a4b12d10b2 Mon Sep 17 00:00:00 2001
From: Frost Ming <mianghong@gmail.com>
Date: Thu, 18 Jul 2024 05:32:08 +0800
Subject: [PATCH] fix: release sdist to PyPI (#797)
* fix: release sdist to PyPI
* fix: add newline at file end
* fix: ignore more files
Signed-off-by: Frost Ming <me@frostming.com>
* fix: change the install root of cmake
Signed-off-by: Frost Ming <me@frostming.com>
* fix: make it work for editable build as well
Signed-off-by: Frost Ming <me@frostming.com>
* fix release script
Signed-off-by: Frost Ming <me@frostming.com>
* fix: include files in sdist
Signed-off-by: Frost Ming <me@frostming.com>
---------
Signed-off-by: Frost Ming <me@frostming.com>
Co-authored-by: Carbo Kuo <BYVoid@users.noreply.github.com>
---
.github/workflows/python.yml | 10 ++++----
.gitignore | 1 +
MANIFEST.in | 9 +++++++
Makefile | 6 ++---
pyproject.toml | 3 +++
python/opencc/.gitignore | 1 +
python/opencc/clib/__init__.py | 1 -
release-pypi-linux.sh | 8 +++----
release-pypi-macos.sh | 6 ++---
release-pypi-windows.cmd | 6 ++---
setup.py | 43 +++++++++-------------------------
11 files changed, 43 insertions(+), 51 deletions(-)
create mode 100644 MANIFEST.in
create mode 100644 pyproject.toml
diff --git a/setup.py b/setup.py
index a7ce160d..a4bc500f 100644
--- a/setup.py
+++ b/setup.py
@@ -9,21 +9,12 @@
import wheel.bdist_wheel
_this_dir = os.path.dirname(os.path.abspath(__file__))
-_clib_dir = os.path.join(_this_dir, 'python', 'opencc', 'clib')
_build_dir = os.path.join(_this_dir, 'build', 'python')
_cmake_file = os.path.join(_this_dir, 'CMakeLists.txt')
_author_file = os.path.join(_this_dir, 'AUTHORS')
_readme_file = os.path.join(_this_dir, 'README.md')
-try:
- sys.path.insert(0, os.path.join(_this_dir, 'python'))
-
- import opencc # noqa
- _libopencc_built = True
-except ImportError:
- _libopencc_built = False
-
def get_version_info():
version_info = ['1', '0', '0']
@@ -70,20 +61,13 @@ def get_long_description():
return f.read().decode('utf-8')
-def build_libopencc():
- if _libopencc_built:
- return # Skip building binary file
+def build_libopencc(output_path):
print('building libopencc into %s' % _build_dir)
is_windows = sys.platform == 'win32'
# Make build directories
- if is_windows:
- subprocess.call('md {}'.format(_build_dir), shell=True)
- subprocess.call('md {}'.format(_clib_dir), shell=True)
- else:
- subprocess.call('mkdir -p {}'.format(_build_dir), shell=True)
- subprocess.call('mkdir -p {}'.format(_clib_dir), shell=True)
+ os.makedirs(_build_dir, exist_ok=True)
# Configure
cmake_args = [
@@ -93,14 +77,14 @@ def build_libopencc():
'-DENABLE_BENCHMARK:BOOL=OFF',
'-DBUILD_PYTHON:BOOL=ON',
'-DCMAKE_BUILD_TYPE=Release',
- '-DCMAKE_INSTALL_PREFIX={}'.format(_clib_dir),
- '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}'.format(_clib_dir),
+ '-DCMAKE_INSTALL_PREFIX={}'.format(output_path),
+ '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}'.format(output_path),
'-DPYTHON_EXECUTABLE={}'.format(sys.executable),
]
if is_windows:
cmake_args += \
- ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE={}'.format(_clib_dir)]
+ ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE={}'.format(output_path)]
if sys.maxsize > 2**32:
cmake_args += ['-A', 'x64']
@@ -117,11 +101,6 @@ def build_libopencc():
errno = subprocess.call(cmd)
assert errno == 0, 'Build failed'
- # Empty __init__.py file has to be created
- # to make opencc.clib a module
- with open('{}/__init__.py'.format(_clib_dir), 'w'):
- pass
-
class OpenCCExtension(setuptools.Extension, object):
def __init__(self, name, sourcedir=''):
@@ -131,8 +110,12 @@ def __init__(self, name, sourcedir=''):
class BuildExtCommand(setuptools.command.build_ext.build_ext, object):
def build_extension(self, ext):
+ if self.inplace:
+ output_path = os.path.join(_this_dir, 'python', 'opencc', 'clib')
+ else:
+ output_path = os.path.abspath(os.path.join(self.build_lib, 'opencc', 'clib'))
if isinstance(ext, OpenCCExtension):
- build_libopencc()
+ build_libopencc(output_path)
else:
super(BuildExtCommand, self).build_extension(ext)
@@ -157,7 +140,7 @@ def _determine_platform_tag():
return 'macosx-11.0-{}'.format(machine)
else:
raise NotImplementedError
-
+
if os.name == 'posix':
_, _, _, _, machine = os.uname()
return 'manylinux2014-{}'.format(machine)
@@ -190,10 +173,6 @@ def initialize_options(self):
packages=packages,
package_dir={'opencc': 'python/opencc'},
- package_data={str('opencc'): [
- 'clib/opencc_clib*',
- 'clib/share/opencc/*',
- ]},
ext_modules=[OpenCCExtension('opencc.clib.opencc_clib', 'python')],
cmdclass={
'build_ext': BuildExtCommand,

View file

@ -5,24 +5,30 @@
pkgbase=opencc pkgbase=opencc
pkgname=(opencc opencc-doc) pkgname=(opencc opencc-doc)
pkgver=1.1.7 pkgver=1.1.8
pkgrel=2 pkgrel=1
pkgdesc="Library for Open Chinese Convert" pkgdesc="Library for Open Chinese Convert"
url="https://github.com/BYVoid/OpenCC" url="https://github.com/BYVoid/OpenCC"
arch=('x86_64') arch=('x86_64')
license=('Apache') license=('Apache')
makedepends=('chrpath' 'cmake' 'darts' 'doxygen' 'marisa' 'pybind11' 'python-setuptools' makedepends=('git' 'chrpath' 'cmake' 'darts' 'doxygen' 'marisa' 'pybind11' 'python-setuptools'
'python-wheel' 'rapidjson' 'tclap' 'gtest') 'python-wheel' 'rapidjson' 'tclap' 'gtest')
source=("https://github.com/BYVoid/OpenCC/archive/ver.$pkgver/$pkgbase-$pkgver.tar.gz") source=("git+https://github.com/BYVoid/OpenCC.git#tag=ver.$pkgver"
sha512sums=('26e4b12238f853b0fa91f9f0d9af7985bf04a0763185cc3b50b69ba99a2d80091b8c3160176d0d4cd348fbf1a680bfd80dc740dc60c938a256dc2dac8ef49f15') 8f3a5b4b201f091713cb4e2b1b5883a4b12d10b2.patch)
sha512sums=('c5ffe2223e5cf3c2a3079128e6eefa74db083c32897f46ae58c981f3fe057cff045c4fed22266d4fe9170cf689169d4d8023b35da058c52d3a8f3034ca0ca8b2'
'febade61cc1734db891234484893128519dffc198f80883fc4838534684f91db2a21641252615820ae9bedffce52451535ea2717a40958b80ea82590850b90ac')
prepare() { prepare() {
cd OpenCC-ver.$pkgver cd OpenCC
rm -r deps rm -r deps
# as of opencc 1.1.8 there is no clean way to disable duplicated building of the clib again. plus, the installation is broken as well.
# let's revert the offending commit for now.
patch -Rp1 -i ../8f3a5b4b201f091713cb4e2b1b5883a4b12d10b2.patch
} }
build() { build() {
cd OpenCC-ver.$pkgver cd OpenCC
cmake -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_DOCUMENTATION:BOOL=ON -DBUILD_PYTHON:BOOL=ON \ cmake -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_DOCUMENTATION:BOOL=ON -DBUILD_PYTHON:BOOL=ON \
-DUSE_SYSTEM_MARISA:BOOL=ON -DUSE_SYSTEM_PYBIND11:BOOL=ON -DUSE_SYSTEM_RAPIDJSON:BOOL=ON \ -DUSE_SYSTEM_MARISA:BOOL=ON -DUSE_SYSTEM_PYBIND11:BOOL=ON -DUSE_SYSTEM_RAPIDJSON:BOOL=ON \
-DUSE_SYSTEM_TCLAP:BOOL=ON -DUSE_SYSTEM_DARTS:BOOL=ON -DENABLE_GTEST:BOOL=ON \ -DUSE_SYSTEM_TCLAP:BOOL=ON -DUSE_SYSTEM_DARTS:BOOL=ON -DENABLE_GTEST:BOOL=ON \
@ -34,7 +40,7 @@ build() {
} }
check() { check() {
cd OpenCC-ver.$pkgver cd OpenCC
make test make test
} }
@ -42,7 +48,7 @@ package_opencc() {
pkgdesc="Library for Open Chinese Convert" pkgdesc="Library for Open Chinese Convert"
depends=('marisa') depends=('marisa')
cd OpenCC-ver.$pkgver cd OpenCC
make DESTDIR="$pkgdir" install make DESTDIR="$pkgdir" install
python setup.py install --root="$pkgdir" --optimize=1 python setup.py install --root="$pkgdir" --optimize=1
@ -61,6 +67,6 @@ package_opencc() {
package_opencc-doc() { package_opencc-doc() {
pkgdesc="Documentation for Library for Open Chinese Convert" pkgdesc="Documentation for Library for Open Chinese Convert"
cd OpenCC-ver.$pkgver/doc cd OpenCC/doc
make DESTDIR="$pkgdir" install make DESTDIR="$pkgdir" install
} }