biocrnpyler.utils.fileutil

Functions

find_file_in_bcp_path(filename[, env_var_name])

Find a file by searching through biocrnpyler paths.

biocrnpyler.utils.fileutil.find_file_in_bcp_path(filename: str, env_var_name: str = 'BCP_PATH') str | None[source]

Find a file by searching through biocrnpyler paths.

Searches for a file in multiple locations in the following order:

  1. Current working directory

  2. Directories specified in environment variable (default: ‘BCP_PATH’)

  3. biocrnpyler package directory

The environment variable should contain a colon-separated (Unix) or semicolon-separated (Windows) list of directory paths.

Parameters:
filenamestr

Name of file to find.

env_var_namestr, default=’BCP_PATH’

Name of environment variable containing search paths.

Returns:
str or None

Full path to file if found, None otherwise.

Examples

Set environment variable and find a file:

>>> import os
>>> os.environ['BCP_PATH'] = '/path/to/models:/path/to/configs'
>>> filepath = find_file_in_bcp_path('model.xml')
>>> if filepath:
...     print(f'Found file at: {filepath}')
... else:
...     print('File not found')
Found file at: /path/to/models/model.xml

Search with a custom environment variable:

>>> filepath = find_file_in_bcp_path(
...     'parameters.csv', env_var_name='MY_PARAMS_PATH')