1 # SPDX-License-Identifier: MIT
3 # Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
4 # Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 # Distutils was removed in Python 3.12, use setuptools as an alternative.
10 if sys
.version_info
>= (3, 12):
11 from setuptools
import setup
, Extension
13 from distutils
.core
import setup
, Extension
15 # Starting with Debian's Python 3.10, the default install scheme is
16 # 'posix_local' which is a Debian specific scheme based on 'posix_prefix' but
17 # with an added 'local' prefix. This is the default so users doing system wide
18 # manual installations of python modules end up in '/usr/local'. This
19 # interferes with our autotools based install which already defaults to
20 # '/usr/local' and expect a provided prefix to be used verbatim.
22 # Monkeypatch sysconfig to override this scheme and use 'posix_prefix' instead.
23 if sys
.version_info
>= (3, 10):
26 original_get_preferred_scheme
= sysconfig
.get_preferred_scheme
28 def our_get_preferred_scheme(key
):
29 scheme
= original_get_preferred_scheme(key
)
30 if scheme
== "posix_local":
35 sysconfig
.get_preferred_scheme
= our_get_preferred_scheme
38 import distutils
.sysconfig
as sysconfig
40 PY_PATH_WARN_MSG
= """
41 -------------------------------------WARNING------------------------------------
42 The install directory used:\n ({})\nis not included in your PYTHONPATH.
44 To add this directory to your Python search path permanently you can add the
45 following command to your .bashrc/.zshrc:
46 export PYTHONPATH="${{PYTHONPATH}}:{}"
47 --------------------------------------------------------------------------------
50 original_get_config_vars
= sysconfig
.get_config_vars
54 cflags
= os
.environ
.get("CFLAGS")
57 [cflags
] = original_get_config_vars("CFLAGS")
62 # distutils performs a similar transformation step on LDSHARED on
63 # darwin to use the overridden CC as the default command for LDSHARED
64 # (see distutils' customize_compiler() step in the sysconfig module).
66 # This takes it a step further by using our own LDFLAGS (when available)
67 # along with the overridden compiler and ensure that flags that are unsupported
68 # by either the Python interprter's CC or the overridden CC don't cause a
71 cc
= os
.environ
.get("CC")
72 ldflags
= os
.environ
.get("LDFLAGS")
73 [py_cc
] = original_get_config_vars("CC")
74 [py_ldshared
] = original_get_config_vars("LDSHARED")
76 if not py_ldshared
.startswith(py_cc
):
80 return "{} -shared {}".format(cc
, ldflags
)
82 return cc
+ py_ldshared
[len(py_cc
) :]
84 return py_cc
+ py_ldshared
[len(py_cc
) :]
89 def our_get_config_vars(*args
):
90 overridden_config_vars_funcs
= {
92 "LDSHARED": get_ldshared
,
96 # Return a dict with all config vars.
97 all_config_vars
= original_get_config_vars()
98 for name
in overridden_config_vars_funcs
:
99 all_config_vars
[name
] = overridden_config_vars_funcs
[name
]()
101 return all_config_vars
103 # Return a list with the requested config vars.
104 subset_config_vars
= []
106 if name
in overridden_config_vars_funcs
:
107 subset_config_vars
.append(overridden_config_vars_funcs
[name
]())
109 subset_config_vars
.append(original_get_config_vars(name
)[0])
111 return subset_config_vars
114 sysconfig
.get_config_vars
= our_get_config_vars
118 babeltrace_ext
= Extension(
120 sources
=["bt2/native_bt.c", "@srcdir@/bt2/logging.c"],
121 libraries
=["babeltrace2", "glib-2.0"],
123 "@top_builddir@/src/autodisc/.libs/libautodisc.a",
124 "@top_builddir@/src/logging/.libs/liblogging.a",
125 "@top_builddir@/src/common/.libs/libcommon.a",
126 "@top_builddir@/src/py-common/.libs/libpy-common.a",
127 "@top_builddir@/src/string-format/.libs/libstring-format.a",
133 version
="@PACKAGE_VERSION@",
134 description
="Babeltrace 2 Python Bindings",
136 package_dir
={"bt2": "bt2"},
138 "build": {"build_base": "build", "build_lib": "build/build_lib"},
139 "build_ext": {"build_lib": "build/build_lib"},
141 url
="https://babeltrace.org/",
142 ext_modules
=[babeltrace_ext
],
145 "Development Status :: 5 - Production/Stable",
146 "Intended Audience :: Developers",
147 "License :: OSI Approved :: The MIT License",
148 "Programming Language :: Python :: 3" "Topic :: System :: Logging",
152 # After the installation, we check that the install directory is included in
153 # the Python search path and we print a warning message when it's not.
154 # We need to do this because Python search path differs depending on the distro
155 # and some distros don't include any /usr/local/ in the search path. This is
156 # also useful for out-of-tree installs and tests.
157 # It's only relevant to make this check on the `install` command.
159 if "install" in dist
.command_obj
:
160 install_dir
= dist
.command_obj
["install"].install_libbase
161 if install_dir
not in sys
.path
:
162 # We can't consider this an error because if affects every
163 # distro differently. We only warn the user that some
164 # extra configuration is needed to use the bindings
165 print(PY_PATH_WARN_MSG
.format(install_dir
, install_dir
))
168 if __name__
== "__main__":