diff --git a/.history/py2c/README_20240704011237.md b/.history/py2c/README_20240704011237.md new file mode 100644 index 0000000..15ad41e --- /dev/null +++ b/.history/py2c/README_20240704011237.md @@ -0,0 +1,12 @@ +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situataion. + + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. \ No newline at end of file diff --git a/.history/py2c/README_20240710013546.md b/.history/py2c/README_20240710013546.md new file mode 100644 index 0000000..f3655f4 --- /dev/null +++ b/.history/py2c/README_20240710013546.md @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/.history/py2c/README_20240710013550.md b/.history/py2c/README_20240710013550.md new file mode 100644 index 0000000..b7dd451 --- /dev/null +++ b/.history/py2c/README_20240710013550.md @@ -0,0 +1,33 @@ + + +Sure, I'll update the README to include the requirement for `jq` and provide a link for installation. + +```markdown:py2c/README.md +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. +``` + +This update includes the requirement for `jq` and provides a link for installation. \ No newline at end of file diff --git a/.history/py2c/README_20240710013555.md b/.history/py2c/README_20240710013555.md new file mode 100644 index 0000000..1976b9e --- /dev/null +++ b/.history/py2c/README_20240710013555.md @@ -0,0 +1,32 @@ + + +Sure, I'll update the README to include the requirement for `jq` and provide a link for installation. + +```markdown:py2c/README.md +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. +``` + diff --git a/.history/py2c/README_20240710013556.md b/.history/py2c/README_20240710013556.md new file mode 100644 index 0000000..6d2a4fe --- /dev/null +++ b/.history/py2c/README_20240710013556.md @@ -0,0 +1,31 @@ + + +Sure, I'll update the README to include the requirement for `jq` and provide a link for installation. + +```markdown:py2c/README.md +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. +``` \ No newline at end of file diff --git a/.history/py2c/README_20240710013606.md b/.history/py2c/README_20240710013606.md new file mode 100644 index 0000000..91e7805 --- /dev/null +++ b/.history/py2c/README_20240710013606.md @@ -0,0 +1,31 @@ + + +Sure, I'll update the README to include the requirement for `jq` and provide a link for installation. + +```markdown:py2c/README.md +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. +`` \ No newline at end of file diff --git a/.history/py2c/README_20240710013608.md b/.history/py2c/README_20240710013608.md new file mode 100644 index 0000000..9ef3956 --- /dev/null +++ b/.history/py2c/README_20240710013608.md @@ -0,0 +1,30 @@ + + +Sure, I'll update the README to include the requirement for `jq` and provide a link for installation. + +```markdown:py2c/README.md +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. diff --git a/.history/py2c/README_20240710013611.md b/.history/py2c/README_20240710013611.md new file mode 100644 index 0000000..9ef3956 --- /dev/null +++ b/.history/py2c/README_20240710013611.md @@ -0,0 +1,30 @@ + + +Sure, I'll update the README to include the requirement for `jq` and provide a link for installation. + +```markdown:py2c/README.md +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. diff --git a/.history/py2c/README_20240710013619.md b/.history/py2c/README_20240710013619.md new file mode 100644 index 0000000..e2be761 --- /dev/null +++ b/.history/py2c/README_20240710013619.md @@ -0,0 +1,31 @@ + + +Sure, I'll update the README to include the requirement for `jq` and provide a link for installation. + +```markdown:py2c/README.md +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: + +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. diff --git a/.history/py2c/README_20240710013645.md b/.history/py2c/README_20240710013645.md new file mode 100644 index 0000000..52b69da --- /dev/null +++ b/.history/py2c/README_20240710013645.md @@ -0,0 +1,30 @@ + + +Sure, I'll update the README to include the requirement for `jq` and provide a link for installation. + +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: + +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. diff --git a/.history/py2c/README_20240710013647.md b/.history/py2c/README_20240710013647.md new file mode 100644 index 0000000..df456b0 --- /dev/null +++ b/.history/py2c/README_20240710013647.md @@ -0,0 +1,30 @@ + + + Sure, I'll update the README to include the requirement for `jq` and provide a link for installation. + +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: + +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. diff --git a/.history/py2c/README_20240710013649.md b/.history/py2c/README_20240710013649.md new file mode 100644 index 0000000..b82ec59 --- /dev/null +++ b/.history/py2c/README_20240710013649.md @@ -0,0 +1,30 @@ + + + Sure, I'll update the README to include the requirement for `jq` and provide a link for installation. + +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: + +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. diff --git a/.history/py2c/README_20240710013653.md b/.history/py2c/README_20240710013653.md new file mode 100644 index 0000000..224b2fc --- /dev/null +++ b/.history/py2c/README_20240710013653.md @@ -0,0 +1,29 @@ + + + +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: + +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. diff --git a/.history/py2c/README_20240710013741.md b/.history/py2c/README_20240710013741.md new file mode 100644 index 0000000..261cc4f --- /dev/null +++ b/.history/py2c/README_20240710013741.md @@ -0,0 +1,29 @@ + + + diff --git a/.history/py2c/README_20240710013746.md b/.history/py2c/README_20240710013746.md new file mode 100644 index 0000000..1b350f9 --- /dev/null +++ b/.history/py2c/README_20240710013746.md @@ -0,0 +1,29 @@ +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situataion. + + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. + + diff --git a/.history/py2c/README_20240710013747.md b/.history/py2c/README_20240710013747.md new file mode 100644 index 0000000..261cc4f --- /dev/null +++ b/.history/py2c/README_20240710013747.md @@ -0,0 +1,29 @@ + + + diff --git a/.history/py2c/README_20240710013749.md b/.history/py2c/README_20240710013749.md new file mode 100644 index 0000000..1b350f9 --- /dev/null +++ b/.history/py2c/README_20240710013749.md @@ -0,0 +1,29 @@ +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situataion. + + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. + + diff --git a/.history/py2c/README_20240710013750.md b/.history/py2c/README_20240710013750.md new file mode 100644 index 0000000..e0a7012 --- /dev/null +++ b/.history/py2c/README_20240710013750.md @@ -0,0 +1,17 @@ + + diff --git a/.history/py2c/README_20240710013753.md b/.history/py2c/README_20240710013753.md new file mode 100644 index 0000000..327260e --- /dev/null +++ b/.history/py2c/README_20240710013753.md @@ -0,0 +1,17 @@ + --> diff --git a/.history/py2c/README_20240710013758.md b/.history/py2c/README_20240710013758.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.history/py2c/README_20240710013758.md @@ -0,0 +1 @@ + diff --git a/.history/py2c/README_20240710013759.md b/.history/py2c/README_20240710013759.md new file mode 100644 index 0000000..e0a7012 --- /dev/null +++ b/.history/py2c/README_20240710013759.md @@ -0,0 +1,17 @@ + + diff --git a/.history/py2c/README_20240710013811.md b/.history/py2c/README_20240710013811.md new file mode 100644 index 0000000..e500634 --- /dev/null +++ b/.history/py2c/README_20240710013811.md @@ -0,0 +1,17 @@ + + +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: + +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. diff --git a/.history/py2c/README_20240710013814.md b/.history/py2c/README_20240710013814.md new file mode 100644 index 0000000..b7641dd --- /dev/null +++ b/.history/py2c/README_20240710013814.md @@ -0,0 +1,15 @@ +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: + +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. diff --git a/.history/py2c/README_20240710013821.md b/.history/py2c/README_20240710013821.md new file mode 100644 index 0000000..e38cf9c --- /dev/null +++ b/.history/py2c/README_20240710013821.md @@ -0,0 +1,17 @@ +# Python to C++ interface + +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. + +## Prerequisites + +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). + +## Runnable script + +Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: + +```bash +./a.out +``` + +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. diff --git a/.history/py2c/asyncUtils_20240704011237.py b/.history/py2c/asyncUtils_20240704011237.py new file mode 100644 index 0000000..0dae66e --- /dev/null +++ b/.history/py2c/asyncUtils_20240704011237.py @@ -0,0 +1,57 @@ +import asyncio +import aiohttp + +async def fetch_data(url): + async with aiohttp.ClientSession() as session: + async with session.get(url) as response: + return await response.text() + +async def fetch_multiple(urls): + async with aiohttp.ClientSession() as session: + tasks = [fetch_data(url) for url in urls] + return await asyncio.gather(*tasks) + +async def post_data(url, data): + async with aiohttp.ClientSession() as session: + async with session.post(url, json=data) as response: + return await response.text() + +async def fetch_with_timeout(url, timeout): + async with aiohttp.ClientSession() as session: + try: + async with session.get(url, timeout=timeout) as response: + return await response.text() + except asyncio.TimeoutError: + return "Request timed out" + +# config for fetch_data +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_data", +# "args": ["https://jsonplaceholder.typicode.com/todos/1"] +# } + +# config for fetch_multiple +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_multiple", +# "args": [["https://jsonplaceholder.typicode.com/todos/1", "https://jsonplaceholder.typicode.com/todos/2"]] +# } + +# config for post_data +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "post_data", +# "args": ["https://jsonplaceholder.typicode.com/posts", {"title": "foo", "body": "bar", "userId": 1}] +# } + +# config for fetch_with_timeout +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_with_timeout", +# "args": ["https://jsonplaceholder.typicode.com/todos/1", 5] +# } \ No newline at end of file diff --git a/.history/py2c/asyncUtils_20240710012824.py b/.history/py2c/asyncUtils_20240710012824.py new file mode 100644 index 0000000..71eeb54 --- /dev/null +++ b/.history/py2c/asyncUtils_20240710012824.py @@ -0,0 +1,42 @@ +import asyncio +import aiohttp + +async def fetch_data(url): + async with aiohttp.ClientSession() as session: + async with session.get(url) as response: + return await response.text() + +async def fetch_multiple(urls): + async with aiohttp.ClientSession() as session: + tasks = [fetch_data(url) for url in urls] + return await asyncio.gather(*tasks) + +async def post_data(url, data): + async with aiohttp.ClientSession() as session: + async with session.post(url, json=data) as response: + return await response.text() + +async def fetch_with_timeout(url, timeout): + async with aiohttp.ClientSession() as session: + try: + async with session.get(url, timeout=timeout) as response: + return await response.text() + except asyncio.TimeoutError: + return "Request timed out" + + +# config for post_data +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "post_data", +# "args": ["https://jsonplaceholder.typicode.com/posts", {"title": "foo", "body": "bar", "userId": 1}] +# } + +# config for fetch_with_timeout +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_with_timeout", +# "args": ["https://jsonplaceholder.typicode.com/todos/1", 5] +# } \ No newline at end of file diff --git a/.history/py2c/asyncUtils_20240710012831.py b/.history/py2c/asyncUtils_20240710012831.py new file mode 100644 index 0000000..0dae66e --- /dev/null +++ b/.history/py2c/asyncUtils_20240710012831.py @@ -0,0 +1,57 @@ +import asyncio +import aiohttp + +async def fetch_data(url): + async with aiohttp.ClientSession() as session: + async with session.get(url) as response: + return await response.text() + +async def fetch_multiple(urls): + async with aiohttp.ClientSession() as session: + tasks = [fetch_data(url) for url in urls] + return await asyncio.gather(*tasks) + +async def post_data(url, data): + async with aiohttp.ClientSession() as session: + async with session.post(url, json=data) as response: + return await response.text() + +async def fetch_with_timeout(url, timeout): + async with aiohttp.ClientSession() as session: + try: + async with session.get(url, timeout=timeout) as response: + return await response.text() + except asyncio.TimeoutError: + return "Request timed out" + +# config for fetch_data +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_data", +# "args": ["https://jsonplaceholder.typicode.com/todos/1"] +# } + +# config for fetch_multiple +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_multiple", +# "args": [["https://jsonplaceholder.typicode.com/todos/1", "https://jsonplaceholder.typicode.com/todos/2"]] +# } + +# config for post_data +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "post_data", +# "args": ["https://jsonplaceholder.typicode.com/posts", {"title": "foo", "body": "bar", "userId": 1}] +# } + +# config for fetch_with_timeout +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_with_timeout", +# "args": ["https://jsonplaceholder.typicode.com/todos/1", 5] +# } \ No newline at end of file diff --git a/.history/py2c/asyncUtils_20240710012848.py b/.history/py2c/asyncUtils_20240710012848.py new file mode 100644 index 0000000..dd4f608 --- /dev/null +++ b/.history/py2c/asyncUtils_20240710012848.py @@ -0,0 +1,25 @@ +import asyncio +import aiohttp + +async def fetch_data(url): + async with aiohttp.ClientSession() as session: + async with session.get(url) as response: + return await response.text() + +async def fetch_multiple(urls): + async with aiohttp.ClientSession() as session: + tasks = [fetch_data(url) for url in urls] + return await asyncio.gather(*tasks) + +async def post_data(url, data): + async with aiohttp.ClientSession() as session: + async with session.post(url, json=data) as response: + return await response.text() + +async def fetch_with_timeout(url, timeout): + async with aiohttp.ClientSession() as session: + try: + async with session.get(url, timeout=timeout) as response: + return await response.text() + except asyncio.TimeoutError: + return "Request timed out" diff --git a/.history/py2c/mathUtils_20240704011237.py b/.history/py2c/mathUtils_20240704011237.py new file mode 100644 index 0000000..fea7ee8 --- /dev/null +++ b/.history/py2c/mathUtils_20240704011237.py @@ -0,0 +1,53 @@ +# def two_sum(nums, target): +# # Create a dictionary to store the complement and its index +# num_to_index = {} + +# # Iterate over the list of numbers +# for index, num in enumerate(nums): +# # Calculate the complement +# complement = target - num + +# # Check if the complement is already in the dictionary +# if complement in num_to_index: +# # If found, return the indices of the two numbers +# return [num_to_index[complement], index] + +# # Otherwise, add the number and its index to the dictionary +# num_to_index[num] = index + +# # If no solution is found, return an empty list +# return [] + +# # Example usage for two_sum +# if __name__ == "__main__": +# nums = [2, 7, 11, 15] +# target = 9 +# result = two_sum(nums, target) +# print(f"Indices of the two numbers that add up to {target} are: {result}") + + +# def multiply(a,b): +# return a*b + +# def concat_sum_string(a, b, s): +# try: +# result = int(a) + int(b) +# print(f"{s}: {result}") +# return result +# except ValueError: +# print("Error: Invalid input") +# return None + +# Example usage for process_data for testing the data types +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013156.py b/.history/py2c/mathUtils_20240710013156.py new file mode 100644 index 0000000..6b61fe9 --- /dev/null +++ b/.history/py2c/mathUtils_20240710013156.py @@ -0,0 +1,14 @@ + +# Example usage for process_data for testing the data types +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013205.py b/.history/py2c/mathUtils_20240710013205.py new file mode 100644 index 0000000..4ee6e5f --- /dev/null +++ b/.history/py2c/mathUtils_20240710013205.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types + +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013207.py b/.history/py2c/mathUtils_20240710013207.py new file mode 100644 index 0000000..31488fd --- /dev/null +++ b/.history/py2c/mathUtils_20240710013207.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types +#you +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013213.py b/.history/py2c/mathUtils_20240710013213.py new file mode 100644 index 0000000..0d64cf0 --- /dev/null +++ b/.history/py2c/mathUtils_20240710013213.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types +# you +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013220.py b/.history/py2c/mathUtils_20240710013220.py new file mode 100644 index 0000000..d9e1b0a --- /dev/null +++ b/.history/py2c/mathUtils_20240710013220.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types +# you can use +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013244.py b/.history/py2c/mathUtils_20240710013244.py new file mode 100644 index 0000000..f5411e3 --- /dev/null +++ b/.history/py2c/mathUtils_20240710013244.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types +# more examples +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013248.py b/.history/py2c/mathUtils_20240710013248.py new file mode 100644 index 0000000..be8b8d7 --- /dev/null +++ b/.history/py2c/mathUtils_20240710013248.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types +# more examples on modeule/ +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013254.py b/.history/py2c/mathUtils_20240710013254.py new file mode 100644 index 0000000..e0549d1 --- /dev/null +++ b/.history/py2c/mathUtils_20240710013254.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types +# more examples on mod +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013256.py b/.history/py2c/mathUtils_20240710013256.py new file mode 100644 index 0000000..4e2d1c5 --- /dev/null +++ b/.history/py2c/mathUtils_20240710013256.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types +# more examples on modu +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013258.py b/.history/py2c/mathUtils_20240710013258.py new file mode 100644 index 0000000..c1f5f79 --- /dev/null +++ b/.history/py2c/mathUtils_20240710013258.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types +# more examples on module +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013301.py b/.history/py2c/mathUtils_20240710013301.py new file mode 100644 index 0000000..e5622cf --- /dev/null +++ b/.history/py2c/mathUtils_20240710013301.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types +# more examples on module/ +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013304.py b/.history/py2c/mathUtils_20240710013304.py new file mode 100644 index 0000000..cf8427e --- /dev/null +++ b/.history/py2c/mathUtils_20240710013304.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types +# more examples on module/test +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013307.py b/.history/py2c/mathUtils_20240710013307.py new file mode 100644 index 0000000..a36c052 --- /dev/null +++ b/.history/py2c/mathUtils_20240710013307.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types +# more examples on module/test_ +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710013310.py b/.history/py2c/mathUtils_20240710013310.py new file mode 100644 index 0000000..dc26f0a --- /dev/null +++ b/.history/py2c/mathUtils_20240710013310.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types +# more examples on module/test_mathUtils.py +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014045.py b/.history/py2c/mathUtils_20240710014045.py new file mode 100644 index 0000000..b9bc77f --- /dev/null +++ b/.history/py2c/mathUtils_20240710014045.py @@ -0,0 +1,15 @@ +'''''' +# Example usage for process_data for testing the data types +# more examples on module/test_mathUtils.py +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014047.py b/.history/py2c/mathUtils_20240710014047.py new file mode 100644 index 0000000..8cb5110 --- /dev/null +++ b/.history/py2c/mathUtils_20240710014047.py @@ -0,0 +1,17 @@ +''' + +''' +# Example usage for process_data for testing the data types +# more examples on module/test_mathUtils.py +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014050.py b/.history/py2c/mathUtils_20240710014050.py new file mode 100644 index 0000000..444f76e --- /dev/null +++ b/.history/py2c/mathUtils_20240710014050.py @@ -0,0 +1,17 @@ +''' +# Example usage for process_data for testing the data types +# more examples on module/test_mathUtils.py +''' + +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014051.py b/.history/py2c/mathUtils_20240710014051.py new file mode 100644 index 0000000..e3b725d --- /dev/null +++ b/.history/py2c/mathUtils_20240710014051.py @@ -0,0 +1,17 @@ +''' +Example usage for process_data for testing the data types +more examples on module/test_mathUtils.py +''' + +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014054.py b/.history/py2c/mathUtils_20240710014054.py new file mode 100644 index 0000000..bd42e0e --- /dev/null +++ b/.history/py2c/mathUtils_20240710014054.py @@ -0,0 +1,16 @@ +''' +Example usage for process_data for testing the data types +more examples on module/test_mathUtils.py +''' +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014101.py b/.history/py2c/mathUtils_20240710014101.py new file mode 100644 index 0000000..bd42e0e --- /dev/null +++ b/.history/py2c/mathUtils_20240710014101.py @@ -0,0 +1,16 @@ +''' +Example usage for process_data for testing the data types +more examples on module/test_mathUtils.py +''' +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014104.py b/.history/py2c/mathUtils_20240710014104.py new file mode 100644 index 0000000..bb61afb --- /dev/null +++ b/.history/py2c/mathUtils_20240710014104.py @@ -0,0 +1,16 @@ +''' +Example usage for process_data for testing the data types +more examples on module/test_mathUtils.py + +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014106.py b/.history/py2c/mathUtils_20240710014106.py new file mode 100644 index 0000000..f26dca9 --- /dev/null +++ b/.history/py2c/mathUtils_20240710014106.py @@ -0,0 +1,16 @@ + +Example usage for process_data for testing the data types +more examples on module/test_mathUtils.py + +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014109.py b/.history/py2c/mathUtils_20240710014109.py new file mode 100644 index 0000000..5322427 --- /dev/null +++ b/.history/py2c/mathUtils_20240710014109.py @@ -0,0 +1,16 @@ +`` +Example usage for process_data for testing the data types +more examples on module/test_mathUtils.py + +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014110.py b/.history/py2c/mathUtils_20240710014110.py new file mode 100644 index 0000000..7a61ac5 --- /dev/null +++ b/.history/py2c/mathUtils_20240710014110.py @@ -0,0 +1,16 @@ +```` +Example usage for process_data for testing the data types +more examples on module/test_mathUtils.py + +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014113.py b/.history/py2c/mathUtils_20240710014113.py new file mode 100644 index 0000000..7a61ac5 --- /dev/null +++ b/.history/py2c/mathUtils_20240710014113.py @@ -0,0 +1,16 @@ +```` +Example usage for process_data for testing the data types +more examples on module/test_mathUtils.py + +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014115.py b/.history/py2c/mathUtils_20240710014115.py new file mode 100644 index 0000000..180d5cd --- /dev/null +++ b/.history/py2c/mathUtils_20240710014115.py @@ -0,0 +1,17 @@ +""" +Example usage for process_data for testing the data types +more examples on module/test_mathUtils.py +""" + +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014118.py b/.history/py2c/mathUtils_20240710014118.py new file mode 100644 index 0000000..226c175 --- /dev/null +++ b/.history/py2c/mathUtils_20240710014118.py @@ -0,0 +1,16 @@ +""" +Example usage for process_data for testing the data types +more examples on module/test_mathUtils.py +""" +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014125.py b/.history/py2c/mathUtils_20240710014125.py new file mode 100644 index 0000000..b383725 --- /dev/null +++ b/.history/py2c/mathUtils_20240710014125.py @@ -0,0 +1,16 @@ +""" +Example usage for process_data for testing the data types +more examples on module/test_mathUtils.py + +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014126.py b/.history/py2c/mathUtils_20240710014126.py new file mode 100644 index 0000000..f26dca9 --- /dev/null +++ b/.history/py2c/mathUtils_20240710014126.py @@ -0,0 +1,16 @@ + +Example usage for process_data for testing the data types +more examples on module/test_mathUtils.py + +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014129.py b/.history/py2c/mathUtils_20240710014129.py new file mode 100644 index 0000000..710689c --- /dev/null +++ b/.history/py2c/mathUtils_20240710014129.py @@ -0,0 +1,16 @@ + + Example usage for process_data for testing the data types + more examples on module/test_mathUtils.py + +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014131.py b/.history/py2c/mathUtils_20240710014131.py new file mode 100644 index 0000000..d6696aa --- /dev/null +++ b/.history/py2c/mathUtils_20240710014131.py @@ -0,0 +1,16 @@ + +# Example usage for process_data for testing the data types +# more examples on module/test_mathUtils.py + +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014133.py b/.history/py2c/mathUtils_20240710014133.py new file mode 100644 index 0000000..dc26f0a --- /dev/null +++ b/.history/py2c/mathUtils_20240710014133.py @@ -0,0 +1,15 @@ + +# Example usage for process_data for testing the data types +# more examples on module/test_mathUtils.py +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/mathUtils_20240710014136.py b/.history/py2c/mathUtils_20240710014136.py new file mode 100644 index 0000000..5952228 --- /dev/null +++ b/.history/py2c/mathUtils_20240710014136.py @@ -0,0 +1,14 @@ +# Example usage for process_data for testing the data types +# more examples on module/test_mathUtils.py +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/.history/py2c/module/function/configs_20240710012814.txt b/.history/py2c/module/function/configs_20240710012814.txt new file mode 100644 index 0000000..e69de29 diff --git a/.history/py2c/module/function/configs_20240710012826.txt b/.history/py2c/module/function/configs_20240710012826.txt new file mode 100644 index 0000000..3808f32 --- /dev/null +++ b/.history/py2c/module/function/configs_20240710012826.txt @@ -0,0 +1,16 @@ + +# config for fetch_data +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_data", +# "args": ["https://jsonplaceholder.typicode.com/todos/1"] +# } + +# config for fetch_multiple +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_multiple", +# "args": [["https://jsonplaceholder.typicode.com/todos/1", "https://jsonplaceholder.typicode.com/todos/2"]] +# } \ No newline at end of file diff --git a/.history/py2c/module/function/configs_20240710012829.txt b/.history/py2c/module/function/configs_20240710012829.txt new file mode 100644 index 0000000..e69de29 diff --git a/.history/py2c/module/function/configs_20240710012850.txt b/.history/py2c/module/function/configs_20240710012850.txt new file mode 100644 index 0000000..d4ad178 --- /dev/null +++ b/.history/py2c/module/function/configs_20240710012850.txt @@ -0,0 +1,32 @@ + +# config for fetch_data +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_data", +# "args": ["https://jsonplaceholder.typicode.com/todos/1"] +# } + +# config for fetch_multiple +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_multiple", +# "args": [["https://jsonplaceholder.typicode.com/todos/1", "https://jsonplaceholder.typicode.com/todos/2"]] +# } + +# config for post_data +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "post_data", +# "args": ["https://jsonplaceholder.typicode.com/posts", {"title": "foo", "body": "bar", "userId": 1}] +# } + +# config for fetch_with_timeout +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_with_timeout", +# "args": ["https://jsonplaceholder.typicode.com/todos/1", 5] +# } \ No newline at end of file diff --git a/.history/py2c/module/tests/test_mathUtils_20240710013157.py b/.history/py2c/module/tests/test_mathUtils_20240710013157.py new file mode 100644 index 0000000..9fac55b --- /dev/null +++ b/.history/py2c/module/tests/test_mathUtils_20240710013157.py @@ -0,0 +1,39 @@ +# def two_sum(nums, target): +# # Create a dictionary to store the complement and its index +# num_to_index = {} + +# # Iterate over the list of numbers +# for index, num in enumerate(nums): +# # Calculate the complement +# complement = target - num + +# # Check if the complement is already in the dictionary +# if complement in num_to_index: +# # If found, return the indices of the two numbers +# return [num_to_index[complement], index] + +# # Otherwise, add the number and its index to the dictionary +# num_to_index[num] = index + +# # If no solution is found, return an empty list +# return [] + +# # Example usage for two_sum +# if __name__ == "__main__": +# nums = [2, 7, 11, 15] +# target = 9 +# result = two_sum(nums, target) +# print(f"Indices of the two numbers that add up to {target} are: {result}") + + +# def multiply(a,b): +# return a*b + +# def concat_sum_string(a, b, s): +# try: +# result = int(a) + int(b) +# print(f"{s}: {result}") +# return result +# except ValueError: +# print("Error: Invalid input") +# return None diff --git a/.history/py2c/module/tests/test_mathUtils_20240710013903.py b/.history/py2c/module/tests/test_mathUtils_20240710013903.py new file mode 100644 index 0000000..a1a02c5 --- /dev/null +++ b/.history/py2c/module/tests/test_mathUtils_20240710013903.py @@ -0,0 +1,41 @@ +# def two_sum(nums, target): +# # Create a dictionary to store the complement and its index +# num_to_index = {} + +# # Iterate over the list of numbers +# for index, num in enumerate(nums): +# # Calculate the complement +# complement = target - num + +# # Check if the complement is already in the dictionary +# if complement in num_to_index: +# # If found, return the indices of the two numbers +# return [num_to_index[complement], index] + +# # Otherwise, add the number and its index to the dictionary +# num_to_index[num] = index + +# # If no solution is found, return an empty list +# return [] + +# # Example usage for two_sum +# if __name__ == "__main__": +# nums = [2, 7, 11, 15] +# target = 9 +# result = two_sum(nums, target) +# print(f"Indices of the two numbers that add up to {target} are: {result}") + + +# def multiply(a,b): +# return a*b + + + +# def concat_sum_string(a, b, s): +# try: +# result = int(a) + int(b) +# print(f"{s}: {result}") +# return result +# except ValueError: +# print("Error: Invalid input") +# return None diff --git a/.history/py2c/module/tests/test_mathUtils_20240710013907.py b/.history/py2c/module/tests/test_mathUtils_20240710013907.py new file mode 100644 index 0000000..1354405 --- /dev/null +++ b/.history/py2c/module/tests/test_mathUtils_20240710013907.py @@ -0,0 +1,41 @@ +def two_sum(nums, target): + # Create a dictionary to store the complement and its index + num_to_index = {} + + # Iterate over the list of numbers + for index, num in enumerate(nums): + # Calculate the complement + complement = target - num + + # Check if the complement is already in the dictionary + if complement in num_to_index: + # If found, return the indices of the two numbers + return [num_to_index[complement], index] + + # Otherwise, add the number and its index to the dictionary + num_to_index[num] = index + + # If no solution is found, return an empty list + return [] + +# Example usage for two_sum +if __name__ == "__main__": + nums = [2, 7, 11, 15] + target = 9 + result = two_sum(nums, target) + print(f"Indices of the two numbers that add up to {target} are: {result}") + + +def multiply(a,b): + return a*b + + + +def concat_sum_string(a, b, s): + try: + result = int(a) + int(b) + print(f"{s}: {result}") + return result + except ValueError: + print("Error: Invalid input") + return None diff --git a/.history/py2c/module/tests/test_mathUtils_20240710013958.py b/.history/py2c/module/tests/test_mathUtils_20240710013958.py new file mode 100644 index 0000000..a760eb8 --- /dev/null +++ b/.history/py2c/module/tests/test_mathUtils_20240710013958.py @@ -0,0 +1,71 @@ +def two_sum(nums, target): + """ + Find two numbers in the list that add up to the target. + + Args: + nums (list): List of integers. + target (int): Target sum. + + Returns: + list: Indices of the two numbers that add up to the target. + """ + # Create a dictionary to store the complement and its index + num_to_index = {} + + # Iterate over the list of numbers + for index, num in enumerate(nums): + # Calculate the complement + complement = target - num + + # Check if the complement is already in the dictionary + if complement in num_to_index: + # If found, return the indices of the two numbers + return [num_to_index[complement], index] + + # Otherwise, add the number and its index to the dictionary + num_to_index[num] = index + + # If no solution is found, return an empty list + return [] + +# Example usage for two_sum +if __name__ == "__main__": + nums = [2, 7, 11, 15] + target = 9 + result = two_sum(nums, target) + print(f"Indices of the two numbers that add up to {target} are: {result}") + + +def multiply(a, b): + """ + Multiply two numbers. + + Args: + a (int): First number. + b (int): Second number. + + Returns: + int: Product of the two numbers. + """ + return a * b + + +def concat_sum_string(a, b, s): + """ + Concatenate a string with the sum of two numbers. + + Args: + a (str): First number as a string. + b (str): Second number as a string. + s (str): String to concatenate with the sum. + + Returns: + int: Sum of the two numbers if valid, otherwise None. + """ + try: + result = int(a) + int(b) + print(f"{s}: {result}") + return result + except ValueError: + print("Error: Invalid input") + return None \ No newline at end of file diff --git a/.history/py2c/module/tests/test_mathUtils_20240710014013.py b/.history/py2c/module/tests/test_mathUtils_20240710014013.py new file mode 100644 index 0000000..f03a3ad --- /dev/null +++ b/.history/py2c/module/tests/test_mathUtils_20240710014013.py @@ -0,0 +1,63 @@ +def two_sum(nums, target): + """ + Find two numbers in the list that add up to the target. + + Args: + nums (list): List of integers. + target (int): Target sum. + + Returns: + list: Indices of the two numbers that add up to the target. + """ + # Create a dictionary to store the complement and its index + num_to_index = {} + + # Iterate over the list of numbers + for index, num in enumerate(nums): + # Calculate the complement + complement = target - num + + # Check if the complement is already in the dictionary + if complement in num_to_index: + # If found, return the indices of the two numbers + return [num_to_index[complement], index] + + # Otherwise, add the number and its index to the dictionary + num_to_index[num] = index + + # If no solution is found, return an empty list + return [] + +def multiply(a, b): + """ + Multiply two numbers. + + Args: + a (int): First number. + b (int): Second number. + + Returns: + int: Product of the two numbers. + """ + return a * b + + +def concat_sum_string(a, b, s): + """ + Concatenate a string with the sum of two numbers. + + Args: + a (str): First number as a string. + b (str): Second number as a string. + s (str): String to concatenate with the sum. + + Returns: + int: Sum of the two numbers if valid, otherwise None. + """ + try: + result = int(a) + int(b) + print(f"{s}: {result}") + return result + except ValueError: + print("Error: Invalid input") + return None \ No newline at end of file diff --git a/.history/py2c/module/tests/test_mathUtils_20240710014015.py b/.history/py2c/module/tests/test_mathUtils_20240710014015.py new file mode 100644 index 0000000..3d0156c --- /dev/null +++ b/.history/py2c/module/tests/test_mathUtils_20240710014015.py @@ -0,0 +1,62 @@ +def two_sum(nums, target): + """ + Find two numbers in the list that add up to the target. + + Args: + nums (list): List of integers. + target (int): Target sum. + + Returns: + list: Indices of the two numbers that add up to the target. + """ + # Create a dictionary to store the complement and its index + num_to_index = {} + + # Iterate over the list of numbers + for index, num in enumerate(nums): + # Calculate the complement + complement = target - num + + # Check if the complement is already in the dictionary + if complement in num_to_index: + # If found, return the indices of the two numbers + return [num_to_index[complement], index] + + # Otherwise, add the number and its index to the dictionary + num_to_index[num] = index + + # If no solution is found, return an empty list + return [] + +def multiply(a, b): + """ + Multiply two numbers. + + Args: + a (int): First number. + b (int): Second number. + + Returns: + int: Product of the two numbers. + """ + return a * b + +def concat_sum_string(a, b, s): + """ + Concatenate a string with the sum of two numbers. + + Args: + a (str): First number as a string. + b (str): Second number as a string. + s (str): String to concatenate with the sum. + + Returns: + int: Sum of the two numbers if valid, otherwise None. + """ + try: + result = int(a) + int(b) + print(f"{s}: {result}") + return result + except ValueError: + print("Error: Invalid input") + return None \ No newline at end of file diff --git a/.history/py2c/module/tests/test_math_utils_20240710013145.py b/.history/py2c/module/tests/test_math_utils_20240710013145.py new file mode 100644 index 0000000..e69de29 diff --git a/.history/py2c/module/tests/test_math_utils_20240710013158.py b/.history/py2c/module/tests/test_math_utils_20240710013158.py new file mode 100644 index 0000000..9fac55b --- /dev/null +++ b/.history/py2c/module/tests/test_math_utils_20240710013158.py @@ -0,0 +1,39 @@ +# def two_sum(nums, target): +# # Create a dictionary to store the complement and its index +# num_to_index = {} + +# # Iterate over the list of numbers +# for index, num in enumerate(nums): +# # Calculate the complement +# complement = target - num + +# # Check if the complement is already in the dictionary +# if complement in num_to_index: +# # If found, return the indices of the two numbers +# return [num_to_index[complement], index] + +# # Otherwise, add the number and its index to the dictionary +# num_to_index[num] = index + +# # If no solution is found, return an empty list +# return [] + +# # Example usage for two_sum +# if __name__ == "__main__": +# nums = [2, 7, 11, 15] +# target = 9 +# result = two_sum(nums, target) +# print(f"Indices of the two numbers that add up to {target} are: {result}") + + +# def multiply(a,b): +# return a*b + +# def concat_sum_string(a, b, s): +# try: +# result = int(a) + int(b) +# print(f"{s}: {result}") +# return result +# except ValueError: +# print("Error: Invalid input") +# return None diff --git a/.history/py2c/run_20240704011237.sh b/.history/py2c/run_20240704011237.sh new file mode 100644 index 0000000..4a63eb4 --- /dev/null +++ b/.history/py2c/run_20240704011237.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Read configuration file +CONFIG_FILE="config.json" +PYTHON_ENV=$(jq -r '.python_env' $CONFIG_FILE) +MODULE_NAME=$(jq -r '.module_name' $CONFIG_FILE) +FUNCTION_NAME=$(jq -r '.function_name' $CONFIG_FILE) +ARGS=$(jq -r '.args | join(" ")' $CONFIG_FILE) + + +# Update the include paths and the python module name +gcc runpython.c -I/Users/visheshyadav/anaconda3/include/python3.11 -L/Users/visheshyadav/anaconda3/lib -lpython3.11 -ldl -framework CoreFoundation + +# Ensure the current directory is in the python path +export PYTHONPATH=".:$PYTHONPATH" + +# Set the library path for the dynamic linker +export DYLD_LIBRARY_PATH="/Users/visheshyadav/anaconda3/lib:$DYLD_LIBRARY_PATH" + +# UNCOMMENT IT TO RUN OR, YOU CAN USE THE CONFIG FILE +# ./a.out mathUtils multiply 12 5 +./a.out mathUtils concat_sum_string 12 5 "Hello" +# ./a.out mathUtils process_data 1 2.5 "hello" "[1,2,3]" "{key:value}" + + +# ./a.out asyncUtils fetch_data "https://jsonplaceholder.typicode.com/todos/1" +# ./a.out asyncUtils fetch_multiple "https://jsonplaceholder.typicode.com/todos/1" "https://jsonplaceholder.typicode.com/todos/2" +# ./a.out asyncUtils post_data "https://jsonplaceholder.typicode.com/posts" "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}" +# ./a.out asyncUtils fetch_with_timeout "https://jsonplaceholder.typicode.com/todos/1" 5 + + + +# # Run the C program with arguments from the configuration file +# ./a.out $MODULE_NAME $FUNCTION_NAME $ARGS \ No newline at end of file diff --git a/.history/py2c/run_20240710014429.sh b/.history/py2c/run_20240710014429.sh new file mode 100644 index 0000000..f10289a --- /dev/null +++ b/.history/py2c/run_20240710014429.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Read configuration file +CONFIG_FILE="config.json" +PYTHON_ENV=$(jq -r '.python_env' $CONFIG_FILE) +MODULE_NAME=$(jq -r '.module_name' $CONFIG_FILE) +FUNCTION_NAME=$(jq -r '.function_name' $CONFIG_FILE) +ARGS=$(jq -r '.args | join(" ")' $CONFIG_FILE) + + +# Update the include paths and the python module name +gcc runpython.c -I/Users/visheshyadav/anaconda3/include/python3.11 -L/Users/visheshyadav/anaconda3/lib -lpython3.11 -ldl -framework CoreFoundation + + +# Ensure the current directory is in the python path +export PYTHONPATH=".:$PYTHONPATH" + +# Set the library path for the dynamic linker +export DYLD_LIBRARY_PATH="/Users/visheshyadav/anaconda3/lib:$DYLD_LIBRARY_PATH" + +# UNCOMMENT IT TO RUN OR, YOU CAN USE THE CONFIG FILE +# ./a.out mathUtils multiply 12 5 +./a.out mathUtils concat_sum_string 12 5 "Hello" +# ./a.out mathUtils process_data 1 2.5 "hello" "[1,2,3]" "{key:value}" + + +# ./a.out asyncUtils fetch_data "https://jsonplaceholder.typicode.com/todos/1" +# ./a.out asyncUtils fetch_multiple "https://jsonplaceholder.typicode.com/todos/1" "https://jsonplaceholder.typicode.com/todos/2" +# ./a.out asyncUtils post_data "https://jsonplaceholder.typicode.com/posts" "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}" +# ./a.out asyncUtils fetch_with_timeout "https://jsonplaceholder.typicode.com/todos/1" 5 + + + +# # Run the C program with arguments from the configuration file +# ./a.out $MODULE_NAME $FUNCTION_NAME $ARGS \ No newline at end of file diff --git a/.history/py2c/run_20240710014430.sh b/.history/py2c/run_20240710014430.sh new file mode 100644 index 0000000..e782e75 --- /dev/null +++ b/.history/py2c/run_20240710014430.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Read configuration file +CONFIG_FILE="config.json" +PYTHON_ENV=$(jq -r '.python_env' $CONFIG_FILE) +MODULE_NAME=$(jq -r '.module_name' $CONFIG_FILE) +FUNCTION_NAME=$(jq -r '.function_name' $CONFIG_FILE) +ARGS=$(jq -r '.args | join(" ")' $CONFIG_FILE) + + +# Update the include paths and the python module name +gcc runpython.c -I/Users/visheshyadav/anaconda3/include/python3.11 -L/Users/visheshyadav/anaconda3/lib -lpython3.11 -ldl -framework CoreFoundation +gcc runpython.c -I${PYTHON_PATH}/include/python3.11 -L${PYTHON_PATH}/lib -lpython3.11 -ldl -framework CoreFoundation + +# Ensure the current directory is in the python path +export PYTHONPATH=".:$PYTHONPATH" + +# Set the library path for the dynamic linker +export DYLD_LIBRARY_PATH="/Users/visheshyadav/anaconda3/lib:$DYLD_LIBRARY_PATH" + +# UNCOMMENT IT TO RUN OR, YOU CAN USE THE CONFIG FILE +# ./a.out mathUtils multiply 12 5 +./a.out mathUtils concat_sum_string 12 5 "Hello" +# ./a.out mathUtils process_data 1 2.5 "hello" "[1,2,3]" "{key:value}" + + +# ./a.out asyncUtils fetch_data "https://jsonplaceholder.typicode.com/todos/1" +# ./a.out asyncUtils fetch_multiple "https://jsonplaceholder.typicode.com/todos/1" "https://jsonplaceholder.typicode.com/todos/2" +# ./a.out asyncUtils post_data "https://jsonplaceholder.typicode.com/posts" "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}" +# ./a.out asyncUtils fetch_with_timeout "https://jsonplaceholder.typicode.com/todos/1" 5 + + + +# # Run the C program with arguments from the configuration file +# ./a.out $MODULE_NAME $FUNCTION_NAME $ARGS \ No newline at end of file diff --git a/.history/py2c/run_20240710014432.sh b/.history/py2c/run_20240710014432.sh new file mode 100644 index 0000000..37a864c --- /dev/null +++ b/.history/py2c/run_20240710014432.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Read configuration file +CONFIG_FILE="config.json" +PYTHON_ENV=$(jq -r '.python_env' $CONFIG_FILE) +MODULE_NAME=$(jq -r '.module_name' $CONFIG_FILE) +FUNCTION_NAME=$(jq -r '.function_name' $CONFIG_FILE) +ARGS=$(jq -r '.args | join(" ")' $CONFIG_FILE) + + +# Update the include paths and the python module name +# gcc runpython.c -I/Users/visheshyadav/anaconda3/include/python3.11 -L/Users/visheshyadav/anaconda3/lib -lpython3.11 -ldl -framework CoreFoundation +gcc runpython.c -I${PYTHON_PATH}/include/python3.11 -L${PYTHON_PATH}/lib -lpython3.11 -ldl -framework CoreFoundation + +# Ensure the current directory is in the python path +export PYTHONPATH=".:$PYTHONPATH" + +# Set the library path for the dynamic linker +export DYLD_LIBRARY_PATH="/Users/visheshyadav/anaconda3/lib:$DYLD_LIBRARY_PATH" + +# UNCOMMENT IT TO RUN OR, YOU CAN USE THE CONFIG FILE +# ./a.out mathUtils multiply 12 5 +./a.out mathUtils concat_sum_string 12 5 "Hello" +# ./a.out mathUtils process_data 1 2.5 "hello" "[1,2,3]" "{key:value}" + + +# ./a.out asyncUtils fetch_data "https://jsonplaceholder.typicode.com/todos/1" +# ./a.out asyncUtils fetch_multiple "https://jsonplaceholder.typicode.com/todos/1" "https://jsonplaceholder.typicode.com/todos/2" +# ./a.out asyncUtils post_data "https://jsonplaceholder.typicode.com/posts" "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}" +# ./a.out asyncUtils fetch_with_timeout "https://jsonplaceholder.typicode.com/todos/1" 5 + + + +# # Run the C program with arguments from the configuration file +# ./a.out $MODULE_NAME $FUNCTION_NAME $ARGS \ No newline at end of file diff --git a/.history/py2c/run_20240710014839.sh b/.history/py2c/run_20240710014839.sh new file mode 100644 index 0000000..94bfa1f --- /dev/null +++ b/.history/py2c/run_20240710014839.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Read configuration file +CONFIG_FILE="config.json" +PYTHON_ENV=$(jq -r '.python_env' $CONFIG_FILE) +MODULE_NAME=$(jq -r '.module_name' $CONFIG_FILE) +FUNCTION_NAME=$(jq -r '.function_name' $CONFIG_FILE) +ARGS=$(jq -r '.args | join(" ")' $CONFIG_FILE) + + +# Update the include paths and the python module name +# gcc runpython.c -I/Users/visheshyadav/anaconda3/include/python3.11 -L/Users/visheshyadav/anaconda3/lib -lpython3.11 -ldl -framework CoreFoundation +gcc runpython.c -I${PYTHON_PATH}/include/python3.11 -L${PYTHON_PATH}/lib -lpython3.11 -ldl -framework CoreFoundation + +# Ensure the current directory is in the python path +export PYTHONPATH=".:$PYTHONPATH" + +# Set the library path for the dynamic linker +export DYLD_LIBRARY_PATH="/Users/visheshyadav/anaconda3/lib:$DYLD_LIBRARY_PATH" + +# UNCOMMENT IT TO RUN OR, YOU CAN USE THE CONFIG FILE +# ./a.out mathUtils multiply 12 5 +# ./a.out mathUtils concat_sum_string 12 5 "Hello" +# ./a.out mathUtils process_data 1 2.5 "hello" "[1,2,3]" "{key:value}" + + +# ./a.out asyncUtils fetch_data "https://jsonplaceholder.typicode.com/todos/1" +# ./a.out asyncUtils fetch_multiple "https://jsonplaceholder.typicode.com/todos/1" "https://jsonplaceholder.typicode.com/todos/2" +# ./a.out asyncUtils post_data "https://jsonplaceholder.typicode.com/posts" "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}" +# ./a.out asyncUtils fetch_with_timeout "https://jsonplaceholder.typicode.com/todos/1" 5 + + + +# # Run the C program with arguments from the configuration file +# ./a.out $MODULE_NAME $FUNCTION_NAME $ARGS \ No newline at end of file diff --git a/.history/py2c/run_20240710014842.sh b/.history/py2c/run_20240710014842.sh new file mode 100644 index 0000000..27b01d9 --- /dev/null +++ b/.history/py2c/run_20240710014842.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Read configuration file +CONFIG_FILE="config.json" +PYTHON_ENV=$(jq -r '.python_env' $CONFIG_FILE) +MODULE_NAME=$(jq -r '.module_name' $CONFIG_FILE) +FUNCTION_NAME=$(jq -r '.function_name' $CONFIG_FILE) +ARGS=$(jq -r '.args | join(" ")' $CONFIG_FILE) + + +# Update the include paths and the python module name +# gcc runpython.c -I/Users/visheshyadav/anaconda3/include/python3.11 -L/Users/visheshyadav/anaconda3/lib -lpython3.11 -ldl -framework CoreFoundation +gcc runpython.c -I${PYTHON_PATH}/include/python3.11 -L${PYTHON_PATH}/lib -lpython3.11 -ldl -framework CoreFoundation + +# Ensure the current directory is in the python path +export PYTHONPATH=".:$PYTHONPATH" + +# Set the library path for the dynamic linker +export DYLD_LIBRARY_PATH="/Users/visheshyadav/anaconda3/lib:$DYLD_LIBRARY_PATH" + +# UNCOMMENT IT TO RUN OR, YOU CAN USE THE CONFIG FILE +# ./a.out mathUtils multiply 12 5 +# ./a.out mathUtils concat_sum_string 12 5 "Hello" +./a.out mathUtils process_data 1 2.5 "hello" "[1,2,3]" "{key:value}" + + +# ./a.out asyncUtils fetch_data "https://jsonplaceholder.typicode.com/todos/1" +# ./a.out asyncUtils fetch_multiple "https://jsonplaceholder.typicode.com/todos/1" "https://jsonplaceholder.typicode.com/todos/2" +# ./a.out asyncUtils post_data "https://jsonplaceholder.typicode.com/posts" "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}" +# ./a.out asyncUtils fetch_with_timeout "https://jsonplaceholder.typicode.com/todos/1" 5 + + + +# # Run the C program with arguments from the configuration file +# ./a.out $MODULE_NAME $FUNCTION_NAME $ARGS \ No newline at end of file diff --git a/.history/py2c/run_20240710014903.sh b/.history/py2c/run_20240710014903.sh new file mode 100644 index 0000000..ff1d22c --- /dev/null +++ b/.history/py2c/run_20240710014903.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Read configuration file +CONFIG_FILE="config.json" +PYTHON_ENV=$(jq -r '.python_env' $CONFIG_FILE) +MODULE_NAME=$(jq -r '.module_name' $CONFIG_FILE) +FUNCTION_NAME=$(jq -r '.function_name' $CONFIG_FILE) +ARGS=$(jq -r '.args | join(" ")' $CONFIG_FILE) + + +# Update the include paths and the python module name +# gcc runpython.c -I/Users/visheshyadav/anaconda3/include/python3.11 -L/Users/visheshyadav/anaconda3/lib -lpython3.11 -ldl -framework CoreFoundation +# gcc runpython.c -I${PYTHON_PATH}/include/python3.11 -L${PYTHON_PATH}/lib -lpython3.11 -ldl -framework CoreFoundation + +# Ensure the current directory is in the python path +export PYTHONPATH=".:$PYTHONPATH" + +# Set the library path for the dynamic linker +export DYLD_LIBRARY_PATH="/Users/visheshyadav/anaconda3/lib:$DYLD_LIBRARY_PATH" + +# UNCOMMENT IT TO RUN OR, YOU CAN USE THE CONFIG FILE +# ./a.out mathUtils multiply 12 5 +# ./a.out mathUtils concat_sum_string 12 5 "Hello" +./a.out mathUtils process_data 1 2.5 "hello" "[1,2,3]" "{key:value}" + + +# ./a.out asyncUtils fetch_data "https://jsonplaceholder.typicode.com/todos/1" +# ./a.out asyncUtils fetch_multiple "https://jsonplaceholder.typicode.com/todos/1" "https://jsonplaceholder.typicode.com/todos/2" +# ./a.out asyncUtils post_data "https://jsonplaceholder.typicode.com/posts" "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}" +# ./a.out asyncUtils fetch_with_timeout "https://jsonplaceholder.typicode.com/todos/1" 5 + + + +# # Run the C program with arguments from the configuration file +# ./a.out $MODULE_NAME $FUNCTION_NAME $ARGS \ No newline at end of file diff --git a/.history/py2c/run_20240710014904.sh b/.history/py2c/run_20240710014904.sh new file mode 100644 index 0000000..7681a1f --- /dev/null +++ b/.history/py2c/run_20240710014904.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Read configuration file +CONFIG_FILE="config.json" +PYTHON_ENV=$(jq -r '.python_env' $CONFIG_FILE) +MODULE_NAME=$(jq -r '.module_name' $CONFIG_FILE) +FUNCTION_NAME=$(jq -r '.function_name' $CONFIG_FILE) +ARGS=$(jq -r '.args | join(" ")' $CONFIG_FILE) + + +# Update the include paths and the python module name +gcc runpython.c -I/Users/visheshyadav/anaconda3/include/python3.11 -L/Users/visheshyadav/anaconda3/lib -lpython3.11 -ldl -framework CoreFoundation +# gcc runpython.c -I${PYTHON_PATH}/include/python3.11 -L${PYTHON_PATH}/lib -lpython3.11 -ldl -framework CoreFoundation + +# Ensure the current directory is in the python path +export PYTHONPATH=".:$PYTHONPATH" + +# Set the library path for the dynamic linker +export DYLD_LIBRARY_PATH="/Users/visheshyadav/anaconda3/lib:$DYLD_LIBRARY_PATH" + +# UNCOMMENT IT TO RUN OR, YOU CAN USE THE CONFIG FILE +# ./a.out mathUtils multiply 12 5 +# ./a.out mathUtils concat_sum_string 12 5 "Hello" +./a.out mathUtils process_data 1 2.5 "hello" "[1,2,3]" "{key:value}" + + +# ./a.out asyncUtils fetch_data "https://jsonplaceholder.typicode.com/todos/1" +# ./a.out asyncUtils fetch_multiple "https://jsonplaceholder.typicode.com/todos/1" "https://jsonplaceholder.typicode.com/todos/2" +# ./a.out asyncUtils post_data "https://jsonplaceholder.typicode.com/posts" "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}" +# ./a.out asyncUtils fetch_with_timeout "https://jsonplaceholder.typicode.com/todos/1" 5 + + + +# # Run the C program with arguments from the configuration file +# ./a.out $MODULE_NAME $FUNCTION_NAME $ARGS \ No newline at end of file diff --git a/.history/py2c/run_20240710014912.sh b/.history/py2c/run_20240710014912.sh new file mode 100644 index 0000000..ff1d22c --- /dev/null +++ b/.history/py2c/run_20240710014912.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Read configuration file +CONFIG_FILE="config.json" +PYTHON_ENV=$(jq -r '.python_env' $CONFIG_FILE) +MODULE_NAME=$(jq -r '.module_name' $CONFIG_FILE) +FUNCTION_NAME=$(jq -r '.function_name' $CONFIG_FILE) +ARGS=$(jq -r '.args | join(" ")' $CONFIG_FILE) + + +# Update the include paths and the python module name +# gcc runpython.c -I/Users/visheshyadav/anaconda3/include/python3.11 -L/Users/visheshyadav/anaconda3/lib -lpython3.11 -ldl -framework CoreFoundation +# gcc runpython.c -I${PYTHON_PATH}/include/python3.11 -L${PYTHON_PATH}/lib -lpython3.11 -ldl -framework CoreFoundation + +# Ensure the current directory is in the python path +export PYTHONPATH=".:$PYTHONPATH" + +# Set the library path for the dynamic linker +export DYLD_LIBRARY_PATH="/Users/visheshyadav/anaconda3/lib:$DYLD_LIBRARY_PATH" + +# UNCOMMENT IT TO RUN OR, YOU CAN USE THE CONFIG FILE +# ./a.out mathUtils multiply 12 5 +# ./a.out mathUtils concat_sum_string 12 5 "Hello" +./a.out mathUtils process_data 1 2.5 "hello" "[1,2,3]" "{key:value}" + + +# ./a.out asyncUtils fetch_data "https://jsonplaceholder.typicode.com/todos/1" +# ./a.out asyncUtils fetch_multiple "https://jsonplaceholder.typicode.com/todos/1" "https://jsonplaceholder.typicode.com/todos/2" +# ./a.out asyncUtils post_data "https://jsonplaceholder.typicode.com/posts" "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}" +# ./a.out asyncUtils fetch_with_timeout "https://jsonplaceholder.typicode.com/todos/1" 5 + + + +# # Run the C program with arguments from the configuration file +# ./a.out $MODULE_NAME $FUNCTION_NAME $ARGS \ No newline at end of file diff --git a/.history/py2c/run_20240710014916.sh b/.history/py2c/run_20240710014916.sh new file mode 100644 index 0000000..1c529f0 --- /dev/null +++ b/.history/py2c/run_20240710014916.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Read configuration file +CONFIG_FILE="config.json" +PYTHON_ENV=$(jq -r '.python_env' $CONFIG_FILE) +MODULE_NAME=$(jq -r '.module_name' $CONFIG_FILE) +FUNCTION_NAME=$(jq -r '.function_name' $CONFIG_FILE) +ARGS=$(jq -r '.args | join(" ")' $CONFIG_FILE) + + +# Update the include paths and the python module name +# gcc runpython.c -I${PYTHON_PATH}/include/python3.11 -L${PYTHON_PATH}/lib -lpython3.11 -ldl -framework CoreFoundation + +# Ensure the current directory is in the python path +export PYTHONPATH=".:$PYTHONPATH" + +# Set the library path for the dynamic linker +export DYLD_LIBRARY_PATH="/Users/visheshyadav/anaconda3/lib:$DYLD_LIBRARY_PATH" + +# UNCOMMENT IT TO RUN OR, YOU CAN USE THE CONFIG FILE +# ./a.out mathUtils multiply 12 5 +# ./a.out mathUtils concat_sum_string 12 5 "Hello" +./a.out mathUtils process_data 1 2.5 "hello" "[1,2,3]" "{key:value}" + + +# ./a.out asyncUtils fetch_data "https://jsonplaceholder.typicode.com/todos/1" +# ./a.out asyncUtils fetch_multiple "https://jsonplaceholder.typicode.com/todos/1" "https://jsonplaceholder.typicode.com/todos/2" +# ./a.out asyncUtils post_data "https://jsonplaceholder.typicode.com/posts" "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}" +# ./a.out asyncUtils fetch_with_timeout "https://jsonplaceholder.typicode.com/todos/1" 5 + + + +# # Run the C program with arguments from the configuration file +# ./a.out $MODULE_NAME $FUNCTION_NAME $ARGS \ No newline at end of file diff --git a/.history/py2c/run_20240710014919.sh b/.history/py2c/run_20240710014919.sh new file mode 100644 index 0000000..81a4d80 --- /dev/null +++ b/.history/py2c/run_20240710014919.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Read configuration file +CONFIG_FILE="config.json" +PYTHON_ENV=$(jq -r '.python_env' $CONFIG_FILE) +MODULE_NAME=$(jq -r '.module_name' $CONFIG_FILE) +FUNCTION_NAME=$(jq -r '.function_name' $CONFIG_FILE) +ARGS=$(jq -r '.args | join(" ")' $CONFIG_FILE) + + +# Update the include paths and the python module name +gcc runpython.c -I${PYTHON_PATH}/include/python3.11 -L${PYTHON_PATH}/lib -lpython3.11 -ldl -framework CoreFoundation + +# Ensure the current directory is in the python path +export PYTHONPATH=".:$PYTHONPATH" + +# Set the library path for the dynamic linker +export DYLD_LIBRARY_PATH="/Users/visheshyadav/anaconda3/lib:$DYLD_LIBRARY_PATH" + +# UNCOMMENT IT TO RUN OR, YOU CAN USE THE CONFIG FILE +# ./a.out mathUtils multiply 12 5 +# ./a.out mathUtils concat_sum_string 12 5 "Hello" +./a.out mathUtils process_data 1 2.5 "hello" "[1,2,3]" "{key:value}" + + +# ./a.out asyncUtils fetch_data "https://jsonplaceholder.typicode.com/todos/1" +# ./a.out asyncUtils fetch_multiple "https://jsonplaceholder.typicode.com/todos/1" "https://jsonplaceholder.typicode.com/todos/2" +# ./a.out asyncUtils post_data "https://jsonplaceholder.typicode.com/posts" "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}" +# ./a.out asyncUtils fetch_with_timeout "https://jsonplaceholder.typicode.com/todos/1" 5 + + + +# # Run the C program with arguments from the configuration file +# ./a.out $MODULE_NAME $FUNCTION_NAME $ARGS \ No newline at end of file diff --git a/.history/py2c/run_20240710015002.sh b/.history/py2c/run_20240710015002.sh new file mode 100644 index 0000000..dabb65c --- /dev/null +++ b/.history/py2c/run_20240710015002.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Read configuration file +CONFIG_FILE="config.json" +PYTHON_ENV=$(jq -r '.python_env' $CONFIG_FILE) +MODULE_NAME=$(jq -r '.module_name' $CONFIG_FILE) +FUNCTION_NAME=$(jq -r '.function_name' $CONFIG_FILE) +ARGS=$(jq -r '.args | join(" ")' $CONFIG_FILE) + +# Find the current Python path +PYTHON_PATH=$(dirname $(dirname $(which python))) + +# Update the include paths and the python module name +gcc runpython.c -I${PYTHON_PATH}/include/python3.11 -L${PYTHON_PATH}/lib -lpython3.11 -ldl -framework CoreFoundation + +# Ensure the current directory is in the python path +export PYTHONPATH=".:$PYTHONPATH" + +# Set the library path for the dynamic linker +export DYLD_LIBRARY_PATH="/Users/visheshyadav/anaconda3/lib:$DYLD_LIBRARY_PATH" + +# UNCOMMENT IT TO RUN OR, YOU CAN USE THE CONFIG FILE +# ./a.out mathUtils multiply 12 5 +# ./a.out mathUtils concat_sum_string 12 5 "Hello" +./a.out mathUtils process_data 1 2.5 "hello" "[1,2,3]" "{key:value}" + + +# ./a.out asyncUtils fetch_data "https://jsonplaceholder.typicode.com/todos/1" +# ./a.out asyncUtils fetch_multiple "https://jsonplaceholder.typicode.com/todos/1" "https://jsonplaceholder.typicode.com/todos/2" +# ./a.out asyncUtils post_data "https://jsonplaceholder.typicode.com/posts" "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}" +# ./a.out asyncUtils fetch_with_timeout "https://jsonplaceholder.typicode.com/todos/1" 5 + + + +# # Run the C program with arguments from the configuration file +# ./a.out $MODULE_NAME $FUNCTION_NAME $ARGS \ No newline at end of file diff --git a/.history/py2c/runpython_20240704011237.c b/.history/py2c/runpython_20240704011237.c new file mode 100644 index 0000000..18755ed --- /dev/null +++ b/.history/py2c/runpython_20240704011237.c @@ -0,0 +1,235 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + PyObject *pName, *pModule, *pDict, *pFunc; + PyObject *pArgs, *pValue; + int i; + + if (argc < 4) { + fprintf(stderr, "Usage: %s [args]\n", argv[0]); + return 1; + } + + // Initialize the Python interpreter + if (Py_IsInitialized() == 0) { + Py_Initialize(); + if (!Py_IsInitialized()) { + fprintf(stderr, "Failed to initialize Python interpreter\n"); + return 1; + } + } + + // Import the module + pName = PyUnicode_DecodeFSDefault(argv[1]); + if (pName == NULL) { + PyErr_Print(); + fprintf(stderr, "Failed to decode module name\n"); + Py_Finalize(); + return 1; + } + + pModule = PyImport_Import(pName); + Py_DECREF(pName); + if (pModule == NULL) { + PyErr_Print(); + fprintf(stderr, "Failed to load module \"%s\"\n", argv[1]); + Py_Finalize(); + return 1; + } + + // Get the function from the module + pDict = PyModule_GetDict(pModule); + if (pDict == NULL) { + PyErr_Print(); + fprintf(stderr, "Failed to get module dictionary\n"); + Py_DECREF(pModule); + Py_Finalize(); + return 1; + } + + pFunc = PyObject_GetAttrString(pModule, argv[2]); + if (pFunc == NULL || !PyCallable_Check(pFunc)) { + if (PyErr_Occurred()) { + PyErr_Print(); + } + fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]); + Py_XDECREF(pFunc); + Py_DECREF(pModule); + Py_Finalize(); + return 1; + } + + // Build the argument tuple to handle strings, ints, floats, lists, dictionaries, and tuples + pArgs = PyTuple_New(argc - 3); + for (i = 0; i < argc - 3; ++i) { + char *arg = argv[i + 3]; + if (isdigit(arg[0]) || (arg[0] == '-' && isdigit(arg[1]))) { + // Check if the argument is an integer + pValue = PyLong_FromLong(atol(arg)); + } else if (strchr(arg, '.')) { + // Check if the argument is a float + pValue = PyFloat_FromDouble(atof(arg)); + } else if (arg[0] == '[' && arg[strlen(arg) - 1] == ']') { + // Check if the argument is a list + pValue = PyList_New(0); + char *token = strtok(arg + 1, ","); + while (token != NULL) { + PyObject *item = PyUnicode_FromString(token); + PyList_Append(pValue, item); + Py_DECREF(item); + token = strtok(NULL, ","); + } + } else if (arg[0] == '{' && arg[strlen(arg) - 1] == '}') { + // Check if the argument is a dictionary + pValue = PyDict_New(); + char *token = strtok(arg + 1, ","); + while (token != NULL) { + char *key = strtok(token, ":"); + char *value = strtok(NULL, ":"); + PyObject *pyKey = PyUnicode_FromString(key); + PyObject *pyValue = PyUnicode_FromString(value); + PyDict_SetItem(pValue, pyKey, pyValue); + Py_DECREF(pyKey); + Py_DECREF(pyValue); + token = strtok(NULL, ","); + } + } else if (arg[0] == '(' && arg[strlen(arg) - 1] == ')') { + // Check if the argument is a tuple + pValue = PyTuple_New(0); + char *token = strtok(arg + 1, ","); + int j = 0; + while (token != NULL) { + PyObject *item = PyUnicode_FromString(token); + PyTuple_SetItem(pValue, j++, item); + token = strtok(NULL, ","); + } + } else { + // Treat the argument as a string + pValue = PyUnicode_FromString(arg); + } + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + Py_XDECREF(pFunc); + PyErr_Print(); + fprintf(stderr, "Cannot convert argument\n"); + Py_Finalize(); + return 1; + } + PyTuple_SetItem(pArgs, i, pValue); + } + + // Measure the start time + clock_t start_time = clock(); + + // Check if the function is a coroutine + if (PyCoro_CheckExact(pFunc)) { + // Import asyncio module + PyObject *asyncio = PyImport_ImportModule("asyncio"); + if (asyncio == NULL) { + PyErr_Print(); + fprintf(stderr, "Failed to import asyncio module\n"); + Py_DECREF(pArgs); + Py_DECREF(pModule); + Py_XDECREF(pFunc); + Py_Finalize(); + return 1; + } + + // Get asyncio.run function + PyObject *asyncio_run = PyObject_GetAttrString(asyncio, "run"); + Py_DECREF(asyncio); + if (asyncio_run == NULL) { + PyErr_Print(); + fprintf(stderr, "Failed to get asyncio.run function\n"); + Py_DECREF(pArgs); + Py_DECREF(pModule); + Py_XDECREF(pFunc); + Py_Finalize(); + return 1; + } + + // Call the coroutine using asyncio.run + PyObject *coroutine = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + if (coroutine == NULL) { + PyErr_Print(); + fprintf(stderr, "Failed to create coroutine\n"); + Py_DECREF(asyncio_run); + Py_DECREF(pModule); + Py_XDECREF(pFunc); + Py_Finalize(); + return 1; + } + + pValue = PyObject_CallFunctionObjArgs(asyncio_run, coroutine, NULL); + Py_DECREF(coroutine); + Py_DECREF(asyncio_run); + } else { + // Call the function + pValue = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + } + + // Measure the end time + clock_t end_time = clock(); + double time_spent = (double)(end_time - start_time) / CLOCKS_PER_SEC; + printf("Execution time: %f seconds\n", time_spent); + + if (pValue != NULL) { + if (PyLong_Check(pValue)) { + long result = PyLong_AsLong(pValue); + printf("Result of call (int): %ld\n", result); + } else if (PyFloat_Check(pValue)) { + double result = PyFloat_AsDouble(pValue); + printf("Result of call (float): %f\n", result); + } else if (PyUnicode_Check(pValue)) { + const char *result = PyUnicode_AsUTF8(pValue); + printf("Result of call (string): %s\n", result); + } else if (PyList_Check(pValue)) { + printf("Result of call (list):\n"); + for (Py_ssize_t i = 0; i < PyList_Size(pValue); i++) { + PyObject *item = PyList_GetItem(pValue, i); + PyObject *str_item = PyObject_Str(item); + const char *str = PyUnicode_AsUTF8(str_item); + printf(" %s\n", str); + Py_DECREF(str_item); + } + } else if (PyDict_Check(pValue)) { + printf("Result of call (dict):\n"); + PyObject *key, *value; + Py_ssize_t pos = 0; + while (PyDict_Next(pValue, &pos, &key, &value)) { + PyObject *str_key = PyObject_Str(key); + PyObject *str_value = PyObject_Str(value); + const char *str_k = PyUnicode_AsUTF8(str_key); + const char *str_v = PyUnicode_AsUTF8(str_value); + printf(" %s: %s\n", str_k, str_v); + Py_DECREF(str_key); + Py_DECREF(str_value); + } + } else { + printf("Error: Function returned an unsupported type\n"); + } + Py_DECREF(pValue); + } else { + PyErr_Print(); + fprintf(stderr, "Call failed\n"); + } + + // Clean up + Py_XDECREF(pFunc); + Py_DECREF(pModule); + + // Finalize the Python interpreter + if (Py_FinalizeEx() < 0) { + return 120; + } + + return 0; +} \ No newline at end of file diff --git a/.history/py2c/runpython_20240710015306.c b/.history/py2c/runpython_20240710015306.c new file mode 100644 index 0000000..5806264 --- /dev/null +++ b/.history/py2c/runpython_20240710015306.c @@ -0,0 +1,283 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + PyObject *pName, *pModule, *pDict, *pFunc; + PyObject *pArgs, *pValue; + int i; + + if (argc < 4) + { + fprintf(stderr, "Usage: %s [args]\n", argv[0]); + return 1; + } + + // Initialize the Python interpreter + if (Py_IsInitialized() == 0) + { + Py_Initialize(); + if (!Py_IsInitialized()) + { + fprintf(stderr, "Failed to initialize Python interpreter\n"); + return 1; + } + } + + // Import the module + pName = PyUnicode_DecodeFSDefault(argv[1]); + if (pName == NULL) + { + PyErr_Print(); + fprintf(stderr, "Failed to decode module name\n"); + Py_Finalize(); + return 1; + } + + pModule = PyImport_Import(pName); + Py_DECREF(pName); + if (pModule == NULL) + { + PyErr_Print(); + fprintf(stderr, "Failed to load module \"%s\"\n", argv[1]); + Py_Finalize(); + return 1; + } + + // Get the function from the module + pDict = PyModule_GetDict(pModule); + if (pDict == NULL) + { + PyErr_Print(); + fprintf(stderr, "Failed to get module dictionary\n"); + Py_DECREF(pModule); + Py_Finalize(); + return 1; + } + + pFunc = PyObject_GetAttrString(pModule, argv[2]); + if (pFunc == NULL || !PyCallable_Check(pFunc)) + { + if (PyErr_Occurred()) + { + PyErr_Print(); + } + fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]); + Py_XDECREF(pFunc); + Py_DECREF(pModule); + Py_Finalize(); + return 1; + } + + // Build the argument tuple to handle strings, ints, floats, lists, dictionaries, and tuples + pArgs = PyTuple_New(argc - 3); + for (i = 0; i < argc - 3; ++i) + { + char *arg = argv[i + 3]; + if (isdigit(arg[0]) || (arg[0] == '-' && isdigit(arg[1]))) + { + // Check if the argument is an integer + pValue = PyLong_FromLong(atol(arg)); + } + else if (strchr(arg, '.')) + { + // Check if the argument is a float + pValue = PyFloat_FromDouble(atof(arg)); + } + else if (arg[0] == '[' && arg[strlen(arg) - 1] == ']') + { + // Check if the argument is a list + pValue = PyList_New(0); + char *token = strtok(arg + 1, ","); + while (token != NULL) + { + PyObject *item = PyUnicode_FromString(token); + PyList_Append(pValue, item); + Py_DECREF(item); + token = strtok(NULL, ","); + } + } + else if (arg[0] == '{' && arg[strlen(arg) - 1] == '}') + { + // Check if the argument is a dictionary + pValue = PyDict_New(); + char *token = strtok(arg + 1, ","); + while (token != NULL) + { + char *key = strtok(token, ":"); + char *value = strtok(NULL, ":"); + PyObject *pyKey = PyUnicode_FromString(key); + PyObject *pyValue = PyUnicode_FromString(value); + PyDict_SetItem(pValue, pyKey, pyValue); + Py_DECREF(pyKey); + Py_DECREF(pyValue); + token = strtok(NULL, ","); + } + } + else if (arg[0] == '(' && arg[strlen(arg) - 1] == ')') + { + // Check if the argument is a tuple + pValue = PyTuple_New(0); + char *token = strtok(arg + 1, ","); + int j = 0; + while (token != NULL) + { + PyObject *item = PyUnicode_FromString(token); + PyTuple_SetItem(pValue, j++, item); + token = strtok(NULL, ","); + } + } + else + { + // Treat the argument as a string + pValue = PyUnicode_FromString(arg); + } + if (!pValue) + { + Py_DECREF(pArgs); + Py_DECREF(pModule); + Py_XDECREF(pFunc); + PyErr_Print(); + fprintf(stderr, "Cannot convert argument\n"); + Py_Finalize(); + return 1; + } + PyTuple_SetItem(pArgs, i, pValue); + } + + // Measure the start time + clock_t start_time = clock(); + + // Check if the function is a coroutine + if (PyCoro_CheckExact(pFunc)) + { + // Import asyncio module + PyObject *asyncio = PyImport_ImportModule("asyncio"); + if (asyncio == NULL) + { + PyErr_Print(); + fprintf(stderr, "Failed to import asyncio module\n"); + Py_DECREF(pArgs); + Py_DECREF(pModule); + Py_XDECREF(pFunc); + Py_Finalize(); + return 1; + } + + // Get asyncio.run function + PyObject *asyncio_run = PyObject_GetAttrString(asyncio, "run"); + Py_DECREF(asyncio); + if (asyncio_run == NULL) + { + PyErr_Print(); + fprintf(stderr, "Failed to get asyncio.run function\n"); + Py_DECREF(pArgs); + Py_DECREF(pModule); + Py_XDECREF(pFunc); + Py_Finalize(); + return 1; + } + + // Call the coroutine using asyncio.run + PyObject *coroutine = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + if (coroutine == NULL) + { + PyErr_Print(); + fprintf(stderr, "Failed to create coroutine\n"); + Py_DECREF(asyncio_run); + Py_DECREF(pModule); + Py_XDECREF(pFunc); + Py_Finalize(); + return 1; + } + + pValue = PyObject_CallFunctionObjArgs(asyncio_run, coroutine, NULL); + Py_DECREF(coroutine); + Py_DECREF(asyncio_run); + } + else + { + // Call the function + pValue = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + } + + // Measure the end time + clock_t end_time = clock(); + double time_spent = (double)(end_time - start_time) / CLOCKS_PER_SEC; + printf("Execution time: %f seconds\n", time_spent); + + if (pValue != NULL) + { + if (PyLong_Check(pValue)) + { + long result = PyLong_AsLong(pValue); + printf("Result of call (int): %ld\n", result); + } + else if (PyFloat_Check(pValue)) + { + double result = PyFloat_AsDouble(pValue); + printf("Result of call (float): %f\n", result); + } + else if (PyUnicode_Check(pValue)) + { + const char *result = PyUnicode_AsUTF8(pValue); + printf("Result of call (string): %s\n", result); + } + else if (PyList_Check(pValue)) + { + printf("Result of call (list):\n"); + for (Py_ssize_t i = 0; i < PyList_Size(pValue); i++) + { + PyObject *item = PyList_GetItem(pValue, i); + PyObject *str_item = PyObject_Str(item); + const char *str = PyUnicode_AsUTF8(str_item); + printf(" %s\n", str); + Py_DECREF(str_item); + } + } + else if (PyDict_Check(pValue)) + { + printf("Result of call (dict):\n"); + PyObject *key, *value; + Py_ssize_t pos = 0; + while (PyDict_Next(pValue, &pos, &key, &value)) + { + PyObject *str_key = PyObject_Str(key); + PyObject *str_value = PyObject_Str(value); + const char *str_k = PyUnicode_AsUTF8(str_key); + const char *str_v = PyUnicode_AsUTF8(str_value); + printf(" %s: %s\n", str_k, str_v); + Py_DECREF(str_key); + Py_DECREF(str_value); + } + } + else + { + printf("Error: Function returned an unsupported type\n"); + } + Py_DECREF(pValue); + } + else + { + PyErr_Print(); + fprintf(stderr, "Call failed\n"); + } + + // Clean up + Py_XDECREF(pFunc); + Py_DECREF(pModule); + + // Finalize the Python interpreter + if (Py_FinalizeEx() < 0) + { + return 120; + } + + return 0; +} \ No newline at end of file diff --git a/py2c/README.md b/py2c/README.md index 15ad41e..e38cf9c 100644 --- a/py2c/README.md +++ b/py2c/README.md @@ -1,12 +1,17 @@ # Python to C++ interface -Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situataion. +Using the following instructions you can call your **existing Python modules** from C/C++. I'm using Pure Embedding instructions taken from [here](https://docs.python.org/release/3.5.5/extending/embedding.html#pure-embedding). This is not a general solution and needs a little bit more work, but using this example code you can run any Python function from C/C++ and even pass arguments (only supports integer values). Hopefully you can adapt it to your situation. +## Prerequisites + +- `jq` is required. You can install it from [here](https://stedolan.github.io/jq/download/). ## Runnable script + Using the `run.sh` script, the `runpython.c` code calls the `multiply` function from the `mathUtils.py` module and gets back the results. you can play around with the last command and call your own Python modules in the following way: + ```bash ./a.out ``` -To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. \ No newline at end of file +To integrate this into your own program, you can use `runpython.c` as a template, but need to handle your Python object in C using `PyObject`. This can represent any Python object, but doing it is needs some coding. Please refer to [Python/C Api Reference Manual](https://docs.python.org/release/3.5.5/c-api/index.html#c-api-index) for more information on how to do this. diff --git a/py2c/asyncUtils.py b/py2c/asyncUtils.py new file mode 100644 index 0000000..dd4f608 --- /dev/null +++ b/py2c/asyncUtils.py @@ -0,0 +1,25 @@ +import asyncio +import aiohttp + +async def fetch_data(url): + async with aiohttp.ClientSession() as session: + async with session.get(url) as response: + return await response.text() + +async def fetch_multiple(urls): + async with aiohttp.ClientSession() as session: + tasks = [fetch_data(url) for url in urls] + return await asyncio.gather(*tasks) + +async def post_data(url, data): + async with aiohttp.ClientSession() as session: + async with session.post(url, json=data) as response: + return await response.text() + +async def fetch_with_timeout(url, timeout): + async with aiohttp.ClientSession() as session: + try: + async with session.get(url, timeout=timeout) as response: + return await response.text() + except asyncio.TimeoutError: + return "Request timed out" diff --git a/py2c/config.json b/py2c/config.json new file mode 100644 index 0000000..ff82895 --- /dev/null +++ b/py2c/config.json @@ -0,0 +1,6 @@ +{ + "python_env": "/Users/visheshyadav/anaconda3", + "module_name": "mathUtils", + "function_name": "process_data", + "args": [1, 2.5, "hello", "[1,2,3]", "{key:value}"] +} \ No newline at end of file diff --git a/py2c/mathUtils.py b/py2c/mathUtils.py index 0555ae6..5952228 100644 --- a/py2c/mathUtils.py +++ b/py2c/mathUtils.py @@ -1,6 +1,14 @@ -def multiply(a,b): - print("Will compute", a, "times", b) - c = 0 - for i in range(0, a): - c = c + b - return c \ No newline at end of file +# Example usage for process_data for testing the data types +# more examples on module/test_mathUtils.py +def process_data(a, b, c, d, e): + print(f"Integer: {a}") + print(f"Float: {b}") + print(f"String: {c}") + print(f"List: {d}") + print(f"Dictionary: {e}") + return a + int(b) # Just a simple return for demonstration + + +if __name__ == "__main__": + result = process_data(1, 2.5, "hello", [1, 2, 3], {"key": "value"}) + print(f"Result: {result}") \ No newline at end of file diff --git a/py2c/module/function/configs.txt b/py2c/module/function/configs.txt new file mode 100644 index 0000000..d4ad178 --- /dev/null +++ b/py2c/module/function/configs.txt @@ -0,0 +1,32 @@ + +# config for fetch_data +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_data", +# "args": ["https://jsonplaceholder.typicode.com/todos/1"] +# } + +# config for fetch_multiple +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_multiple", +# "args": [["https://jsonplaceholder.typicode.com/todos/1", "https://jsonplaceholder.typicode.com/todos/2"]] +# } + +# config for post_data +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "post_data", +# "args": ["https://jsonplaceholder.typicode.com/posts", {"title": "foo", "body": "bar", "userId": 1}] +# } + +# config for fetch_with_timeout +# { +# "python_env": "/Users/visheshyadav/anaconda3", +# "module_name": "asyncUtils", +# "function_name": "fetch_with_timeout", +# "args": ["https://jsonplaceholder.typicode.com/todos/1", 5] +# } \ No newline at end of file diff --git a/py2c/module/tests/test_mathUtils.py b/py2c/module/tests/test_mathUtils.py new file mode 100644 index 0000000..3d0156c --- /dev/null +++ b/py2c/module/tests/test_mathUtils.py @@ -0,0 +1,62 @@ +def two_sum(nums, target): + """ + Find two numbers in the list that add up to the target. + + Args: + nums (list): List of integers. + target (int): Target sum. + + Returns: + list: Indices of the two numbers that add up to the target. + """ + # Create a dictionary to store the complement and its index + num_to_index = {} + + # Iterate over the list of numbers + for index, num in enumerate(nums): + # Calculate the complement + complement = target - num + + # Check if the complement is already in the dictionary + if complement in num_to_index: + # If found, return the indices of the two numbers + return [num_to_index[complement], index] + + # Otherwise, add the number and its index to the dictionary + num_to_index[num] = index + + # If no solution is found, return an empty list + return [] + +def multiply(a, b): + """ + Multiply two numbers. + + Args: + a (int): First number. + b (int): Second number. + + Returns: + int: Product of the two numbers. + """ + return a * b + +def concat_sum_string(a, b, s): + """ + Concatenate a string with the sum of two numbers. + + Args: + a (str): First number as a string. + b (str): Second number as a string. + s (str): String to concatenate with the sum. + + Returns: + int: Sum of the two numbers if valid, otherwise None. + """ + try: + result = int(a) + int(b) + print(f"{s}: {result}") + return result + except ValueError: + print("Error: Invalid input") + return None \ No newline at end of file diff --git a/py2c/run.sh b/py2c/run.sh index a42a9f2..dabb65c 100755 --- a/py2c/run.sh +++ b/py2c/run.sh @@ -1,10 +1,36 @@ #!/bin/bash -# the include paths and the python module name might be different -# use `locate libpython` to locate the library and `locate include/python` for include path -gcc runpython.c -I/usr/include/python3.5 -lpython3.5m +# Read configuration file +CONFIG_FILE="config.json" +PYTHON_ENV=$(jq -r '.python_env' $CONFIG_FILE) +MODULE_NAME=$(jq -r '.module_name' $CONFIG_FILE) +FUNCTION_NAME=$(jq -r '.function_name' $CONFIG_FILE) +ARGS=$(jq -r '.args | join(" ")' $CONFIG_FILE) +# Find the current Python path +PYTHON_PATH=$(dirname $(dirname $(which python))) -# not sure why, but the current directory is not in the python path when you run this +# Update the include paths and the python module name +gcc runpython.c -I${PYTHON_PATH}/include/python3.11 -L${PYTHON_PATH}/lib -lpython3.11 -ldl -framework CoreFoundation + +# Ensure the current directory is in the python path export PYTHONPATH=".:$PYTHONPATH" -./a.out mathUtils multiply 12 5 + +# Set the library path for the dynamic linker +export DYLD_LIBRARY_PATH="/Users/visheshyadav/anaconda3/lib:$DYLD_LIBRARY_PATH" + +# UNCOMMENT IT TO RUN OR, YOU CAN USE THE CONFIG FILE +# ./a.out mathUtils multiply 12 5 +# ./a.out mathUtils concat_sum_string 12 5 "Hello" +./a.out mathUtils process_data 1 2.5 "hello" "[1,2,3]" "{key:value}" + + +# ./a.out asyncUtils fetch_data "https://jsonplaceholder.typicode.com/todos/1" +# ./a.out asyncUtils fetch_multiple "https://jsonplaceholder.typicode.com/todos/1" "https://jsonplaceholder.typicode.com/todos/2" +# ./a.out asyncUtils post_data "https://jsonplaceholder.typicode.com/posts" "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}" +# ./a.out asyncUtils fetch_with_timeout "https://jsonplaceholder.typicode.com/todos/1" 5 + + + +# # Run the C program with arguments from the configuration file +# ./a.out $MODULE_NAME $FUNCTION_NAME $ARGS \ No newline at end of file diff --git a/py2c/runpython.c b/py2c/runpython.c index 999e76f..5806264 100644 --- a/py2c/runpython.c +++ b/py2c/runpython.c @@ -1,21 +1,28 @@ #include #include #include +#include +#include +#include -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; - if (argc < 4) { - fprintf(stderr, "Usage: %s pythonfile funcname [args]\n", argv[0]); + if (argc < 4) + { + fprintf(stderr, "Usage: %s [args]\n", argv[0]); return 1; } // Initialize the Python interpreter - if (Py_IsInitialized() == 0) { + if (Py_IsInitialized() == 0) + { Py_Initialize(); - if (!Py_IsInitialized()) { + if (!Py_IsInitialized()) + { fprintf(stderr, "Failed to initialize Python interpreter\n"); return 1; } @@ -23,7 +30,8 @@ int main(int argc, char *argv[]) { // Import the module pName = PyUnicode_DecodeFSDefault(argv[1]); - if (pName == NULL) { + if (pName == NULL) + { PyErr_Print(); fprintf(stderr, "Failed to decode module name\n"); Py_Finalize(); @@ -32,7 +40,8 @@ int main(int argc, char *argv[]) { pModule = PyImport_Import(pName); Py_DECREF(pName); - if (pModule == NULL) { + if (pModule == NULL) + { PyErr_Print(); fprintf(stderr, "Failed to load module \"%s\"\n", argv[1]); Py_Finalize(); @@ -41,7 +50,8 @@ int main(int argc, char *argv[]) { // Get the function from the module pDict = PyModule_GetDict(pModule); - if (pDict == NULL) { + if (pDict == NULL) + { PyErr_Print(); fprintf(stderr, "Failed to get module dictionary\n"); Py_DECREF(pModule); @@ -50,8 +60,10 @@ int main(int argc, char *argv[]) { } pFunc = PyObject_GetAttrString(pModule, argv[2]); - if (pFunc == NULL || !PyCallable_Check(pFunc)) { - if (PyErr_Occurred()) { + if (pFunc == NULL || !PyCallable_Check(pFunc)) + { + if (PyErr_Occurred()) + { PyErr_Print(); } fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]); @@ -61,11 +73,71 @@ int main(int argc, char *argv[]) { return 1; } - // Build the argument tuple + // Build the argument tuple to handle strings, ints, floats, lists, dictionaries, and tuples pArgs = PyTuple_New(argc - 3); - for (i = 0; i < argc - 3; ++i) { - pValue = PyLong_FromLong(atol(argv[i + 3])); - if (!pValue) { + for (i = 0; i < argc - 3; ++i) + { + char *arg = argv[i + 3]; + if (isdigit(arg[0]) || (arg[0] == '-' && isdigit(arg[1]))) + { + // Check if the argument is an integer + pValue = PyLong_FromLong(atol(arg)); + } + else if (strchr(arg, '.')) + { + // Check if the argument is a float + pValue = PyFloat_FromDouble(atof(arg)); + } + else if (arg[0] == '[' && arg[strlen(arg) - 1] == ']') + { + // Check if the argument is a list + pValue = PyList_New(0); + char *token = strtok(arg + 1, ","); + while (token != NULL) + { + PyObject *item = PyUnicode_FromString(token); + PyList_Append(pValue, item); + Py_DECREF(item); + token = strtok(NULL, ","); + } + } + else if (arg[0] == '{' && arg[strlen(arg) - 1] == '}') + { + // Check if the argument is a dictionary + pValue = PyDict_New(); + char *token = strtok(arg + 1, ","); + while (token != NULL) + { + char *key = strtok(token, ":"); + char *value = strtok(NULL, ":"); + PyObject *pyKey = PyUnicode_FromString(key); + PyObject *pyValue = PyUnicode_FromString(value); + PyDict_SetItem(pValue, pyKey, pyValue); + Py_DECREF(pyKey); + Py_DECREF(pyValue); + token = strtok(NULL, ","); + } + } + else if (arg[0] == '(' && arg[strlen(arg) - 1] == ')') + { + // Check if the argument is a tuple + pValue = PyTuple_New(0); + char *token = strtok(arg + 1, ","); + int j = 0; + while (token != NULL) + { + PyObject *item = PyUnicode_FromString(token); + PyTuple_SetItem(pValue, j++, item); + token = strtok(NULL, ","); + } + } + else + { + // Treat the argument as a string + pValue = PyUnicode_FromString(arg); + } + if (!pValue) + { Py_DECREF(pArgs); Py_DECREF(pModule); Py_XDECREF(pFunc); @@ -77,19 +149,124 @@ int main(int argc, char *argv[]) { PyTuple_SetItem(pArgs, i, pValue); } - // Call the function - pValue = PyObject_CallObject(pFunc, pArgs); - Py_DECREF(pArgs); - if (pValue != NULL) { - printf("Result of call: %ld\n", PyLong_AsLong(pValue)); + // Measure the start time + clock_t start_time = clock(); + + // Check if the function is a coroutine + if (PyCoro_CheckExact(pFunc)) + { + // Import asyncio module + PyObject *asyncio = PyImport_ImportModule("asyncio"); + if (asyncio == NULL) + { + PyErr_Print(); + fprintf(stderr, "Failed to import asyncio module\n"); + Py_DECREF(pArgs); + Py_DECREF(pModule); + Py_XDECREF(pFunc); + Py_Finalize(); + return 1; + } + + // Get asyncio.run function + PyObject *asyncio_run = PyObject_GetAttrString(asyncio, "run"); + Py_DECREF(asyncio); + if (asyncio_run == NULL) + { + PyErr_Print(); + fprintf(stderr, "Failed to get asyncio.run function\n"); + Py_DECREF(pArgs); + Py_DECREF(pModule); + Py_XDECREF(pFunc); + Py_Finalize(); + return 1; + } + + // Call the coroutine using asyncio.run + PyObject *coroutine = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + if (coroutine == NULL) + { + PyErr_Print(); + fprintf(stderr, "Failed to create coroutine\n"); + Py_DECREF(asyncio_run); + Py_DECREF(pModule); + Py_XDECREF(pFunc); + Py_Finalize(); + return 1; + } + + pValue = PyObject_CallFunctionObjArgs(asyncio_run, coroutine, NULL); + Py_DECREF(coroutine); + Py_DECREF(asyncio_run); + } + else + { + // Call the function + pValue = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + } + + // Measure the end time + clock_t end_time = clock(); + double time_spent = (double)(end_time - start_time) / CLOCKS_PER_SEC; + printf("Execution time: %f seconds\n", time_spent); + + if (pValue != NULL) + { + if (PyLong_Check(pValue)) + { + long result = PyLong_AsLong(pValue); + printf("Result of call (int): %ld\n", result); + } + else if (PyFloat_Check(pValue)) + { + double result = PyFloat_AsDouble(pValue); + printf("Result of call (float): %f\n", result); + } + else if (PyUnicode_Check(pValue)) + { + const char *result = PyUnicode_AsUTF8(pValue); + printf("Result of call (string): %s\n", result); + } + else if (PyList_Check(pValue)) + { + printf("Result of call (list):\n"); + for (Py_ssize_t i = 0; i < PyList_Size(pValue); i++) + { + PyObject *item = PyList_GetItem(pValue, i); + PyObject *str_item = PyObject_Str(item); + const char *str = PyUnicode_AsUTF8(str_item); + printf(" %s\n", str); + Py_DECREF(str_item); + } + } + else if (PyDict_Check(pValue)) + { + printf("Result of call (dict):\n"); + PyObject *key, *value; + Py_ssize_t pos = 0; + while (PyDict_Next(pValue, &pos, &key, &value)) + { + PyObject *str_key = PyObject_Str(key); + PyObject *str_value = PyObject_Str(value); + const char *str_k = PyUnicode_AsUTF8(str_key); + const char *str_v = PyUnicode_AsUTF8(str_value); + printf(" %s: %s\n", str_k, str_v); + Py_DECREF(str_key); + Py_DECREF(str_value); + } + } + else + { + printf("Error: Function returned an unsupported type\n"); + } Py_DECREF(pValue); - } else { + } + else + { PyErr_Print(); - fprintf(stderr, "Function call failed\n"); - Py_DECREF(pModule); - Py_XDECREF(pFunc); - Py_Finalize(); - return 1; + fprintf(stderr, "Call failed\n"); } // Clean up @@ -97,9 +274,10 @@ int main(int argc, char *argv[]) { Py_DECREF(pModule); // Finalize the Python interpreter - if (Py_FinalizeEx() < 0) { + if (Py_FinalizeEx() < 0) + { return 120; } return 0; -} +} \ No newline at end of file