File: python_install_path.py

package info (click to toggle)
ros2-colcon-core 0.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,156 kB
  • sloc: python: 10,333; makefile: 7
file content (38 lines) | stat: -rw-r--r-- 1,543 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Copyright 2022 Open Source Robotics Foundation, Inc.
# Licensed under the Apache License, Version 2.0

from pathlib import Path
import sysconfig


def get_python_install_path(name, vars_=()):
    """
    Get Python install paths matching Colcon's preferred scheme.

    See sysconfig.get_path for more info about the arguments.

    :param name: Name of the path type
    :param vars_: A dictionary of variables updating the values of
        sysconfig.get_config_vars()
    :rtype: Pathlib.Path
    """
    kwargs = {}
    kwargs['vars'] = dict(vars_)

    install_base = kwargs['vars'].get('base', sysconfig.get_config_var('base'))
    if install_base != sysconfig.get_config_var('base'):
        # If we are not actually installing to /usr, the default path scheme
        # may be inadequate. Check if we need to override.
        schemes = sysconfig.get_scheme_names()
        if 'deb_system' in schemes or 'osx_framework_library' in schemes:
            # Avoid deb_system because it requires using --install-layout deb
            # which ignores --prefix and hardcodes it to /usr
            kwargs['scheme'] = 'posix_prefix'
        elif 'rpm_prefix' in schemes:
            # The presence of the rpm_prefix scheme indicates that posix_prefix
            # has been patched to inject `local` into the installation
            # locations. The rpm_prefix scheme is a backup of what posix_prefix
            # was before it was patched.
            kwargs['scheme'] = 'rpm_prefix'

    return Path(sysconfig.get_path(name, **kwargs))