2021-12-16 23:38:12 +01:00
|
|
|
import platform
|
2022-02-17 20:38:09 +01:00
|
|
|
import shlex
|
2021-12-16 23:51:04 +01:00
|
|
|
from glob import glob
|
2022-02-17 20:38:09 +01:00
|
|
|
from os import environ, pathsep
|
2011-08-16 14:55:32 +02:00
|
|
|
|
2020-03-24 08:59:47 +01:00
|
|
|
from setuptools import Extension, setup
|
|
|
|
|
2022-02-17 20:38:09 +01:00
|
|
|
dconv_includes = [
|
|
|
|
dir
|
|
|
|
for dir in environ.get(
|
|
|
|
"UJSON_BUILD_DC_INCLUDES",
|
|
|
|
"./deps/double-conversion/double-conversion",
|
|
|
|
).split(pathsep)
|
|
|
|
if dir
|
|
|
|
]
|
|
|
|
dconv_libs = shlex.split(environ.get("UJSON_BUILD_DC_LIBS", ""))
|
|
|
|
dconv_source_files = []
|
|
|
|
if not dconv_libs:
|
|
|
|
dconv_source_files.extend(glob("./deps/double-conversion/double-conversion/*.cc"))
|
2020-02-29 11:26:52 +01:00
|
|
|
dconv_source_files.append("./lib/dconv_wrapper.cc")
|
2017-02-14 12:20:04 +01:00
|
|
|
|
2022-02-15 20:45:10 +01:00
|
|
|
if platform.system() == "Linux" and environ.get("UJSON_BUILD_NO_STRIP", "0") not in (
|
|
|
|
"1",
|
|
|
|
"True",
|
|
|
|
):
|
|
|
|
strip_flags = ["-Wl,--strip-all"]
|
|
|
|
else:
|
|
|
|
strip_flags = []
|
2021-12-16 23:38:12 +01:00
|
|
|
|
2017-02-14 12:20:04 +01:00
|
|
|
module1 = Extension(
|
2020-02-23 20:33:39 +01:00
|
|
|
"ujson",
|
2020-02-29 11:26:52 +01:00
|
|
|
sources=dconv_source_files
|
|
|
|
+ [
|
2020-02-23 20:33:39 +01:00
|
|
|
"./python/ujson.c",
|
|
|
|
"./python/objToJSON.c",
|
|
|
|
"./python/JSONtoObj.c",
|
|
|
|
"./lib/ultrajsonenc.c",
|
|
|
|
"./lib/ultrajsondec.c",
|
|
|
|
],
|
2022-02-17 20:38:09 +01:00
|
|
|
include_dirs=["./python", "./lib"] + dconv_includes,
|
2020-02-23 20:33:39 +01:00
|
|
|
extra_compile_args=["-D_GNU_SOURCE"],
|
2022-02-17 20:38:09 +01:00
|
|
|
extra_link_args=["-lstdc++", "-lm"] + dconv_libs + strip_flags,
|
2017-02-14 12:20:04 +01:00
|
|
|
)
|
|
|
|
|
2020-02-26 17:37:41 +01:00
|
|
|
with open("python/version_template.h") as f:
|
|
|
|
version_template = f.read()
|
|
|
|
|
|
|
|
|
|
|
|
def local_scheme(version):
|
|
|
|
"""Skip the local version (eg. +xyz of 0.6.1.dev4+gdf99fe2)
|
|
|
|
to be able to upload to Test PyPI"""
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
2017-02-14 12:20:04 +01:00
|
|
|
setup(
|
2020-02-23 20:33:39 +01:00
|
|
|
ext_modules=[module1],
|
2020-02-26 17:37:41 +01:00
|
|
|
use_scm_version={
|
|
|
|
"local_scheme": local_scheme,
|
|
|
|
"write_to": "python/version.h",
|
|
|
|
"write_to_template": version_template,
|
|
|
|
},
|
2017-02-14 12:20:04 +01:00
|
|
|
)
|