Skip to content

Commit

Permalink
update python versions, remove dependency on (stale) bundled src library
Browse files Browse the repository at this point in the history
* respin debian patch
* add endian fix from upstream PR

Origin1: https://salsa.debian.org/python-team/packages/python-datrie/-/tree/master/debian/patches
Origin2: upstream, pytries#85
Signed-off-by: Stephen L Arnold <[email protected]>
  • Loading branch information
sarnold committed Nov 16, 2020
1 parent c111d84 commit afa9620
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
4 changes: 1 addition & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ include COPYING
include tox.ini
include tox-bench.ini
include update_c.sh
recursive-include libdatrie *.h
recursive-include libdatrie *.c
include tests/words100k.txt.zip
recursive-include tests *.py

include src/datrie.pyx
include src/cdatrie.pxd
include src/stdio_ext.pxd
exclude src/datrie.c
exclude src/datrie.c
21 changes: 10 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
from setuptools import setup, Extension

from Cython.Build import cythonize

LIBDATRIE_DIR = 'libdatrie'
LIBDATRIE_FILES = sorted(glob.glob(os.path.join(LIBDATRIE_DIR, "datrie", "*.c")))
from Cython.Build.Dependencies import default_create_extension

DESCRIPTION = __doc__
LONG_DESCRIPTION = open('README.rst').read() + open('CHANGES.rst').read()
Expand All @@ -30,22 +28,26 @@
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Scientific/Engineering :: Information Analysis',
'Topic :: Text Processing :: Linguistic'
]

def do_create_extension(template, kwds):
libs = kwds.get('libraries', []) + ["datrie"]
kwds['libraries'] = libs
return default_create_extension(template, kwds)

ext_modules = cythonize(
'src/datrie.pyx', 'src/cdatrie.pxd', 'src/stdio_ext.pxd',
annotate=True,
include_path=[os.path.join(os.path.dirname(os.path.abspath(__file__)), "src")],
language_level=2
language_level=2,
create_extension=do_create_extension
)

for m in ext_modules:
m.include_dirs=[LIBDATRIE_DIR]

setup(name="datrie",
version="0.8.2",
description=DESCRIPTION,
Expand All @@ -55,10 +57,7 @@
license=LICENSE,
url='https://github.com/kmike/datrie',
classifiers=CLASSIFIERS,
libraries=[('datrie', {
"sources": LIBDATRIE_FILES,
"include_dirs": [LIBDATRIE_DIR]})],
ext_modules=ext_modules,
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*",
setup_requires=["pytest-runner", 'Cython>=0.28'],
tests_require=["pytest", "hypothesis"])
6 changes: 3 additions & 3 deletions src/cdatrie.pxd
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# cython: profile=False
from libc cimport stdio

cdef extern from "../libdatrie/datrie/triedefs.h":
cdef extern from "/usr/include/datrie/triedefs.h":
ctypedef int AlphaChar # it should be utf32 letter
ctypedef unsigned char TrieChar # 1 byte
ctypedef int TrieIndex
ctypedef int TrieData # int

cdef extern from "../libdatrie/datrie/alpha-map.h":
cdef extern from "/usr/include/datrie/alpha-map.h":

struct AlphaMap:
pass
Expand All @@ -20,7 +20,7 @@ cdef extern from "../libdatrie/datrie/alpha-map.h":
int alpha_char_strlen (AlphaChar *str)


cdef extern from "../libdatrie/datrie/trie.h":
cdef extern from "/usr/include/datrie/trie.h":

ctypedef struct Trie:
pass
Expand Down
6 changes: 4 additions & 2 deletions src/datrie.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1120,8 +1120,10 @@ cdef unicode unicode_from_alpha_char(cdatrie.AlphaChar* key, int len=0):
if length == 0:
length = cdatrie.alpha_char_strlen(key)*sizeof(cdatrie.AlphaChar)
cdef char* c_str = <char*> key
return c_str[:length].decode('utf_32_le')

if sys.byteorder == 'little':
return c_str[:length].decode('utf_32_le')
else:
return c_str[:length].decode('utf_32_be')

def to_ranges(lst):
"""
Expand Down
3 changes: 2 additions & 1 deletion tox-bench.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tox]
envlist = py27,py34,py35,py36,py37
envlist = py27, py3{5,6,7,8,9}
skip_missing_interpreters = true

[testenv]
commands=
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tox]
envlist = py27,py34,py35,py36,py37,py38
envlist = py27, py3{5,6,7,8,9}
skip_missing_interpreters = true

[testenv]
deps =
Expand Down

0 comments on commit afa9620

Please sign in to comment.