Skip to content

Commit

Permalink
Update ergup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Feb 18, 2024
1 parent 64e6810 commit bf0be15
Showing 1 changed file with 43 additions and 41 deletions.
84 changes: 43 additions & 41 deletions ergup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,9 @@ def as_record(self):
return namedtuple('Record', self.keys())(**self)
class Set(set):
pass



class Bytes(bytes):
def try_new(b): # -> Result[Nat]
if isinstance(b, bytes):
Expand All @@ -1127,7 +1130,6 @@ def try_new(b): # -> Result[Nat]
return Error("not a bytes")

def __getitem__(self, index_or_slice):

if isinstance(index_or_slice, slice):
return Bytes(bytes.__getitem__(self, index_or_slice))
elif isinstance(index_or_slice, Range):
Expand Down Expand Up @@ -1157,17 +1159,17 @@ def float__(f):
def str__(s):
return Str(s)
def if_tmp_func_3__():
if (answer_L18_C4 == Str("y")):
(print)(((Str("Removing ") + (str__)(erg_dir_L12,)) + Str(" ...")),)
if_tmp_2__ = (su_L8).rmtree(erg_dir_L12,)
if (Str(answer_L18_C4) == Str("y")):
(print)(((Str("Removing ") + (str__)(Str(erg_dir_L12),)) + Str(" ...")),)
if_tmp_2__ = (su_L8).rmtree(Str(erg_dir_L12),)
else:
(print)(Str("Aborting installation"),)
if_tmp_2__ = (exit)(Nat(1),)
return if_tmp_2__
def if_tmp_func_1__():
if (
(os_L6).path
).exists(erg_dir_L12,):
).exists(Str(erg_dir_L12),):
(print)(Str(".erg directory already exists, do you want to overwrite it? [y/n]"),end=Str(" "),)
global answer_L18_C4
answer_L18_C4 = (input)()
Expand All @@ -1178,35 +1180,35 @@ def if_tmp_func_1__():
urllib_L1 = __import__("urllib.request")
urllib_L1 = __import__("urllib.request")
def if_tmp_func_5__():
if (((sys_L5).argv).get(Nat(1),) == Str("nightly")):
if ((Array((sys_L5).argv)).get(Nat(1),) == Str("nightly")):
global latest_url_L32_C8
latest_url_L32_C8 = Str("https://api.github.com/repos/erg-lang/erg/releases")
global _stream_L33_C8
_stream_L33_C8 = (
(urllib_L1).request
).urlopen(latest_url_L32_C8,)
).urlopen(Str(latest_url_L32_C8),)
global s_L34_C8
s_L34_C8 = ((_stream_L33_C8).read()).decode()
global jdata_L35_C8
jdata_L35_C8 = (json_L4).loads(s_L34_C8,)
jdata_L35_C8 = (json_L4).loads(Str(s_L34_C8),)
assert contains_operator((Array)[Dict({(Str): (object),}),],jdata_L35_C8)
if_tmp_4__ = ((jdata_L35_C8).__getitem__(Nat(0),)).__getitem__(Str("tag_name"),)
if_tmp_4__ = ((Array(jdata_L35_C8)).__getitem__(Nat(0),)).__getitem__(Str("tag_name"),)
else:
global latest_url_L39_C8
latest_url_L39_C8 = Str("https://api.github.com/repos/erg-lang/erg/releases/latest")
global _stream_L40_C8
_stream_L40_C8 = (
(urllib_L1).request
).urlopen(latest_url_L39_C8,)
).urlopen(Str(latest_url_L39_C8),)
global s_L41_C8
s_L41_C8 = ((_stream_L40_C8).read()).decode()
global jdata_L42_C8
jdata_L42_C8 = (json_L4).loads(s_L41_C8,)
jdata_L42_C8 = (json_L4).loads(Str(s_L41_C8),)
assert contains_operator(Dict({(Str): (object),}),jdata_L42_C8)
if_tmp_4__ = (jdata_L42_C8).__getitem__(Str("tag_name"),)
if_tmp_4__ = (Dict(jdata_L42_C8)).__getitem__(Str("tag_name"),)
return if_tmp_4__
def match_tmp_func_7__():
match (sys_L5).platform:
match Str((sys_L5).platform):
case ("darwin") as __percent__p_desugar_1_L49_C4:
match_tmp_6__ = Str("erg-x86_64-apple-darwin.tar.gz")
case ("win32") as __percent__p_desugar_2_L50_C4:
Expand All @@ -1216,32 +1218,32 @@ def match_tmp_func_7__():
return match_tmp_6__
urllib_L1 = __import__("urllib.request")
def if_tmp_func_9__():
if ((sys_L5).platform == Str("win32")):
(print)(((Str("Extracting ") + (str__)(filename_L48,)) + Str(" ...")),)
if (Str((sys_L5).platform) == Str("win32")):
(print)(((Str("Extracting ") + (str__)(Str(filename_L48),)) + Str(" ...")),)
global bytesio_L60_C8
bytesio_L60_C8 = (io_L7).BytesIO((stream_L56).read(),)
global zipfile_L61_C8
zipfile_L61_C8 = (zf_L3).ZipFile(bytesio_L60_C8,)
(zipfile_L61_C8).extractall(erg_tmp_dir_L14,)
(zipfile_L61_C8).extractall(Str(erg_tmp_dir_L14),)
(zipfile_L61_C8).close()
(discard__)((su_L8).move(((Str("") + (str__)(erg_tmp_dir_L14,)) + Str("/erg.exe")),((Str("") + (str__)(erg_bin_dir_L13,)) + Str("/erg.exe")),),)
(discard__)((su_L8).move(((Str("") + (str__)(erg_tmp_dir_L14,)) + Str("/lib")),((Str("") + (str__)(erg_dir_L12,)) + Str("/lib")),),)
if_tmp_8__ = (su_L8).rmtree(erg_tmp_dir_L14,)
(discard__)((su_L8).move(((Str("") + (str__)(Str(erg_tmp_dir_L14),)) + Str("/erg.exe")),((Str("") + (str__)(Str(erg_bin_dir_L13),)) + Str("/erg.exe")),),)
(discard__)((su_L8).move(((Str("") + (str__)(Str(erg_tmp_dir_L14),)) + Str("/lib")),((Str("") + (str__)(Str(erg_dir_L12),)) + Str("/lib")),),)
if_tmp_8__ = (su_L8).rmtree(Str(erg_tmp_dir_L14),)
else:
(print)(((Str("Extracting ") + (str__)(filename_L48,)) + Str(" ...")),)
(print)(((Str("Extracting ") + (str__)(Str(filename_L48),)) + Str(" ...")),)
global tarfile_L69_C8
tarfile_L69_C8 = (tf_L2).open(fileobj=stream_L56,mode=Str("r|gz"),)
(tarfile_L69_C8).extractall(erg_tmp_dir_L14,)
(tarfile_L69_C8).extractall(Str(erg_tmp_dir_L14),)
(tarfile_L69_C8).close()
(discard__)((su_L8).move(((Str("") + (str__)(erg_tmp_dir_L14,)) + Str("/erg")),((Str("") + (str__)(erg_bin_dir_L13,)) + Str("/erg")),),)
(discard__)((su_L8).move(((Str("") + (str__)(erg_tmp_dir_L14,)) + Str("/lib")),((Str("") + (str__)(erg_dir_L12,)) + Str("/lib")),),)
if_tmp_8__ = (su_L8).rmtree(erg_tmp_dir_L14,)
(discard__)((su_L8).move(((Str("") + (str__)(Str(erg_tmp_dir_L14),)) + Str("/erg")),((Str("") + (str__)(Str(erg_bin_dir_L13),)) + Str("/erg")),),)
(discard__)((su_L8).move(((Str("") + (str__)(Str(erg_tmp_dir_L14),)) + Str("/lib")),((Str("") + (str__)(Str(erg_dir_L12),)) + Str("/lib")),),)
if_tmp_8__ = (su_L8).rmtree(Str(erg_tmp_dir_L14),)
return if_tmp_8__
os_L6 = __import__("os.path")
def if_tmp_func_11__():
if ((res2_L88).returncode != Nat(0)):
if (Int((res2_L88).returncode) != Nat(0)):
assert contains_operator(Bytes,(res2_L88).stderr)
if_tmp_10__ = (quit)(((Str("Failed to install poise: ") + (str__)(((res2_L88).stderr).decode(),)) + Str("")),)
if_tmp_10__ = (quit)(((Str("Failed to install poise: ") + (str__)((Bytes((res2_L88).stderr)).decode(),)) + Str("")),)
else:
if_tmp_10__ = None
return if_tmp_10__
Expand All @@ -1257,35 +1259,35 @@ def if_tmp_func_11__():
homedir_L11 = (
(os_L6).path
).expanduser(Str("~"),)
erg_dir_L12 = (homedir_L11 + Str("/.erg"))
erg_bin_dir_L13 = (homedir_L11 + Str("/.erg/bin"))
erg_tmp_dir_L14 = (homedir_L11 + Str("/.erg/tmp"))
erg_dir_L12 = (Str(homedir_L11) + Str("/.erg"))
erg_bin_dir_L13 = (Str(homedir_L11) + Str("/.erg/bin"))
erg_tmp_dir_L14 = (Str(homedir_L11) + Str("/.erg/tmp"))
if_tmp_func_1__()
(os_L6).mkdir(erg_dir_L12,)
(os_L6).mkdir(erg_bin_dir_L13,)
(os_L6).mkdir(Str(erg_dir_L12),)
(os_L6).mkdir(Str(erg_bin_dir_L13),)
latest_version_L30 = if_tmp_func_5__()
(print)(((Str("version: ") + (str__)(latest_version_L30,)) + Str("")),)
filename_L48 = match_tmp_func_7__()
url_L52 = ((((Str("https://github.com/erg-lang/erg/releases/download/") + (str__)(latest_version_L30,)) + Str("/")) + (str__)(filename_L48,)) + Str(""))
(print)(((Str("Downloading ") + (str__)(url_L52,)) + Str(" ...")),)
url_L52 = ((((Str("https://github.com/erg-lang/erg/releases/download/") + (str__)(latest_version_L30,)) + Str("/")) + (str__)(Str(filename_L48),)) + Str(""))
(print)(((Str("Downloading ") + (str__)(Str(url_L52),)) + Str(" ...")),)
stream_L56 = (
(urllib_L1).request
).urlopen(url_L52,)
).urlopen(Str(url_L52),)
if_tmp_func_9__()
(print)(Str("erg installed successfully"),)
poise_git_url_L78 = Str("https://github.com/erg-lang/poise.git")
(print)(Str("Cloning poise (erg package manager) ..."),)
(os_L6).mkdir(erg_tmp_dir_L14,) if (not ((
(os_L6).mkdir(Str(erg_tmp_dir_L14),) if (not ((
(os_L6).path
).exists(erg_tmp_dir_L14,))) else None
(os_L6).chdir(erg_tmp_dir_L14,)
res_L83 = (sub_L9).run(Array([Str("git"),Str("clone"),poise_git_url_L78,]),capture_output=Bool(True),)
(quit)(Str("Failed to clone poise repo"),) if ((res_L83).returncode != Nat(0)) else None
).exists(Str(erg_tmp_dir_L14),))) else None
(os_L6).chdir(Str(erg_tmp_dir_L14),)
res_L83 = (sub_L9).run(Array([Str("git"),Str("clone"),Str(poise_git_url_L78),]),capture_output=Bool(True),)
(quit)(Str("Failed to clone poise repo"),) if (Int((res_L83).returncode) != Nat(0)) else None
(os_L6).chdir(Str("poise"),)
(print)(Str("Building poise ..."),)
res2_L88 = (sub_L9).run(Array([((Str("") + (str__)(erg_bin_dir_L13,)) + Str("/erg")),Str("src/main.er"),Str("--"),Str("install"),]),capture_output=Bool(True),)
res2_L88 = (sub_L9).run(Array([((Str("") + (str__)(Str(erg_bin_dir_L13),)) + Str("/erg")),Str("src/main.er"),Str("--"),Str("install"),]),capture_output=Bool(True),)
if_tmp_func_11__()
(print)(Str("poise installed successfully"),)
(os_L6).chdir(Str(".."),)
(su_L8).rmtree(Str("poise"),)
(print)(((((Str("Please add `.erg` to your PATH by running `export PATH=$PATH:") + (str__)(erg_bin_dir_L13,)) + Str("` and `export ERG_PATH=")) + (str__)(erg_dir_L12,)) + Str("`")),)
(print)(((((Str("Please add `.erg` to your PATH by running `export PATH=$PATH:") + (str__)(Str(erg_bin_dir_L13),)) + Str("` and `export ERG_PATH=")) + (str__)(Str(erg_dir_L12),)) + Str("`")),)

0 comments on commit bf0be15

Please sign in to comment.