Platform utilities¶
Functions that may be useful in your packages to locate and load native shared libraries.
Platform specific helpers to manage locating native dynamic libraries
This module hosts features similar to https://github.com/rdotnet/dynamic-interop-dll/blob/master/DynamicInterop/PlatformUtility.cs
augment_path_env(added_paths, subfolder=None, to_env='PATH', prepend=False)
¶
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:
Name | Type | Description | Default |
---|---|---|---|
added_paths |
Union[str, List[str]]
|
paths prepended |
required |
subfolder |
str
|
Optional subfolder name to append to each in path prepended. Useful for 64/32 bits variations. Defaults to None. |
None
|
to_env |
str
|
Environment variable with existing Paths to start with. Defaults to 'PATH'. |
'PATH'
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Content (set of paths), typically for a updating/setting an environment variable |
Source code in refcount/putils.py
build_new_path_env(from_env='LIBRARY_PATH', to_env='PATH', platform=None)
¶
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:
Name | Type | Description | Default |
---|---|---|---|
from_env |
str
|
name of the source environment variable specifying the location(s) of custom libraries to load. Defaults to 'LIBRARY_PATH'. |
'LIBRARY_PATH'
|
to_env |
str
|
environment variable to update, most likely the Windows PATH env var. Defaults to 'PATH'. |
'PATH'
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the proposed updated content for the 'to_env' environment variable. |
Source code in refcount/putils.py
find_full_path(name, prefix=None)
¶
Find the full path of a library in under the python installation directory, or as devised by ctypes.find_library
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Library name, e.g. 'R' for the R programming language. |
required |
Returns:
Type | Description |
---|---|
Union[str, None]
|
Union[str, None]: First suitable library full file name. |
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 refcount/putils.py
library_short_filename(library_name, platform=None)
¶
Based on the library name, return the platform-specific expected library short file name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
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 |
required |
Raises:
Type | Description |
---|---|
ValueError
|
invalid argument |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
expected short file name for the library, for this platform |
Source code in refcount/putils.py
update_path_windows(from_env='LIBRARY_PATH', to_env='PATH')
¶
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:
Name | Type | Description | Default |
---|---|---|---|
from_env |
str
|
name of the source environment variable specifying the location(s) of custom libraries to load. Defaults to 'LIBRARY_PATH'. |
'LIBRARY_PATH'
|
to_env |
str
|
environment variable to update, most likely the Windows PATH env var. Defaults to 'PATH'. |
'PATH'
|
Returns:
Type | Description |
---|---|
None
|
None |