Commit | Line | Data |
---|---|---|
de4dee04 PP |
1 | # -*- coding: utf-8 -*- |
2 | # | |
c0c0989a | 3 | # SPDX-License-Identifier: LGPL-2.1-only |
de4dee04 | 4 | # |
c0c0989a | 5 | # Copyright (C) 2015 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> |
de4dee04 | 6 | |
a49a7e68 FD |
7 | import os |
8 | import sys | |
9 | ||
ed898ff6 MJ |
10 | if sys.version_info < (3, 12): |
11 | from distutils.core import setup, Extension | |
12 | else: | |
13 | from setuptools import setup, Extension | |
de4dee04 | 14 | |
245091df MJ |
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. | |
21 | # | |
22 | # Monkeypatch sysconfig to override this scheme and use 'posix_prefix' instead. | |
23 | if sys.version_info >= (3, 10): | |
24 | import sysconfig | |
25 | ||
26 | original_get_preferred_scheme = sysconfig.get_preferred_scheme | |
27 | ||
28 | def our_get_preferred_scheme(key): | |
29 | scheme = original_get_preferred_scheme(key) | |
30 | if scheme == "posix_local": | |
31 | return "posix_prefix" | |
32 | else: | |
33 | return scheme | |
34 | ||
35 | sysconfig.get_preferred_scheme = our_get_preferred_scheme | |
36 | ||
a49a7e68 FD |
37 | PY_PATH_WARN_MSG = """ |
38 | -------------------------------------WARNING------------------------------------ | |
39 | The install directory used:\n ({0})\nis not included in your PYTHONPATH. | |
40 | ||
41 | To add this directory to your Python search path permanently you can add the | |
42 | following command to your .bashrc/.zshrc: | |
43 | export PYTHONPATH="${{PYTHONPATH}}:{0}" | |
44 | -------------------------------------------------------------------------------- | |
45 | """ | |
46 | ||
47 | def main(): | |
48 | dist = setup(name='lttngust', | |
49 | version='@PACKAGE_VERSION@', | |
50 | description='LTTng-UST Python agent', | |
51 | packages=['lttngust'], | |
52 | package_dir={'lttngust': 'lttngust'}, | |
53 | options={'build': {'build_base': 'build'}}, | |
54 | url='http://lttng.org', | |
55 | license='LGPL-2.1', | |
56 | classifiers=[ | |
57 | 'Development Status :: 5 - Production/Stable', | |
58 | 'Intended Audience :: Developers', | |
59 | 'License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)', | |
60 | 'Programming Language :: Python :: 2.7', | |
61 | 'Programming Language :: Python :: 3' | |
62 | 'Topic :: System :: Logging', | |
63 | ]) | |
64 | ||
65 | # After the installation, we check that the install directory is included in | |
66 | # the Python search path and we print a warning message when it's not. We need | |
67 | # to do this because Python search path differs depending on the distro and | |
68 | # some distros don't include any `/usr/local/` (the default install prefix) in | |
69 | # the search path. This is also useful for out-of-tree installs and tests. It's | |
70 | # only relevant to make this check on the `install` command. | |
71 | ||
72 | if 'install' in dist.command_obj: | |
73 | install_dir = dist.command_obj['install'].install_libbase | |
74 | if install_dir not in sys.path: | |
75 | # We can't consider this an error because if affects every | |
76 | # distro differently. We only warn the user that some | |
77 | # extra configuration is needed to use the agent | |
78 | abs_install_dir = os.path.abspath(install_dir) | |
79 | print(PY_PATH_WARN_MSG.format(abs_install_dir)) | |
f92d03ee | 80 | |
a49a7e68 FD |
81 | if __name__ == '__main__': |
82 | main() |