Repository: ivy-llc/ivy

Issue:
Replace `exit()` with `sys.exit()` for Improved Portability
I see that at few places `exit()` is used, we can replace it with `sys.exit()` because of the following reasons.
`sys.exit()` is a built-in function in the sys module, while `exit()` is a function defined in the builtins module. This means that `sys.exit()` is always available (If we import sys module), while `exit()` may not be available if you are running your code in a restricted environment.

In general, `sys.exit()` is the preferred way to exit a Python program. It is more explicit, more reliable, and provides more control.


Discussion:

Resolving patch:
diff --git a/scripts/backend_generation/generate.py b/scripts/backend_generation/generate.py
--- a/scripts/backend_generation/generate.py
+++ b/scripts/backend_generation/generate.py
@@ -94,7 +94,7 @@ def _get_user_input(fn, *args, **kwargs):
                 break
         except KeyboardInterrupt:
             print("Aborted.")
-            exit()
+            sys.exit()
 
 
 def _update_native_config_value(key):
diff --git a/scripts/duplicate.py b/scripts/duplicate.py
--- a/scripts/duplicate.py
+++ b/scripts/duplicate.py
@@ -1,12 +1,13 @@
 import importlib
 import os
+import sys
 import glob
 
 
 def get_all_functions_from_directory(root_dir, startswith="test"):
     if not os.path.exists(root_dir):
         print("Invalid directory")
-        exit(1)
+        sys.exit(1)
     functions_names = []
     for filename in glob.iglob(f"{root_dir}/**/*.py", recursive=True):
         if len(filename) >= 2 and filename[:2] == "./":
@@ -40,4 +41,4 @@ def check_duplicate():
     common_set = check_duplicate()
     if len(common_set) != 0:
         print("This function already exists in the functional API.")
-        exit(1)
+        sys.exit(1)


Test patch:
diff --git a/scripts/run_tests/array_api_run_tests.py b/scripts/run_tests/array_api_run_tests.py
--- a/scripts/run_tests/array_api_run_tests.py
+++ b/scripts/run_tests/array_api_run_tests.py
@@ -106,7 +106,7 @@ def main():
                 "latest-stable",
             )
     if failed:
-        exit(1)
+        sys.exit(1)
 
 
 if __name__ == "__main__":
diff --git a/scripts/run_tests/array_api_run_tests_pr.py b/scripts/run_tests/array_api_run_tests_pr.py
--- a/scripts/run_tests/array_api_run_tests_pr.py
+++ b/scripts/run_tests/array_api_run_tests_pr.py
@@ -34,7 +34,7 @@ def main():
             if ret != 0:
                 failed = True
     if failed:
-        exit(1)
+        sys.exit(1)
 
 
 if __name__ == "__main__":
diff --git a/scripts/run_tests/run_tests.py b/scripts/run_tests/run_tests.py
--- a/scripts/run_tests/run_tests.py
+++ b/scripts/run_tests/run_tests.py
@@ -283,4 +283,4 @@ def get_submodule_and_function_name(test_path, is_frontend_test=False):
 
     # if any tests fail, the workflow fails
     if failed:
-        exit(1)
+        sys.exit(1)
diff --git a/scripts/run_tests/run_tests_pr.py b/scripts/run_tests/run_tests_pr.py
--- a/scripts/run_tests/run_tests_pr.py
+++ b/scripts/run_tests/run_tests_pr.py
@@ -79,4 +79,4 @@ def get_mod_submod_test(test_path):
                         f_write.write(line)
 
     if failed:
-        exit(1)
+        sys.exit(1)
diff --git a/scripts/setup_tests/clone-mapping.py b/scripts/setup_tests/clone-mapping.py
--- a/scripts/setup_tests/clone-mapping.py
+++ b/scripts/setup_tests/clone-mapping.py
@@ -1,4 +1,5 @@
 import os
+import sys
 import git
 import bz2
 import _pickle as cPickle
@@ -9,7 +10,7 @@
 # Check if the directory exists
 if not os.path.exists(mapping_dir):
     print(f"Directory does not exist: {mapping_dir}")
-    exit(1)
+    sys.exit(1)
 
 # Create a Repo object to interact with the Git repositories
 current_repo = git.Repo("ivy/")