from setuptools import setup, find_packages
import os
import re
RUST_BUILD = "debug"
def version():
with open('pyspellrs/Cargo.toml', encoding='utf-8') as f:
content = f.read()
m = re.search('version = "([0-9\.]*)".*', content)
return m.group(1)
def readme():
with open('../README.md', encoding='utf-8') as f:
return f.read()
def build_native(spec):
cmd = ['cargo', 'build']
if RUST_BUILD == "release":
cmd.append('--release')
cmd.append('--package')
cmd.append('pyspellrs')
file_path = os.path.dirname(os.path.realpath(__file__))
add_external_build_path = os.path.realpath(os.path.dirname(file_path))
build = spec.add_external_build(
cmd=cmd,
path=add_external_build_path
)
cargo_target_dir = os.getenv('CARGO_TARGET_DIR', 'target')
in_path_dylib = os.path.normpath(os.path.join(cargo_target_dir, RUST_BUILD))
in_path_header = os.path.normpath("target")
spec.add_cffi_module(
module_path='spell._native',
dylib=lambda: build.find_dylib(
'pyspellrs', in_path=in_path_dylib),
header_filename=lambda: build.find_header(
'spell.h', in_path=in_path_header),
rtld_flags=['NOW', 'NODELETE']
)
setup(
name='spellrs',
version=version(),
url="https://travis-ci.org/nbigaouette/spell-rs",
author="Nicolas Bigaouette",
author_email="nbigaouette@gmail.com",
long_description=readme(),
python_requires='>=3',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
platforms='any',
install_requires=[
'milksnake',
'wheel',
],
milksnake_tasks=[
build_native,
]
)