Commit
Β·
aa8b25c
1
Parent(s):
5c115f4
attemp to install mnz from app.py
Browse files- app.py +36 -10
- src/utils.py +0 -7
app.py
CHANGED
@@ -1,21 +1,47 @@
|
|
|
|
|
|
1 |
import os
|
2 |
import subprocess
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
os.
|
|
|
|
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
try:
|
12 |
-
|
13 |
-
print("MiniZinc version:",
|
14 |
except Exception as e:
|
15 |
-
print("MiniZinc
|
16 |
-
|
17 |
|
18 |
-
setup_directories()
|
19 |
|
20 |
if __name__ == "__main__":
|
21 |
demo = create_ui()
|
|
|
1 |
+
from src.ui import create_ui
|
2 |
+
|
3 |
import os
|
4 |
import subprocess
|
5 |
+
import urllib.request
|
6 |
+
import tarfile
|
7 |
|
8 |
+
def install_minizinc():
|
9 |
+
install_path = "/home/user/minizinc"
|
10 |
+
if os.path.exists(os.path.join(install_path, "bin", "minizinc")):
|
11 |
+
print("β
MiniZinc already installed.")
|
12 |
+
return
|
13 |
+
|
14 |
+
print("β¬οΈ Downloading MiniZinc...")
|
15 |
+
url = "https://github.com/MiniZinc/MiniZincIDE/releases/download/2.9.0/MiniZincIDE-2.9.0-bundle-linux-x86_64.tgz"
|
16 |
+
bundle_path = "/tmp/minizinc.tgz"
|
17 |
+
|
18 |
+
urllib.request.urlretrieve(url, bundle_path)
|
19 |
|
20 |
+
print("π¦ Extracting MiniZinc...")
|
21 |
+
os.makedirs(install_path, exist_ok=True)
|
22 |
+
with tarfile.open(bundle_path, "r:gz") as tar:
|
23 |
+
tar.extractall(path=install_path, members=_strip_top_level(tar))
|
24 |
|
25 |
+
print("β
MiniZinc installed.")
|
26 |
+
|
27 |
+
def _strip_top_level(tar):
|
28 |
+
# Removes top-level folder when extracting
|
29 |
+
top_level = tar.getmembers()[0].name.split('/')[0]
|
30 |
+
for member in tar.getmembers():
|
31 |
+
member.path = '/'.join(member.path.split('/')[1:])
|
32 |
+
yield member
|
33 |
+
|
34 |
+
# Install and patch env
|
35 |
+
install_minizinc()
|
36 |
+
os.environ["PATH"] = f"/home/user/minizinc/bin:{os.environ['PATH']}"
|
37 |
+
|
38 |
+
# Check it works
|
39 |
try:
|
40 |
+
version = subprocess.check_output(["minizinc", "--version"], text=True)
|
41 |
+
print("π§ MiniZinc version:", version.strip())
|
42 |
except Exception as e:
|
43 |
+
print("β MiniZinc install failed:", e)
|
|
|
44 |
|
|
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
demo = create_ui()
|
src/utils.py
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
|
3 |
-
from src.config import LOCAL_TEMP_SUBMISSIONS_DIR
|
4 |
-
|
5 |
-
|
6 |
-
def setup_directories():
|
7 |
-
os.makedirs(LOCAL_TEMP_SUBMISSIONS_DIR, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|