Example #1
0
    def create_environment_hooks(self, prefix_path, pkg_name):  # noqa: D102
        hooks = OrderedDict()

        logger.log(1, "checking '%s' for CMake module files" % prefix_path)
        for path in self._get_potential_cmake_module_paths(
                prefix_path, pkg_name):
            if not path.is_dir():
                continue
            # skip paths which are the same but only differ in case
            if any(path.samefile(p) for p in hooks.keys()):
                continue

            for filename in path.iterdir():
                if not filename.is_file():
                    continue
                if (filename.name.startswith('Find')
                        and filename.name.endswith('.cmake')):
                    hooks[path] = create_environment_hook(
                        'cmake_module_path' +
                        (str(len(hooks)) if hooks else ''),
                        prefix_path,
                        pkg_name,
                        'CMAKE_MODULE_PATH',
                        str(path.relative_to(prefix_path)),
                        mode='prepend')

        return hooks.values()
Example #2
0
    def create_environment_hooks(self, prefix_path, pkg_name):  # noqa: D102
        LibraryDescriptor = namedtuple(
            'LibraryDescriptor',
            ['hook_name', 'subdirectory', 'extension', 'environment_variable'])

        if sys.platform == 'win32':
            library_descriptors = [
                LibraryDescriptor('path_dll', 'bin', 'dll', 'PATH')
            ]
        elif platform.system() == 'Darwin':
            library_descriptors = [
                LibraryDescriptor(
                    'dyld_library_path', 'lib', 'dylib', 'DYLD_LIBRARY_PATH')]
        else:
            library_descriptors = [
                LibraryDescriptor(
                    'ld_library_path_{directory.name}'.format_map(locals()),
                    directory.name, 'so', 'LD_LIBRARY_PATH')
                for directory in prefix_path.glob('lib*')]

        environment_hooks = []
        for library_descriptor in library_descriptors:
            library_path = prefix_path / library_descriptor.subdirectory
            logger.log(1, "checking '%s'" % library_path)

            if any(library_path.glob('*.' + library_descriptor.extension)):
                environment_hooks += create_environment_hook(
                    library_descriptor.hook_name,
                    prefix_path, pkg_name,
                    library_descriptor.environment_variable,
                    library_descriptor.subdirectory, mode='prepend')

        return environment_hooks
Example #3
0
 def create_environment_hooks(self, prefix_path, pkg_name):  # noqa: D102
     subdirectory = Path('lib') / 'pkgconfig'
     pkg_config_file = prefix_path / subdirectory / (pkg_name + '.pc')
     logger.log(1, "checking '%s'" % pkg_config_file)
     if not pkg_config_file.is_file():
         return []
     return create_environment_hook('pkg_config',
                                    prefix_path,
                                    pkg_name,
                                    'PKG_CONFIG_PATH',
                                    str(subdirectory),
                                    mode='prepend')
Example #4
0
    def create_environment_hooks(self, prefix_path, pkg_name):  # noqa: D102
        hooks = []

        python_path = Path(get_python_lib(prefix=str(prefix_path)))
        logger.log(1, "checking '%s'" % python_path)
        if python_path.exists():
            rel_python_path = python_path.relative_to(prefix_path)
            hooks += shell.create_environment_hook(
                'pythonpath', prefix_path, pkg_name,
                'PYTHONPATH', str(rel_python_path), mode='prepend')

        return hooks
Example #5
0
    def create_environment_hooks(self, prefix_path: Path,
                                 pkg_name: str):  # noqa D102
        hooks = []
        dub_path = prefix_path / 'lib' / 'dub' / pkg_name
        dub_package = DubPackage.load(dub_path)
        logger.log(1, "checking '%s'" % dub_path)

        if dub_package:
            hooks += shell.create_environment_hook('dub_package_path',
                                                   prefix_path,
                                                   pkg_name,
                                                   DUB_PACKAGE_PATH_ENV,
                                                   str(dub_package.path),
                                                   mode='prepend')

        return hooks
    def create_environment_hooks(self, prefix_path, pkg_name):  # noqa: D102
        hooks = []

        logger.log(1, "checking '%s' for CMake config files" % prefix_path)
        for _, _, filenames in os.walk(str(prefix_path)):
            for filename in filenames:
                if filename.endswith('-config.cmake') or \
                        filename.endswith('Config.cmake'):
                    hooks += create_environment_hook(
                        'cmake_prefix_path', prefix_path, pkg_name,
                        'CMAKE_PREFIX_PATH', '', mode='prepend')
                    break
            else:
                continue
            break

        return hooks
Example #7
0
    def _create_environment_hooks(
        self, prefix_path, pkg_name, subdirectory, suffix=''
    ):
        hooks = []
        bin_path = prefix_path / subdirectory
        logger.log(1, "checking '%s'" % bin_path)
        try:
            names = os.listdir(str(bin_path))
        except FileNotFoundError:
            pass
        else:
            for name in names:
                if not (bin_path / name).is_file():
                    continue
                hooks += shell.create_environment_hook(
                    'path' + suffix, prefix_path, pkg_name, 'PATH',
                    subdirectory, mode='prepend')
                break

        return hooks