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 overriden 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 overriden compiler and ensure that flags that are unsupported
68 # by either the Python interprter's CC or the overriden 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
= {
91 "CFLAGS": get_cflags(),
92 "LDSHARED": get_ldshared(),
96 all_config_vars
= original_get_config_vars()
97 for name
in overridden_config_vars
:
98 all_config_vars
[name
] = overridden_config_vars
[name
]
99 return all_config_vars
101 subset_config_vars
= []
103 if name
not in overridden_config_vars
:
104 [var
] = original_get_config_vars(name
)
105 subset_config_vars
.append(var
)
108 subset_config_vars
.append(overridden_config_vars
[name
])
110 return subset_config_vars
113 sysconfig
.get_config_vars
= our_get_config_vars
117 babeltrace_ext
= Extension(
119 sources
=["bt2/native_bt.c", "@srcdir@/bt2/logging.c"],
120 libraries
=["babeltrace2", "glib-2.0"],
122 "@top_builddir@/src/autodisc/.libs/libautodisc.a",
123 "@top_builddir@/src/logging/.libs/liblogging.a",
124 "@top_builddir@/src/common/.libs/libcommon.a",
125 "@top_builddir@/src/py-common/.libs/libpy-common.a",
126 "@top_builddir@/src/string-format/.libs/libstring-format.a",
132 version
="@PACKAGE_VERSION@",
133 description
="Babeltrace 2 Python Bindings",
135 package_dir
={"bt2": "bt2"},
137 "build": {"build_base": "build", "build_lib": "build/build_lib"},
138 "build_ext": {"build_lib": "build/build_lib"},
140 url
="https://babeltrace.org/",
141 ext_modules
=[babeltrace_ext
],
144 "Development Status :: 5 - Production/Stable",
145 "Intended Audience :: Developers",
146 "License :: OSI Approved :: The MIT License",
147 "Programming Language :: Python :: 3" "Topic :: System :: Logging",
151 # After the installation, we check that the install directory is included in
152 # the Python search path and we print a warning message when it's not.
153 # We need to do this because Python search path differs depending on the distro
154 # and some distros don't include any /usr/local/ in the search path. This is
155 # also useful for out-of-tree installs and tests.
156 # It's only relevant to make this check on the `install` command.
158 if "install" in dist
.command_obj
:
159 install_dir
= dist
.command_obj
["install"].install_libbase
160 if install_dir
not in sys
.path
:
161 # We can't consider this an error because if affects every
162 # distro differently. We only warn the user that some
163 # extra configuration is needed to use the bindings
164 print(PY_PATH_WARN_MSG
.format(install_dir
, install_dir
))
167 if __name__
== "__main__":