diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py index f32fc5151e63cca44b9ba3078e6abfcb8cf4e617..8b958a4b9d7dccd1f5e37f2d1d4acf03b35800bf 100644 --- a/binarycpython/utils/functions.py +++ b/binarycpython/utils/functions.py @@ -14,6 +14,9 @@ import tempfile import copy import inspect import sys +import subprocess +import time +import types from io import StringIO from typing import Union, Any @@ -22,7 +25,6 @@ from collections import defaultdict import h5py import numpy as np - from binarycpython import _binary_c_bindings import binarycpython.utils.moe_distefano_data as moe_distefano_data @@ -36,9 +38,9 @@ def convert_bytes(size): Function to return the size + a magnitude string """ - for x in ['bytes', 'KB', 'MB', 'GB', 'TB']: + for name in ['bytes', 'KB', 'MB', 'GB', 'TB']: if size < 1024.0: - return "%3.1f %s" % (size, x) + return "%3.1f %s" % (size, name) size /= 1024.0 return size @@ -291,6 +293,34 @@ class Capturing(list): del self._stringio # free up some memory sys.stdout = self._stdout +def call_binary_c_config(argument): + """ + Function to interface with the binary_c config file + + input: + - argument: argument for the binary_c config + + Returns: + - raw output of binary_c-config + """ + + BINARY_C_DIR = os.getenv("BINARY_C", None) + if not BINARY_C_DIR: + msg = "Error: the BINARY_C environment variable is not set. Aborting" + raise ValueError(msg) + + BINARY_C_CONFIG = os.path.join(BINARY_C_DIR, "binary_c-config") + if not os.path.isfile(BINARY_C_CONFIG): + msg = "binary_c-config file does not exist. Aborting" + raise ValueError(msg) + + output = ( + subprocess.run([BINARY_C_CONFIG, argument], stdout=subprocess.PIPE, check=True) + .stdout.decode("utf-8") + ) + + return output + ######################################################## # utility functions