forked from pypest/pypestutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
83 lines (64 loc) · 2.8 KB
/
setup.py
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
#!/usr/bin/env python3
import os
from setuptools import setup
from setuptools.command.install import install
from setuptools.dist import Distribution
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
# current working directory of this setup.py file
_cwd = os.path.abspath(os.path.split(__file__)[0])
class bdist_wheel(_bdist_wheel):
def finalize_options(self):
_bdist_wheel.finalize_options(self)
self.root_is_pure = False
class BinaryDistribution(Distribution):
"""Distribution which always forces a binary package with platform name"""
def has_ext_modules(foo):
return True
class InstallPlatlib(install):
def finalize_options(self):
"""
Copy the shared libraries into the wheel. Note that this
will *only* check in `pypestutils/lib` rather than anywhere on
the system so if you are building a wheel you *must* copy or
symlink the `.so`/`.dll`/`.dylib` files into `pypestutils/lib`.
"""
# use for checking extension types
from fnmatch import fnmatch
install.finalize_options(self)
if self.distribution.has_ext_modules():
self.install_lib = self.install_platlib
# get the location of the shared library on the filesystem
# where we're putting the shared library in the build directory
target_dir = os.path.join(self.build_lib, "pypestutils", "lib")
# where are we checking for shared libraries
source_dir = os.path.join(_cwd, "pypestutils", "lib")
# what patterns represent shared libraries
patterns = {"*.so", "libpestutils*dylib", "*.dll"}
if not os.path.isdir(source_dir):
# no copying of binary parts to library
# this is so `pip install .` works even
# if `pypestutils/lib` isn't populated
return
for file_name in os.listdir(source_dir):
# make sure file name is lower case
check = file_name.lower()
# use filename pattern matching to see if it is
# a shared library format file
if not any(fnmatch(check, p) for p in patterns):
continue
# if the source isn't a file skip it
if not os.path.isfile(os.path.join(source_dir, file_name)):
continue
# make build directory if it doesn't exist yet
if not os.path.isdir(target_dir):
os.makedirs(target_dir)
# copy the source file to the target directory
self.copy_file(
os.path.join(source_dir, file_name), os.path.join(target_dir, file_name)
)
# See pyproject.toml for other project metadata
setup(
name="pypestutils",
distclass=BinaryDistribution,
cmdclass={"bdist_wheel": bdist_wheel, "install": InstallPlatlib},
)