putils
¶
Platform specific helpers to manage locating native dynamic libraries.
This module hosts features similar to https://github.com/rdotnet/dynamic-interop-dll/blob/main/DynamicInterop/PlatformUtility.cs
Functions:
-
augment_path_env
–Build a new list of directory paths, prepending prior to an existing env var with paths.
-
build_new_path_env
–Propose an update to an existing environment variable, based on the path(s) specified in another environment variable. This function is effectively meant to be useful on Windows only.
-
find_full_path
–Find the full path of a library in under the python.
-
library_short_filename
–Based on the library name, return the platform-specific expected library short file name.
-
update_path_windows
–If called on Windows, append an environment variable, based on the path(s) specified in another environment variable. This function is effectively meant to be useful on Windows only.
augment_path_env
¶
augment_path_env(
added_paths: Union[str, List[str]],
subfolder: Optional[str] = None,
to_env: str = "PATH",
prepend: bool = False,
) -> str
Build a new list of directory paths, prepending prior to an existing env var with paths.
New paths are prepended only if they do already exist.
Parameters:
-
added_paths
(Union[str, List[str]]
) –paths prepended
-
subfolder
(str
, default:None
) –Optional subfolder name to append to each in path prepended. Useful for 64/32 bits variations. Defaults to None.
-
to_env
(str
, default:'PATH'
) –Environment variable with existing Paths to start with. Defaults to 'PATH'.
Returns:
-
str
(str
) –Content (set of paths), typically for a updating/setting an environment variable
Source code in src/refcount/putils.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
build_new_path_env
¶
build_new_path_env(
from_env: str = "LIBRARY_PATH",
to_env: str = "PATH",
platform: Optional[str] = None,
) -> str
Propose an update to an existing environment variable, based on the path(s) specified in another environment variable. This function is effectively meant to be useful on Windows only.
Parameters:
-
from_env
(str
, default:'LIBRARY_PATH'
) –name of the source environment variable specifying the location(s) of custom libraries to load. Defaults to 'LIBRARY_PATH'.
-
to_env
(str
, default:'PATH'
) –environment variable to update, most likely the Windows PATH env var. Defaults to 'PATH'.
Returns:
-
str
(str
) –the proposed updated content for the 'to_env' environment variable.
Source code in src/refcount/putils.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
find_full_path
¶
Find the full path of a library in under the python.
installation directory, or as devised by ctypes.find_library
Parameters:
-
name
(str
) –Library name, e.g. 'R' for the R programming language.
Returns:
Examples:
>>> from refcount.putils import *
>>> find_full_path("gfortran")
'/home/xxxyyy/anaconda3/envs/wqml/lib/libgfortran.so'
>>> find_full_path("R")
'libR.so'
Source code in src/refcount/putils.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
library_short_filename
¶
Based on the library name, return the platform-specific expected library short file name.
Parameters:
-
library_name
(str
) –name of the library, for instance 'R', which results out of this function as 'libR.so' on Linux and 'R.dll' on Windows
Raises:
-
ValueError
–invalid argument
Returns:
-
str
(str
) –expected short file name for the library, for this platform
Source code in src/refcount/putils.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
update_path_windows
¶
If called on Windows, append an environment variable, based on the path(s) specified in another environment variable. This function is effectively meant to be useful on Windows only.
Parameters:
-
from_env
(str
, default:'LIBRARY_PATH'
) –name of the source environment variable specifying the location(s) of custom libraries to load. Defaults to 'LIBRARY_PATH'.
-
to_env
(str
, default:'PATH'
) –environment variable to update, most likely the Windows PATH env var. Defaults to 'PATH'.
Returns:
-
None
–None
Source code in src/refcount/putils.py
231 232 233 234 235 236 237 238 239 240 241 242 |
|