From 88bc300104c753b8ef48d306b0e37aa04aaf6ee6 Mon Sep 17 00:00:00 2001
From: David Hendriks <davidhendriks93@gmail.com>
Date: Fri, 17 Jan 2020 15:25:24 +0000
Subject: [PATCH] executed black formatting on the code

---
 .../utils/custom_logging_functions.py         | 17 ++++----
 binarycpython/utils/functions.py              | 27 ++++++------
 binarycpython/utils/grid.py                   | 28 ++++++-------
 binarycpython/utils/grid_options_defaults.py  |  2 +-
 examples/examples.py                          | 11 ++++-
 examples/examples_custom_logging.py           | 41 ++++++++++++++-----
 tests/population/grid_tests.py                |  8 ++--
 tests/python_API_test.py                      |  4 +-
 tests/random_tests.py                         |  4 +-
 9 files changed, 86 insertions(+), 56 deletions(-)

diff --git a/binarycpython/utils/custom_logging_functions.py b/binarycpython/utils/custom_logging_functions.py
index 54bd02b65..06910af44 100644
--- a/binarycpython/utils/custom_logging_functions.py
+++ b/binarycpython/utils/custom_logging_functions.py
@@ -7,6 +7,7 @@ import ctypes
 import random
 import uuid
 
+
 def autogen_C_logging_code(logging_dict):
     """
     Function that autogenerates PRINTF statements for binaryc. intput is a dictionary where the key is the header of that logging line and items which are lists of parameters\
@@ -234,7 +235,7 @@ def compile_shared_lib(code, sourcefile_name, outfile_name, verbose=False):
     # Remove the library if present:
     if os.path.exists(outfile_name):
         try:
-            print('removing' ,outfile_name)
+            print("removing", outfile_name)
             os.remove(outfile_name)
         except:
             print("Error while deleting file {}".format(outfile_name))
@@ -242,7 +243,6 @@ def compile_shared_lib(code, sourcefile_name, outfile_name, verbose=False):
     # create compilation command
     compilation_dict = return_compilation_dict()
 
-
     # Construct full command
     command = "{cc} {ccflags} {libs} -o {outfile_name} {sourcefile_name} {inc}".format(
         cc=compilation_dict["cc"],
@@ -292,9 +292,10 @@ def create_and_load_logging_function(custom_logging_code):
 
     #
 
+    library_name = os.path.join(
+        temp_custom_logging_dir(), "libcustom_logging_{}.so".format(uuid.uuid4().hex)
+    )
 
-    library_name = os.path.join(temp_custom_logging_dir(), "libcustom_logging_{}.so".format(uuid.uuid4().hex))
-    
     compile_shared_lib(
         custom_logging_code,
         sourcefile_name=os.path.join(temp_custom_logging_dir(), "custom_logging.c"),
@@ -308,11 +309,13 @@ def create_and_load_logging_function(custom_logging_code):
     dll1 = ctypes.CDLL("libgslcblas.so", mode=ctypes.RTLD_GLOBAL)
     dll2 = ctypes.CDLL("libgsl.so", mode=ctypes.RTLD_GLOBAL)
     dll3 = ctypes.CDLL("libbinary_c.so", mode=ctypes.RTLD_GLOBAL)
-    libcustom_logging = ctypes.CDLL(library_name,
-        mode=ctypes.RTLD_GLOBAL,
+    libcustom_logging = ctypes.CDLL(
+        library_name, mode=ctypes.RTLD_GLOBAL,
     )  # loads the shared library
 
     # Get memory adress of function. mimicking a pointer
-    func_memaddr = ctypes.cast(libcustom_logging.custom_output_function, ctypes.c_void_p).value
+    func_memaddr = ctypes.cast(
+        libcustom_logging.custom_output_function, ctypes.c_void_p
+    ).value
 
     return func_memaddr
diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py
index 756401682..91700951b 100644
--- a/binarycpython/utils/functions.py
+++ b/binarycpython/utils/functions.py
@@ -7,6 +7,7 @@ from binarycpython.utils.custom_logging_functions import (
     create_and_load_logging_function,
 )
 
+
 def get_help_super(print_help=False, return_dict=True):
     """
     Function that first runs get_help_all, and then per argument also run the help function to get as much information as possible.
@@ -14,35 +15,34 @@ def get_help_super(print_help=False, return_dict=True):
 
     help_all_dict = get_help_all(print_help=False, return_dict=True)
 
-
     # print(help_all_dict)
 
     # print(json.dumps(help_all_dict, indent=4))
 
     help_all_super_dict = help_all_dict.copy()
 
-
     for section_name in help_all_dict.keys():
         section = help_all_dict[section_name]
 
         # print(section)
-        for parameter_name in section['parameters'].keys():
-            parameter = section['parameters'][parameter_name]
+        for parameter_name in section["parameters"].keys():
+            parameter = section["parameters"][parameter_name]
 
-            detailed_help = get_help(parameter_name, print_help=False, return_dict=True, fail_silently=True)
+            detailed_help = get_help(
+                parameter_name, print_help=False, return_dict=True, fail_silently=True
+            )
 
-            parameter['detailed_help'] = detailed_help
+            parameter["detailed_help"] = detailed_help
 
-            if parameter['detailed_help']:
-                if not parameter['description']==parameter['detailed_help']['description']:
+            if parameter["detailed_help"]:
+                if (
+                    not parameter["description"]
+                    == parameter["detailed_help"]["description"]
+                ):
                     print(json.dumps(parameter, indent=4))
 
-
             # print(parameter['description']==parameter['detailed_help']['description'])
 
-
-
-
             # print(parameter.keys())
 
     if print_help:
@@ -51,8 +51,7 @@ def get_help_super(print_help=False, return_dict=True):
         pass
 
     if return_dict:
-        return 
-
+        return
 
 
 def get_help_all(print_help=True, return_dict=False):
diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py
index 13b5654f7..eb8a6dc1d 100644
--- a/binarycpython/utils/grid.py
+++ b/binarycpython/utils/grid.py
@@ -92,10 +92,13 @@ class Population(object):
                 self.grid_options[key] = kwargs[key]
             # The of the keys go into a custom_options dict
             else:
-                print("!! Key doesnt match previously known parameter: adding: {}={} to custom_options".format(key, kwargs[key]))
+                print(
+                    "!! Key doesnt match previously known parameter: adding: {}={} to custom_options".format(
+                        key, kwargs[key]
+                    )
+                )
                 self.custom_options[key] = kwargs[key]
 
-
     def return_argline(self, parameter_dict=None):
         """
         Function to create the string for the arg line from a parameter dict
@@ -281,7 +284,6 @@ class Population(object):
                 "custom_logging_func_memaddr"
             ] = create_and_load_logging_function(custom_logging_code)
 
-
     ###################################################
     # Evolution functions
     ###################################################
@@ -298,7 +300,11 @@ class Population(object):
         argline = self.return_argline(self.bse_options)
 
         # Run system
-        out = binary_c_python_api.run_system(argline, self.grid_options['custom_logging_func_memaddr'], self.grid_options['store_memaddr']) # Todo: change this to run_binary again but then build in checks in binary
+        out = binary_c_python_api.run_system(
+            argline,
+            self.grid_options["custom_logging_func_memaddr"],
+            self.grid_options["store_memaddr"],
+        )  # Todo: change this to run_binary again but then build in checks in binary
 
         # TODO: add call to function that cleans up the temp customlogging dir, and unloads the loaded libraries.
 
@@ -333,18 +339,17 @@ class Population(object):
             ] = create_and_load_logging_function(custom_logging_code)
 
         ### Load store
-        self.grid_options['store_memaddr'] = binary_c_python_api.return_store("")
+        self.grid_options["store_memaddr"] = binary_c_python_api.return_store("")
 
         # Execute.
         out = binary_c_python_api.run_population(
-            self.return_argline(), 
-            self.grid_options['custom_logging_func_memaddr'], 
-            self.grid_options['store_memaddr']
+            self.return_argline(),
+            self.grid_options["custom_logging_func_memaddr"],
+            self.grid_options["store_memaddr"],
         )
 
         print(out)
 
-
         ### Arguments
         # If user inputs a file containing arg lines then use that
         if custom_arg_file:
@@ -365,10 +370,8 @@ class Population(object):
 
             pass
 
-
         quit()
 
-
         #######
         # Do stuff
         for line in population_arglines:
@@ -378,9 +381,6 @@ class Population(object):
 
         # TODO: add call to function that cleans up the temp customlogging dir, and unloads the loaded libraries.
 
-
-
-
     ###################################################
     # Testing functions
     ###################################################
diff --git a/binarycpython/utils/grid_options_defaults.py b/binarycpython/utils/grid_options_defaults.py
index 5f360e7b0..fd62de48a 100644
--- a/binarycpython/utils/grid_options_defaults.py
+++ b/binarycpython/utils/grid_options_defaults.py
@@ -9,7 +9,7 @@ grid_options_defaults_dict = {
     "C_logging_code": None,  # Should contain a string which holds the logging code.
     "custom_logging_func_memaddr": -1,  # Contains the custom_logging functions memory address
     # Store pre-loading:
-    'store_memaddr': -1, # Contains the store object memory adress, useful for preloading. defaults to -1 and isnt used if thats the default then.
+    "store_memaddr": -1,  # Contains the store object memory adress, useful for preloading. defaults to -1 and isnt used if thats the default then.
     # Log args: logging of arguments
     "log_args": 0,  #
     "log_args_dir": "/tmp/",
diff --git a/examples/examples.py b/examples/examples.py
index 83b1a6886..ffe5a6f45 100644
--- a/examples/examples.py
+++ b/examples/examples.py
@@ -103,6 +103,7 @@ def run_example_binary_with_run_system():
 
 run_example_binary_with_run_system()
 
+
 def run_example_custom_logging_autogenerated():
     """
     This is an example function for the autogeneration of logging codes that binary_c uses.
@@ -116,7 +117,6 @@ def run_example_custom_logging_autogenerated():
         }
     )
 
-
     # Generate code around logging lines
     custom_logging_code = binary_c_log_code(logging_line)
 
@@ -132,11 +132,18 @@ def run_example_custom_logging_autogenerated():
     metallicity = 0.02
     max_evolution_time = 15000
     argstring = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g}".format(
-        m1, m2, separation, orbital_period, eccentricity, metallicity, max_evolution_time
+        m1,
+        m2,
+        separation,
+        orbital_period,
+        eccentricity,
+        metallicity,
+        max_evolution_time,
     )
     output = binary_c_python_api.run_binary_custom_logging(argstring, func_memaddr)
     print(output)
 
+
 run_example_custom_logging_autogenerated()
 
 
diff --git a/examples/examples_custom_logging.py b/examples/examples_custom_logging.py
index a6c93ab7c..1cbe9af5b 100644
--- a/examples/examples_custom_logging.py
+++ b/examples/examples_custom_logging.py
@@ -9,20 +9,28 @@ from binarycpython.utils.custom_logging_functions import (
 from binarycpython.utils.grid import Population
 
 #################################################
-# 
-
+#
 
 
 #################################################
 # no logging set.
 pop = Population()
-pop.set(M_1=10, M_2=10, separation=0, orbital_period=4530, eccentricity=0, metallicity=0.02, max_evolution_time=15000)
+pop.set(
+    M_1=10,
+    M_2=10,
+    separation=0,
+    orbital_period=4530,
+    eccentricity=0,
+    metallicity=0.02,
+    max_evolution_time=15000,
+)
 out = pop.evolve_single()
 print(out)
 
 #################################################
-# Example logging snippet for logging 
-pop.set(C_logging_code="""
+# Example logging snippet for logging
+pop.set(
+    C_logging_code="""
     if(stardata->star[0].stellar_type>=MS)
     {
         if (stardata->model.time < stardata->model.max_evolution_time)
@@ -46,15 +54,25 @@ pop.set(C_logging_code="""
         /* Kill the simulation to save time */
         //stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm;
     };
-""")
+"""
+)
 out = pop.evolve_single()
 print(out)
 
 
 #################################################
 # Example logging snippet for checking whether the system becomes a NS, and stop the evolution if so.
-pop.set(M_1=100, M_2=10, separation=0, orbital_period=400530, eccentricity=0, metallicity=0.002, max_evolution_time=15000)
-pop.set(C_logging_code="""
+pop.set(
+    M_1=100,
+    M_2=10,
+    separation=0,
+    orbital_period=400530,
+    eccentricity=0,
+    metallicity=0.002,
+    max_evolution_time=15000,
+)
+pop.set(
+    C_logging_code="""
     if(stardata->star[0].stellar_type>=NS)
     {
         if (stardata->model.time < stardata->model.max_evolution_time)
@@ -76,12 +94,13 @@ pop.set(C_logging_code="""
         /* Kill the simulation to save time */
         stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm;
     };
-""") 
+"""
+)
 out = pop.evolve_single()
 
 
-# TODO: add function that shows a 
+# TODO: add function that shows a
 
 # TODO: add function for compact object mergers
 
-# TODO: add function 
\ No newline at end of file
+# TODO: add function
diff --git a/tests/population/grid_tests.py b/tests/population/grid_tests.py
index dc09adfb0..f25678360 100644
--- a/tests/population/grid_tests.py
+++ b/tests/population/grid_tests.py
@@ -53,7 +53,8 @@ test_pop.set(
 
 ## Custom logging with bigger print statement:
 test_pop.set(M_1=100, M_2=1, metallicity=0.0002, orbital_period=500000000)
-test_pop.set(C_logging_code="""
+test_pop.set(
+    C_logging_code="""
     if(stardata->star[0].stellar_type>=MS)
     {
         if (stardata->model.time < stardata->model.max_evolution_time)
@@ -75,7 +76,8 @@ test_pop.set(C_logging_code="""
         /* Kill the simulation to save time */
         //stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm;
     };
-""")
+"""
+)
 test_pop.evolve_population()
 
 
@@ -88,4 +90,4 @@ test_pop.evolve_population()
 
 # return all info:
 # print(json.dumps(test_pop.return_all_info(), indent=4))
-test_pop.export_all_info(outfile=os.path.join(os.getcwd(), "test_output.txt"))
\ No newline at end of file
+test_pop.export_all_info(outfile=os.path.join(os.getcwd(), "test_output.txt"))
diff --git a/tests/python_API_test.py b/tests/python_API_test.py
index 958c24b7a..ef1f1fbf5 100755
--- a/tests/python_API_test.py
+++ b/tests/python_API_test.py
@@ -14,6 +14,7 @@ import tempfile
 # Test script for the api functions
 ############################################################
 
+
 def test_run_binary():
     m1 = 15.0  # Msun
     m2 = 14.0  # Msun
@@ -153,6 +154,7 @@ def test_run_system():
     )
     out = binary_c_python_api.run_system(argstring, -1, -1)
 
+
 ####
 if __name__ == "__main__":
     # test_run_binary()
@@ -171,4 +173,4 @@ if __name__ == "__main__":
 
     # test_return_store()
 
-    test_run_system()
\ No newline at end of file
+    test_run_system()
diff --git a/tests/random_tests.py b/tests/random_tests.py
index 45db44c4f..b41d16e20 100644
--- a/tests/random_tests.py
+++ b/tests/random_tests.py
@@ -1,8 +1,6 @@
-
 import binary_c_python_api
 from binarycpython.utils.functions import get_help_super
 
 
-
 # get_help_super(print_help=True)
-get_help_super(print_help=False)
\ No newline at end of file
+get_help_super(print_help=False)
-- 
GitLab