-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
145 lines (121 loc) · 4.39 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
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
136
137
138
139
140
141
142
143
144
145
# -*- coding: utf-8 -*-
# Copyright 2019 ko-han. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re
import io
import os
from setuptools import setup, Extension, find_packages
from distutils.command.build_ext import build_ext
from distutils.command.build_clib import build_clib
from distutils import sysconfig
def _is_using_gcc(obj):
is_gcc = False
if obj.compiler.compiler_type == "unix":
cc = sysconfig.get_config_var("CC")
if not cc:
cc = ""
is_gcc = "gcc" in cc
return is_gcc
class new_build_clib(build_clib):
def build_a_library(self, build_info, lib_name, libraries):
if _is_using_gcc(self):
args = build_info.get("extra_compiler_args") or []
args.append("-std=c99")
build_info["extra_compiler_args"] = args
build_clib.build_a_library(self, build_info, lib_name, libraries)
class new_build_ext(build_ext):
def build_extension(self, ext):
if _is_using_gcc(self):
if "-std=c99" not in ext.extra_compile_args:
ext.extra_compile_args.append("-std=c99")
build_ext.build_extension(self, ext)
here = os.path.abspath(os.path.dirname(__file__))
def source(*args):
return [os.path.join("src", arg) for arg in args]
DEBUG = os.getenv("CTOOLS_DEBUG", "").upper() == "TRUE"
extra_extension_args = {}
if DEBUG:
extra_extension_args.update(undef_macros=["NDEBUG"])
print("-" * 80)
print("Ctools enable DEBUG")
print("-" * 80)
else:
extra_extension_args.update(define_macros=[("NDEBUG", "1")])
def find_version():
with open(os.path.join(here, "ctools", "__init__.py"), "rt") as f:
value = f.read()
regex = r"""__version__\s?=\s?['"](?P<version>.+)['"]"""
match = re.search(regex, value)
if match is None:
raise RuntimeError("can't get version info")
return match.group("version").strip()
extensions = [
Extension(
"ctools._ctools",
source(
"cachemap.c",
"channel.c",
"ttlcache.c",
"functions.c",
"module.c",
"rbtree.c",
),
language="c",
**extra_extension_args
),
]
with io.open("README.rst", "rt", encoding="utf8") as f:
readme = f.read()
setup(
name="ctools",
version=find_version(),
author="hanke",
author_email="[email protected]",
description="A collection of useful extensions for python implement in C.",
url="https://github.com/ko-han/python-ctools",
project_urls={
"Bug Tracker": "https://github.com/ko-han/python-ctools/issues",
"Documentation": "https://python-ctools.readthedocs.io",
"Source Code": "https://github.com/ko-han/python-ctools",
},
license="Apache License 2.0",
long_description=readme,
long_description_content_type="text/x-rst",
python_requires=">=3.5",
include_package_data=True,
zip_safe=False,
ext_modules=extensions,
packages=find_packages(include=["ctools", "ctools.*"]),
classifiers=[
"License :: OSI Approved :: Apache Software License",
"Programming Language :: C",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: Implementation :: CPython",
"Operating System :: OS Independent",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Operating System :: Unix",
"Topic :: Utilities",
"Topic :: Software Development",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
],
cmdclass={"build_ext": new_build_ext, "build_clib": new_build_clib},
)