From a251a28fc2c8a97a75e83d1d96d779c39fe06575 Mon Sep 17 00:00:00 2001
From: David Hendriks <davidhendriks93@gmail.com>
Date: Sun, 25 Jul 2021 14:49:21 +0100
Subject: [PATCH] updated code to interface with binary c config

---
 binarycpython/utils/functions.py | 36 +++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py
index f32fc5151..8b958a4b9 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
-- 
GitLab