Remove `skip-string-normalization` in Python formatter config
[babeltrace.git] / src / bindings / python / bt2 / setup.py.in
CommitLineData
0235b0db 1# SPDX-License-Identifier: MIT
1b8fb862 2#
0235b0db
MJ
3# Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
4# Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
1b8fb862
MJ
5
6import sys
afdd1f82
JG
7import os
8import distutils.sysconfig
1b8fb862
MJ
9
10from distutils.core import setup, Extension
11
12PY_PATH_WARN_MSG = """
13-------------------------------------WARNING------------------------------------
14The install directory used:\n ({})\nis not included in your PYTHONPATH.
15
16To add this directory to your Python search path permanently you can add the
17following command to your .bashrc/.zshrc:
18 export PYTHONPATH="${{PYTHONPATH}}:{}"
19--------------------------------------------------------------------------------
20"""
21
afdd1f82
JG
22original_get_config_vars = distutils.sysconfig.get_config_vars
23
24
25def get_cflags():
f5567ea8 26 cflags = os.environ.get("CFLAGS")
afdd1f82
JG
27
28 if cflags is None:
f5567ea8 29 [cflags] = original_get_config_vars("CFLAGS")
afdd1f82
JG
30
31 return cflags
32
33
34# distutils performs a similar transformation step on LDSHARED on
35# darwin to use the overriden CC as the default command for LDSHARED
36# (see distutils' customize_compiler() step in the sysconfig module).
37#
38# This takes it a step further by using our own LDFLAGS (when available)
39# along with the overriden compiler and ensure that flags that are unsupported
40# by either the Python interprter's CC or the overriden CC don't cause a
41# build failure.
42def get_ldshared():
f5567ea8
FD
43 cc = os.environ.get("CC")
44 ldflags = os.environ.get("LDFLAGS")
45 [py_cc] = original_get_config_vars("CC")
46 [py_ldshared] = original_get_config_vars("LDSHARED")
afdd1f82
JG
47
48 if not py_ldshared.startswith(py_cc):
49 return py_ldshared
50
51 if cc and ldflags:
f5567ea8 52 return "{} -shared {}".format(cc, ldflags)
afdd1f82
JG
53 elif cc:
54 return cc + py_ldshared[len(py_cc) :]
55 elif ldflags:
56 return py_cc + py_ldshared[len(py_cc) :]
57 else:
58 return py_ldshared
59
60
61def our_get_config_vars(*args):
62 overridden_config_vars = {
f5567ea8
FD
63 "CFLAGS": get_cflags(),
64 "LDSHARED": get_ldshared(),
afdd1f82
JG
65 }
66
67 if len(args) == 0:
68 all_config_vars = original_get_config_vars()
69 for name in overridden_config_vars:
70 all_config_vars[name] = overridden_config_vars[name]
71 return all_config_vars
72
73 subset_config_vars = []
74 for name in args:
75 if name not in overridden_config_vars:
76 [var] = original_get_config_vars(name)
77 subset_config_vars.append(var)
78 continue
79
80 subset_config_vars.append(overridden_config_vars[name])
81
82 return subset_config_vars
83
84
85distutils.sysconfig.get_config_vars = our_get_config_vars
86
cfbd7cf3 87
1b8fb862 88def main():
cfbd7cf3 89 babeltrace_ext = Extension(
f5567ea8
FD
90 "bt2._native_bt",
91 sources=["bt2/native_bt.c", "@srcdir@/bt2/logging.c"],
92 libraries=["babeltrace2", "glib-2.0"],
cfbd7cf3 93 extra_objects=[
f5567ea8
FD
94 "@top_builddir@/src/autodisc/.libs/libbabeltrace2-autodisc.a",
95 "@top_builddir@/src/logging/.libs/libbabeltrace2-logging.a",
96 "@top_builddir@/src/common/.libs/libbabeltrace2-common.a",
97 "@top_builddir@/src/py-common/.libs/libbabeltrace2-py-common.a",
98 "@top_builddir@/src/string-format/.libs/libbabeltrace2-string-format.a",
cfbd7cf3
FD
99 ],
100 )
1b8fb862 101
cfbd7cf3 102 dist = setup(
f5567ea8
FD
103 name="bt2",
104 version="@PACKAGE_VERSION@",
105 description="Babeltrace 2 Python Bindings",
106 packages=["bt2"],
107 package_dir={"bt2": "bt2"},
cfbd7cf3 108 options={
f5567ea8
FD
109 "build": {"build_base": "build", "build_lib": "build/build_lib"},
110 "build_ext": {"build_lib": "build/build_lib"},
cfbd7cf3 111 },
f5567ea8 112 url="https://babeltrace.org/",
cfbd7cf3 113 ext_modules=[babeltrace_ext],
f5567ea8 114 license="MIT",
cfbd7cf3 115 classifiers=[
f5567ea8
FD
116 "Development Status :: 5 - Production/Stable",
117 "Intended Audience :: Developers",
118 "License :: OSI Approved :: The MIT License",
119 "Programming Language :: Python :: 3" "Topic :: System :: Logging",
cfbd7cf3
FD
120 ],
121 )
1b8fb862 122
cfbd7cf3
FD
123 # After the installation, we check that the install directory is included in
124 # the Python search path and we print a warning message when it's not.
125 # We need to do this because Python search path differs depending on the distro
126 # and some distros don't include any /usr/local/ in the search path. This is
127 # also useful for out-of-tree installs and tests.
128 # It's only relevant to make this check on the `install` command.
1b8fb862 129
f5567ea8
FD
130 if "install" in dist.command_obj:
131 install_dir = dist.command_obj["install"].install_libbase
1b8fb862
MJ
132 if install_dir not in sys.path:
133 # We can't consider this an error because if affects every
134 # distro differently. We only warn the user that some
135 # extra configuration is needed to use the bindings
136 print(PY_PATH_WARN_MSG.format(install_dir, install_dir))
137
cfbd7cf3 138
1b8fb862
MJ
139if __name__ == "__main__":
140 main()
This page took 0.067684 seconds and 4 git commands to generate.