Skip to content

Commit 5559c2c

Browse files
authored
feat: add Cython as build dependency (#122)
1 parent 7b3c18d commit 5559c2c

File tree

14 files changed

+37
-37155
lines changed

14 files changed

+37
-37155
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGES
1111
* Rebuild Cython wrapper with Cython 3.1.2 (#119).
1212
* Moved static project metadata to ``pyproject.toml`` (#120).
1313
* Updated metadata license to include the bundled one from marisa-trie as well (#120).
14+
* Add Cython as build dependency (#122).
1415

1516
1.2.1 (2024-10-12)
1617
------------------

MANIFEST.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include update_cpp.sh
2-
31
recursive-include src *.cpp *.pxd *.pyx
42
recursive-include marisa-trie/lib/marisa *.h *.cc
53
recursive-include marisa-trie/include/marisa *.h

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
22
build-backend = "setuptools.build_meta"
3-
requires = ["setuptools>=77.0"]
3+
requires = ["setuptools>=77.0", "cython>=3.1.2"]
44

55
[project]
66
name = "marisa-trie"

setup.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import glob
21
import itertools
3-
import os.path
2+
from pathlib import Path
43

4+
from Cython.Build import cythonize
55
from setuptools import setup, Extension
66

77

8-
MARISA_ROOT_DIR = "marisa-trie"
9-
MARISA_SOURCE_DIR = os.path.join(MARISA_ROOT_DIR, "lib")
10-
MARISA_INCLUDE_DIR = os.path.join(MARISA_ROOT_DIR, "include")
8+
MARISA_ROOT_DIR = Path("marisa-trie")
9+
MARISA_SOURCE_DIR = MARISA_ROOT_DIR / "lib"
10+
MARISA_INCLUDE_DIR = MARISA_ROOT_DIR / "include"
1111
MARISA_FILES = [
1212
"marisa/*.cc",
1313
"marisa/grimoire.cc",
@@ -16,36 +16,29 @@
1616
"marisa/grimoire/vector/*.cc",
1717
]
1818

19-
MARISA_FILES[:] = itertools.chain(
20-
*(glob.glob(os.path.join(MARISA_SOURCE_DIR, path)) for path in MARISA_FILES)
19+
MARISA_FILES[:] = map(str, itertools.chain(
20+
*(MARISA_SOURCE_DIR.glob(path) for path in MARISA_FILES)
21+
)
2122
)
2223

24+
extensions = [
25+
Extension(
26+
"marisa_trie",
27+
sources=["src/*.pyx"],
28+
language="c++",
29+
include_dirs=[str(MARISA_INCLUDE_DIR)],
30+
),
31+
]
2332

2433
setup(
2534
libraries=[
2635
(
2736
"libmarisa-trie",
2837
{
2938
"sources": MARISA_FILES,
30-
"include_dirs": [MARISA_SOURCE_DIR, MARISA_INCLUDE_DIR],
39+
"include_dirs": [str(MARISA_SOURCE_DIR), str(MARISA_INCLUDE_DIR)],
3140
},
3241
)
3342
],
34-
ext_modules=[
35-
Extension(
36-
"marisa_trie",
37-
[
38-
"src/agent.cpp",
39-
"src/base.cpp",
40-
"src/iostream.cpp",
41-
"src/key.cpp",
42-
"src/keyset.cpp",
43-
"src/marisa_trie.cpp",
44-
"src/query.cpp",
45-
"src/std_iostream.cpp",
46-
"src/trie.cpp",
47-
],
48-
include_dirs=[MARISA_INCLUDE_DIR],
49-
)
50-
],
43+
ext_modules=cythonize(extensions),
5144
)

0 commit comments

Comments
 (0)