diff --git a/Makefile b/Makefile index 3bf93bfcbdced05007f97bbc517ab4fec3111d82..36703ebb15daf9357b025bab3a731deacec805c4 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ SO_FLAGS := -shared PY_EXEC := python3 PY_SETUP := setup.py #PY_OPTIONS := build_ext --build-lib $(TARGET_LIB_DIR) -PY_OPTIONS := build_ext --inplace -- +PY_OPTIONS := build_ext --inplace # maybe pass argument from here to the setup.py? all: diff --git a/binarycpython/core/__init__.py b/binarycpython/core/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py index cc7e3b954d63f36e77370f5ee1bcba7f94de5022..539bcf8319e2b1147bec1c9b83052c85a41997cc 100644 --- a/binarycpython/utils/functions.py +++ b/binarycpython/utils/functions.py @@ -1,7 +1,7 @@ from collections import defaultdict -import binary_c -from binaryc_python_utils.custom_logging_functions import ( +import binary_c_python_api +from binarycpython.utils.custom_logging_functions import ( create_and_load_logging_function, ) @@ -22,7 +22,7 @@ def get_defaults(): Function that calls the binaryc get args function and cast it into a dictionary All the values are strings """ - default_output = binary_c.return_arglines() + default_output = binary_c_python_api.return_arglines() default_dict = {} for default in default_output.split("\n"): @@ -71,7 +71,7 @@ def run_system(**kwargs): arg_string = "binary_c {}".format(arg_string) # Run it and get output - output = binary_c.run_binary_custom_logging(arg_string, func_memaddr) + output = binary_c_python_api.run_binary_custom_logging(arg_string, func_memaddr) return output elif "log_filename" in kwargs: @@ -84,7 +84,7 @@ def run_system(**kwargs): arg_string = "binary_c {}".format(arg_string) # Run it and get output - output = binary_c.run_binary_with_logfile(arg_string) + output = binary_c_python_api.run_binary_with_logfile(arg_string) return output else: # run the plain basic type @@ -98,7 +98,7 @@ def run_system(**kwargs): arg_string = "binary_c {}".format(arg_string) # Run it and get output - output = binary_c.run_binary(arg_string) + output = binary_c_python_api.run_binary(arg_string) return output @@ -129,7 +129,7 @@ def run_system_with_log(**kwargs): # Run it and get output buffer = "" - output = binary_c.run_binary_with_log(arg_string) + output = binary_c_python_api.run_binary_with_log(arg_string) return output diff --git a/examples/examples.py b/examples/examples.py index 7df0e0287746f778d0acddc09f546ed2c73c1721..ab728b6e4679484d265be8068ed00d8ca4fe2dbf 100644 --- a/examples/examples.py +++ b/examples/examples.py @@ -2,10 +2,10 @@ import os import sys -import binary_c +import binary_c_python_api -from binaryc_python_utils.functions import run_system, parse_output -from binaryc_python_utils.custom_logging_functions import ( +from binarycpython.utils.functions import run_system, parse_output +from binarycpython.utils.custom_logging_functions import ( autogen_C_logging_code, binary_c_log_code, ) @@ -42,10 +42,10 @@ def run_example_binary(): metallicity=metallicity, max_evolution_time=max_evolution_time, ) - output = binary_c.run_binary(argstring) + output = binary_c_python_api.run_binary(argstring) print(output) -# run_example_binary() +run_example_binary() def run_example_binary_with_run_system(): @@ -143,7 +143,7 @@ def run_example_binary_with_custom_logging(): # Do whatever you like with the dataframe. print(df) -# run_example_binary_with_custom_logging() +run_example_binary_with_custom_logging() def run_example_binary_with_writing_logfile(): """ @@ -161,23 +161,7 @@ def run_example_binary_with_writing_logfile(): separation=0, orbital_period=100000000000, log_filename=tempfile.gettempdir() + "/test_log.txt", - ) - - # Catch results that start with a given header. (Mind that binary_c has to be configured to print them if your not using a custom logging function) - result_example_header = parse_output(output, "example_header") - #### Now do whatever you want with it: - # Put it in numpy arrays - # t_res = np.asarray(result_example_header['t'], dtype=np.float64, order='C') - # m_res = np.asarray(result_example_header['mass'], dtype=np.float64, order='C') - - # Cast the data into a dataframe. - df = pd.DataFrame.from_dict(result_example_header, dtype=np.float64) - - # print(df) - # sliced_df = df[df.t < 1000] # Cut off late parts of evolution - # print(sliced_df[["t","m1"]]) - - # Some routine to plot. + ) -# run_example_binary_with_writing_logfile() \ No newline at end of file +run_example_binary_with_writing_logfile() \ No newline at end of file diff --git a/lib/__init__.py b/lib/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/setup.py b/setup.py index 2abee2e381dafcea751c3d7436031fe4f3020be4..9e97e0f499f50bd70ca9917da1818511cc0b08f1 100644 --- a/setup.py +++ b/setup.py @@ -58,8 +58,9 @@ binary_c_define_macros.extend([("BINARY_C_API_H", API_h)]) binary_c_python_api_module = Extension( - "binary_c", - ["src/binary_c_python.c"], + # name="binarycpython.core.binary_c", + name="binary_c_python_api", + sources=["src/binary_c_python.c"], include_dirs=[ os.environ["BINARY_C"] + "/src", os.environ["BINARY_C"] + "/src/API", @@ -71,17 +72,20 @@ binary_c_python_api_module = Extension( os.environ["BINARY_C"] + "/src", "./", os.path.join(CWD, "lib/"), + # os.path.join(CWD, "binarycpython/core/"), ] + binary_c_libdirs, runtime_library_dirs=[ os.environ["BINARY_C"] + "/src", "./", os.path.join(CWD, "lib/"), + # os.path.join(CWD, "binarycpython/core/"), ] + binary_c_libdirs, define_macros=[] + binary_c_define_macros, extra_objects=[], extra_compile_args=[], + language="C", ) def readme(): @@ -100,15 +104,17 @@ setup( package_dir = { 'binarycpython': 'binarycpython', 'binarycpython.utils': 'binarycpython/utils', + # 'binarycpython.core': 'lib', }, - packages=['binarycpython', + packages=[ + 'binarycpython', 'binarycpython.utils', + # 'binarycpython.core', ], - - - - + # package_data={ + # 'binarycpython.core': ['libbinary_c_api.so'], + # }, ext_modules=[ binary_c_python_api_module diff --git a/src/binary_c_python.c b/src/binary_c_python.c index 7a96ccc4d29f09a963d071ec5c049fd8c8e57454..9504c50fed98529810f4438aa4f6173826a56cc8 100644 --- a/src/binary_c_python.c +++ b/src/binary_c_python.c @@ -82,7 +82,7 @@ static PyMethodDef module_methods[] = { #if PY_MAJOR_VERSION >= 3 /* Python 3+ */ -static struct PyModuleDef Py_binary_c = +static struct PyModuleDef Py_binary_c_python_api = { PyModuleDef_HEAD_INIT, "binary_c", /* name of module */ @@ -91,9 +91,9 @@ static struct PyModuleDef Py_binary_c = module_methods }; -PyMODINIT_FUNC PyInit_binary_c(void) +PyMODINIT_FUNC PyInit_binary_c_python_api(void) { - return PyModule_Create(&Py_binary_c); + return PyModule_Create(&Py_binary_c_python_api); } #else @@ -106,7 +106,7 @@ PyMODINIT_FUNC PyInit_binary_c(void) PyMODINIT_FUNC initbinary_c(void) { - PyObject *m = Py_InitModule3("binary_c", module_methods, module_docstring); + PyObject *m = Py_InitModule3("binary_c_python_api", module_methods, module_docstring); if(m == NULL) return; }