33import string
44
55file_path = os .path .abspath (__file__ )
6- def generate_random_string (length , allowed_chars = None ):
6+
7+
8+ def generate_random_string (length , allowed_chars = None ):
79 if allowed_chars is None :
810 allowed_chars = string .ascii_letters + string .digits
911 return '' .join (random .choice (allowed_chars ) for _ in range (length ))
1012
13+
1114def install_itp_interface ():
1215 print ("Installing itp_interface" )
1316 itp_dir = os .path .dirname (os .path .dirname (file_path ))
1417 tools_dir = os .path .join (itp_dir , "tools" )
1518 repl_dir = os .path .join (tools_dir , "repl" )
1619 assert os .path .exists (repl_dir ), f"repl_dir: { repl_dir } does not exist"
17- assert os .path .exists (os .path .join (repl_dir , "lean-toolchain" )), f"lean-toolchain does not exist in { repl_dir } , build has failed"
20+ assert os .path .exists (os .path .join (repl_dir , "lean-toolchain" )
21+ ), f"lean-toolchain does not exist in { repl_dir } , build has failed"
1822 print ("repl_dir: " , repl_dir )
1923 print ("Building itp_interface" )
2024 os .system (f"cd { repl_dir } && lake build repl" )
2125
26+
2227def install_lean_repl ():
2328 print ("Updating Lean" )
2429 itp_dir = os .path .dirname (os .path .dirname (file_path ))
2530 tools_dir = os .path .join (itp_dir , "tools" )
2631 repl_dir = os .path .join (tools_dir , "repl" )
2732 assert os .path .exists (repl_dir ), f"repl_dir: { repl_dir } does not exist"
28- assert os .path .exists (os .path .join (repl_dir , "lean-toolchain" )), f"lean-toolchain does not exist in { repl_dir } , build has failed"
33+ assert os .path .exists (os .path .join (repl_dir , "lean-toolchain" )
34+ ), f"lean-toolchain does not exist in { repl_dir } , build has failed"
2935 print ("repl_dir: " , repl_dir )
3036 assert os .system ("git --version" ) == 0 , "git is not installed"
3137 print ("[OK] git is installed" )
@@ -48,7 +54,8 @@ def install_lean_repl():
4854 output = os .popen (cmd_to_run ).read ()
4955 print ("Output: " , output )
5056 if output == "" :
51- print (f"Could not find a commit with message containing { lean_version } " )
57+ print (
58+ f"Could not find a commit with message containing { lean_version } " )
5259 print ("Probably this version does not exist in the git history of the REPL" )
5360 lean_version = "4.7.0-rc2"
5461 print ("Switching to v4.7.0-rc2 on commit 97182f0" )
@@ -71,36 +78,20 @@ def install_lean_repl():
7178 elan_url = "https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh"
7279 os .system (f"curl -sSL { elan_url } -sSf | sh -s -- -y" )
7380 print ("[OK] .elan installed" )
81+
7482 lean_repo = "leanprover/lean4"
75- # Create a temporary script to run
76- shell_code = f"""source $HOME/.elan/env
77- echo "Installing Lean 4 ({ lean_repo } :{ lean_version } )..."
78- elan toolchain install { lean_repo } :{ lean_version }
79- elan override set { lean_repo } :{ lean_version }
80- echo "Installed Lean 4 ({ lean_repo } :{ lean_version } ) successfully!"
81- export PATH=$PATH:$HOME/.elan/bin"""
82- random_string = os .urandom (8 ).hex ()
83- number = random .randint (1 , 10 )
84- lens = [random .randint (1 , 10 ) for _ in range (number )]
85- rand_dirnames = [generate_random_string (l ) for l in lens ]
86- random_path = "/" .join (rand_dirnames )
87- os .makedirs (f"/tmp/{ random_path } " , exist_ok = True )
88- random_sh_path = f"/tmp/{ random_path } /{ random_string } .sh"
89- print (f"Writing the script to { random_sh_path } " )
90- with open (random_sh_path , "w" ) as f :
91- f .write (shell_code )
92- os .system (f"chmod +x { random_sh_path } " )
93- print ("Running the script" )
94- os .system (f"bash { random_sh_path } " )
95- print ("Removing the script" )
96- os .system (f"rm { random_sh_path } " )
97- os .system (f"rmdir /tmp/{ random_path } " )
83+ os .system ("source $HOME/.elan/env" )
84+ os .system (f"echo 'Installing Lean 4 ({ lean_repo } :{ lean_version } )...'" )
85+ os .system (f"elan toolchain install { lean_repo } :{ lean_version } " )
86+ os .system (f"elan override set { lean_repo } :{ lean_version } " )
87+ os .system (
88+ f"echo 'Installed Lean 4 ({ lean_repo } :{ lean_version } ) successfully!'" )
89+ os .system ("export PATH=$PATH:$HOME/.elan/bin" )
90+
9891 os .system ("ls -l $HOME/.elan/bin" )
99- assert os .system ("export PATH=$PATH:$HOME/.elan/bin && lean --version" ) == 0 , "Lean 4 is not installed aborting"
100- print ("[OK] Lean 4 installed successfully" )
101- print ("NOTE: Please run `install-itp-interface` to finish the installation" )
10292
93+ assert os .system (
94+ "export PATH=$PATH:$HOME/.elan/bin && lean --version" ) == 0 , "Lean 4 is not installed aborting"
95+ print ("[OK] Lean 4 installed successfully" )
10396
104-
105-
106-
97+ print ("NOTE: Please run `install-itp-interface` to finish the installation" )
0 commit comments