Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
124 lines (108 loc) · 4.33 KB
/
Copy pathsetup.py
File metadata and controls
124 lines (108 loc) · 4.33 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from setuptools import setup
from os import path
import os
import subprocess
import sys
# milksnake 0.1.6 uses distutils.sysconfig.get_config_var('SHLIB_SUFFIX') to
# build the library name inside the wheel. On Windows this var is None,
# producing the literal name '_libomikuji__libNone' (no .dll extension),
# which cffi's dlopen / LoadLibraryEx cannot resolve. Patch it so the
# generated wrapper dlopens a proper '_libomikuji__lib.dll'.
if sys.platform in ("win32", "cygwin"):
_orig_get_config_var = None
def _patched_get_config_var(name):
if name == "SHLIB_SUFFIX":
return ".dll"
return _orig_get_config_var(name)
import distutils.sysconfig as _sysconfig
_orig_get_config_var = _sysconfig.get_config_var
_sysconfig.get_config_var = _patched_get_config_var
def build_native(spec):
c_api_dir = path.abspath(path.join(path.dirname(__file__), "c-api"))
if sys.platform == "darwin" and os.environ.get("OMIKUJI_UNIVERSAL2") == "1":
# Build for x86_64
subprocess.run(
["cargo", "build", "--release", "--target", "x86_64-apple-darwin"],
check=True,
cwd=c_api_dir,
)
# Build for arm64
subprocess.run(
["cargo", "build", "--release", "--target", "aarch64-apple-darwin"],
check=True,
cwd=c_api_dir,
)
# Combine with lipo into a fat binary
lib_x86 = path.join(
c_api_dir, "target", "x86_64-apple-darwin", "release", "libomikuji.dylib"
)
lib_arm = path.join(
c_api_dir, "target", "aarch64-apple-darwin", "release", "libomikuji.dylib"
)
fat_lib = path.join(c_api_dir, "target", "release", "libomikuji.dylib")
os.makedirs(path.dirname(fat_lib), exist_ok=True)
subprocess.run(
["lipo", "-create", "-output", fat_lib, lib_x86, lib_arm],
check=True,
cwd=c_api_dir,
)
# Use a no-op command for milksnake since we've already built everything
build_cmd = ["echo", "universal2 fat binary already built"]
else:
build_cmd = ["cargo", "build", "--release"]
build = spec.add_external_build(cmd=build_cmd, path="c-api")
spec.add_cffi_module(
module_path="omikuji._libomikuji",
dylib=lambda: build.find_dylib("omikuji", in_path="target/release"),
header_filename=lambda: build.find_header(
"omikuji.h", in_path="target/include"
),
rtld_flags=["NOW", "NODELETE"],
)
def load_readme():
curr_dir = path.abspath(path.dirname(__file__))
with open(path.join(curr_dir, "README.md"), encoding="utf-8") as f:
return f.read()
setup(
name="omikuji",
version="0.5.2",
author="Tom Dong",
author_email="tom.tung.dyb@gmail.com",
maintainer="Juho Inkinen, Osma Suominen",
maintainer_email="juho.inkinen@helsinki.fi, osma.suominen@helsinki.fi",
description=(
"Python binding to Omikuji, an efficient implementation of Partioned Label "
"Trees and its variations for extreme multi-label classification"
),
long_description=load_readme(),
long_description_content_type="text/markdown",
python_requires=">=3.8",
url="https://github.com/NatLibFi/omikuji",
license="MIT",
packages=["omikuji"],
package_dir={"": "python-wrapper"},
zip_safe=False,
platforms="any",
setup_requires=["milksnake>=0.1.6"],
install_requires=["milksnake>=0.1.6"],
milksnake_tasks=[build_native],
milksnake_universal=False,
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Rust",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Software Development :: Libraries",
],
)