forked from JetBrains-Research/YouTokenToMe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
39 lines (36 loc) · 1.19 KB
/
Copy pathbuild.py
File metadata and controls
39 lines (36 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# https://stackoverflow.com/questions/63679315/how-to-use-cython-with-poetry
import os
# See if Cython is installed
try:
from Cython.Build import cythonize
# Do nothing if Cython is not available
except ImportError:
# Got to provide this function. Otherwise, poetry will fail
def build(setup_kwargs):
pass
# Cython is installed. Compile
else:
from setuptools import Extension
from setuptools.dist import Distribution
from distutils.command.build_ext import build_ext
# This function will be executed in setup.py:
def build(setup_kwargs):
# The file you want to compile
extensions = [
Extension(
"_youtokentome_cython",
[
"youtokentome/cpp/yttm.pyx",
"youtokentome/cpp/bpe.cpp",
"youtokentome/cpp/utils.cpp",
"youtokentome/cpp/utf8.cpp",
],
extra_compile_args=["-std=c++11", "-pthread", "-O3"],
language="c++",
)
]
# Build
setup_kwargs.update({
'ext_modules': cythonize(extensions),
'cmdclass': {'build_ext': build_ext}
})