Repository: AI-SDC/SACRO-ML (language: python)

Issue:
OS system calls rely on calling "python"
There are several OS calls that have been added in various examples and tests to execute the command line that rely on a python executable named "python" when on GNU/Linux "python3" is the command. I haven't looked specifically at the CI runners, which might automatically install a "python -> python3" mapping, but this is typically not the case for desktop users.

```python
os.system("python -m ...")
```

This might be as easily fixed as changing "python" to `sys.executable`.
OS system calls rely on calling "python"
There are several OS calls that have been added in various examples and tests to execute the command line that rely on a python executable named "python" when on GNU/Linux "python3" is the command. I haven't looked specifically at the CI runners, which might automatically install a "python -> python3" mapping, but this is typically not the case for desktop users.

```python
os.system("python -m ...")
```

This might be as easily fixed as changing "python" to `sys.executable`.


Discussion / hints:

Fix patch:
diff --git a/examples/lira_attack_example.py b/examples/lira_attack_example.py
index e356fb04..d61f4ebb 100644
--- a/examples/lira_attack_example.py
+++ b/examples/lira_attack_example.py
@@ -34,6 +34,7 @@
 
 import json
 import os
+import sys
 
 import numpy as np
 from sklearn.datasets import load_breast_cancer
@@ -166,12 +167,12 @@
 
 # [TRE] Runs the attack. This would be done on the command line, here we do that with os.system
 # [TRE] First they access the help to work out which parameters they need to set
-os.system("python -m aisdc.attacks.likelihood_attack run-attack --help")
+os.system(f"{sys.executable} -m aisdc.attacks.likelihood_attack run-attack --help")
 
 # [TRE] Then they run the attack
 # Example 1 to demonstrate all given shadow models trained
 os.system(
-    "python -m aisdc.attacks.likelihood_attack run-attack "
+    f"{sys.executable} -m aisdc.attacks.likelihood_attack run-attack "
     "--attack-config-json-file-name config.json "
     "--report-name example1_lira_report "
     "--n-shadow-models 100 "
@@ -179,7 +180,7 @@
 
 # Example 2 to demonstrate fail fast of shadow models trained
 os.system(
-    "python -m aisdc.attacks.likelihood_attack run-attack "
+    f"{sys.executable} -m aisdc.attacks.likelihood_attack run-attack "
     "--attack-config-json-file-name config.json "
     "--report-name example2_lira_report "
     "--n-shadow-models 100 "
diff --git a/examples/worst_case_attack_example.py b/examples/worst_case_attack_example.py
index 99cad662..4cd056a2 100644
--- a/examples/worst_case_attack_example.py
+++ b/examples/worst_case_attack_example.py
@@ -251,12 +251,12 @@
 
 # [TRE] Runs the attack. This would be done on the command line, here we do that with os.system
 # [TRE] First they access the help to work out which parameters they need to set
-os.system("python -m aisdc.attacks.worst_case_attack run-attack --help")
+os.system(f"{sys.executable} -m aisdc.attacks.worst_case_attack run-attack --help")
 
 # [TRE] Then they run the attack
 # Example 1: Worstcase attack through commandline by passing parameters
 os.system(
-    "python -m aisdc.attacks.worst_case_attack run-attack "
+    f"{sys.executable} -m aisdc.attacks.worst_case_attack run-attack "
     "--training-preds-filename train_preds.csv "
     "--test_preds_filename test_preds.csv "
     "--n-reps 10 "
@@ -294,7 +294,7 @@
     f.write(json.dumps(config))
 
 os.system(
-    "python -m aisdc.attacks.worst_case_attack run-attack-from-configfile "
+    f"{sys.executable} -m aisdc.attacks.worst_case_attack run-attack-from-configfile "
     "--attack-config-json-file-name config_worstcase_cmd.json "
 )
 
@@ -315,7 +315,7 @@
     f.write(json.dumps(config))
 
 os.system(
-    "python -m aisdc.attacks.worst_case_attack run-attack-from-configfile "
+    f"{sys.executable} -m aisdc.attacks.worst_case_attack run-attack-from-configfile "
     "--attack-config-json-file-name config_worstcase_cmd.json "
 )
 


Test patch:
diff --git a/tests/test_worst_case_attack.py b/tests/test_worst_case_attack.py
index 40f1412d..27fbfca5 100644
--- a/tests/test_worst_case_attack.py
+++ b/tests/test_worst_case_attack.py
@@ -74,7 +74,7 @@ def test_attack_from_predictions_cmd():
     with open("config_worstcase_cmd.json", "w", encoding="utf-8") as f:
         f.write(json.dumps(config))
     os.system(
-        "python -m aisdc.attacks.worst_case_attack run-attack-from-configfile "
+        f"{sys.executable} -m aisdc.attacks.worst_case_attack run-attack-from-configfile "
         "--attack-config-json-file-name config_worstcase_cmd.json "
     )
     os.remove("config_worstcase_cmd.json")