Debian Codegraph @

README.md

raw
1 # findlibs
2
3 A Python package that searches for shared libraries on various platforms.
4
5
6 ## Usage
7
8 ```python
9 import findlibs
10 lib = findlibs.find("eccodes")
11
12 # If package name differs from library name use:
13 lib = findlibs.find(lib_name="odccore", pkg_name="odc")
14 ```
15
16 ## Installation
17
18 ```bash
19 pip install findlibs
20 ```
21
22 ## Testing
23
24 ```bash
25 git clone https://github.com/ecmwf/findlibs
26 cd findlibs
27 pip install -e ".[test]"
28 pytest
29 ```
30
31 ## find
32
33 The module only contains the `find()` function.
34
35 ```python
36 def find(lib_name, pkg_name=None)
37 ```
38
39 Returns the path to the selected library, or None if not found.
40
41 **Arguments**:
42
43 - `lib_name` _str_ - Library name without the `lib` prefix. The name of the library to find is formed using `lib_name` and a platform specific suffix (by default ".so"). E.g. when `lib_name` is "eccodes" the library name will be "libeccodes.so" on Linux and "libeccodes.dylib" on macOS.
44 - `pkg_name` _str, optional_ - Package name if it differs from the library name.
45
46
47 **Returns**:
48
49 str or None: Path to selected library
50
51 The **algorithm** to find the library is as follows:
52
53 - First, tries to find the library in an installed python module package
54 with the given name, e.g. eccodeslib, eckitlib. Disable this search
55 option by setting environment variable `FINDLIBS_DISABLE_PACKAGE=yes`.
56
57 - Next, tries the `lib` and `lib64` directories under `sys.prefix` and `$CONDA_PREFIX`. Disable this search option by setting environment variable `FINDLIBS_DISABLE_PYTHON=yes`.
58
59 - Next, tries the `lib` and `lib64` directories under the paths defined by the `pkg_name + "_HOME"` and `pkg_name + "_DIR"` environment variables. Both lowercase and uppercase versions are tested. E.g. if `pkg_name` is "eccodes" it will check the paths defined by `$eccodes_dir`, `$eccodes_home`, `$ECCODES_DIR` and `$ECCODES_HOME`. Disable this search option by setting environment variable `FINDLIBS_DISABLE_HOME=yes`.
60
61 - Next, tries to load the search paths from the user defined `~/.findlibs` or `~/.config/findlibs/findlibs.conf` INI configuration files. Then for all the user defined search paths, the `lib` and `lib64` subdirectories are tried.
62
63 Please note that only one of these files can exist. The configuration file can contain multiple search paths, but no relative paths or paths to files are allowed. The file can even be completely empty or can contain no paths at all. The file format is as follows:
64
65 ```
66 [Paths]
67 /path/to/lib_directory
68 ```
69 Disable this search option by setting environment variable `FINDLIBS_DISABLE_CONFIG_PATHS=yes`.
70
71 - Next, tries the directories defined by the `$LD_LIBRARY_PATH` and `$DYLD_LIBRARY_PATH` environment variables. Disable this search option by setting environment variable `FINDLIBS_DISABLE_LD_PATH=yes`.
72
73 - Next, tries the `lib` and `lib64` directories under the following paths "/", "/usr/", "/usr/local/", "/opt/", "/opt/homebrew/" and "~/.local/". Disable this search option by setting environment variable `FINDLIBS_DISABLE_SYS=yes`.
74
75 - Finally, tries calling the `ctypes.util.find_library` function. Disable this search option by setting environment variable `FINDLIBS_DISABLE_CTYPES_UTIL=yes`.