Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
135 lines (113 loc) · 4.38 KB
/
Copy pathsetup.py
File metadata and controls
135 lines (113 loc) · 4.38 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
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python
import os
import re
import subprocess
import sys
from setuptools import Distribution
from setuptools import find_packages
from setuptools import setup
from setuptools.command.bdist_wheel import bdist_wheel
from setuptools.command.install import install
# This hack is from http://stackoverflow.com/a/7071358/1231454;
# the version is kept in a seperate file and gets parsed - this
# way, setup.py doesn't have to import the package.
VERSIONFILE = "libfaketime/_version.py"
version_line = open(VERSIONFILE).read()
version_re = r"^__version__ = ['\"]([^'\"]*)['\"]"
match = re.search(version_re, version_line, re.M)
if match:
version = match.group(1)
else:
raise RuntimeError(f"Could not find version in '{VERSIONFILE}'")
_vendor_path = "libfaketime/vendor/libfaketime"
if sys.platform == "linux" or sys.platform == "linux2":
libname = "libfaketime.so.1"
elif sys.platform == "darwin":
libname = "libfaketime.1.dylib"
else:
raise RuntimeError("libfaketime does not support platform {sys.platform}")
faketime_lib = os.path.join(_vendor_path, "src", libname)
class BinaryDistribution(Distribution):
"""A distribution containing a platform-specific shared library."""
def has_ext_modules(self) -> bool:
"""Use the platform library directory for the bundled native library."""
return True
class PlatformWheel(bdist_wheel):
"""A platform-specific wheel without a Python ABI dependency."""
def get_tag(self) -> tuple[str, str, str]:
"""Keep Python compatibility while selecting the build platform."""
_, _, platform_tag = super().get_tag()
return "py3", "none", platform_tag
class CustomInstall(install):
def run(self):
self.my_outputs = []
if sys.platform in ("linux", "linux2"):
# -Wno-unused-function works around a libfaketime 0.9.13 build
# failure under -UFAKE_SLEEP; drop it once 0.9.14 is vendored.
subprocess.check_call(
[
"env",
"FAKETIME_COMPILE_CFLAGS="
"-UFAKE_STAT -UFAKE_UTIME -UFAKE_SLEEP -Wno-unused-function",
"make",
"-C",
_vendor_path,
]
)
elif sys.platform == "darwin":
subprocess.check_call(["make", "-C", _vendor_path])
dest = os.path.join(self.install_lib, os.path.dirname(faketime_lib))
try:
os.makedirs(dest)
except OSError as e:
if e.errno != 17:
raise
print(faketime_lib, "->", dest)
self.copy_file(faketime_lib, dest)
self.my_outputs.append(os.path.join(dest, libname))
install.run(self)
def get_outputs(self):
outputs = install.get_outputs(self)
outputs.extend(self.my_outputs)
return outputs
setup(
name="libfaketime",
version=version,
author="Simon Weber",
author_email="simon@simonmweber.com",
url="http://pypi.python.org/pypi/libfaketime/",
packages=find_packages(exclude=["test"]),
scripts=[],
license="GPLv2",
description="A fast alternative to freezegun that wraps libfaketime.",
long_description=(open("README.md").read() + "\n\n" + open("CHANGELOG.md").read()),
long_description_content_type="text/markdown",
python_requires=">=3.11",
install_requires=[
"python-dateutil >= 1.3",
"pytz", # for pytz.timezone and pytz.utc
],
classifiers=[
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"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 :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries :: Python Modules",
],
include_package_data=True,
zip_safe=False,
distclass=BinaryDistribution,
cmdclass={"bdist_wheel": PlatformWheel, "install": CustomInstall},
entry_points={
"console_scripts": [
"python-libfaketime = libfaketime:main",
]
},
)