Skip to content

Commit

Permalink
feat: nightly installing option
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Feb 18, 2024
1 parent 512725d commit 55f60d3
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 57 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Execute the script (Ubuntu/MacOS)
if: runner.os != 'Windows'
run: |
python bin/ergup310.pyc && rm -rf ~/.erg && python ergup.py
python bin/ergup310.pyc && rm -rf ~/.erg && python ergup.py nightly
export PATH=$PATH:~/.erg/bin
export ERG_PATH=~/.erg
Expand All @@ -34,7 +34,7 @@ jobs:
- name: Execute the script (Windows)
if: runner.os == 'Windows'
run: |
python bin/ergup310.pyc && Remove-Item -Force -Recurse C:\Users\runneradmin\.erg && python ergup.py
python bin/ergup310.pyc && Remove-Item -Force -Recurse C:\Users\runneradmin\.erg && python ergup.py nightly
$env:PATH+=";C:\Users\runneradmin\.erg\bin"
$env:ERG_PATH="C:\Users\runneradmin\.erg"
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ Python 3
curl -L https://github.com/mtshiba/ergup/raw/main/ergup.py | python3
# and please set environment variables
```

### Installing nightly version

```sh
curl -L https://github.com/mtshiba/ergup/raw/main/ergup.py | python3 nightly
```
21 changes: 15 additions & 6 deletions ergup.er
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ if! os.path.exists!(erg_dir), do!:
os.mkdir! erg_dir
os.mkdir! erg_bin_dir

latest_url = "https://api.github.com/repos/erg-lang/erg/releases/latest"
_stream = urllib.request.urlopen!(latest_url)
s = _stream.read!().decode()
jdata = json.loads s
assert jdata in {Str: Obj}
latest_version = jdata["tag_name"]
latest_version = if! sys.argv.get(1) == "nightly":
do!:
latest_url = "https://api.github.com/repos/erg-lang/erg/releases"
_stream = urllib.request.urlopen!(latest_url)
s = _stream.read!().decode()
jdata = json.loads s
assert jdata in Array({Str: Obj})
jdata[0]["tag_name"]
do!:
latest_url = "https://api.github.com/repos/erg-lang/erg/releases/latest"
_stream = urllib.request.urlopen!(latest_url)
s = _stream.read!().decode()
jdata = json.loads s
assert jdata in {Str: Obj}
jdata["tag_name"]

print! "version: \{latest_version}"

Expand Down
173 changes: 124 additions & 49 deletions ergup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,59 @@ class UnsizedArray:
elem: object
def __init__(self, elem):
self.elem = elem
class Dict(dict):
@staticmethod
def try_new(dic): # -> Result[Dict]
if isinstance(dic, dict):
return Dict(dic)
else:
return Error("not a dict")
def concat(self, other):
return Dict({**self, **other})
def diff(self, other):
return Dict({k: v for k, v in self.items() if k not in other})
# other: Iterable
def update(self, other, conflict_resolver=None):
if conflict_resolver == None:
super().update(other)
elif isinstance(other, dict):
self.merge(other, conflict_resolver)
else:
for k, v in other:
if k in self:
self[k] = conflict_resolver(self[k], v)
else:
self[k] = v
# other: Dict
def merge(self, other, conflict_resolver=None):
self.update(other, conflict_resolver)
def insert(self, key, value):
self[key] = value
def remove(self, key):
res = self.get(key)
if res != None:
del self[key]
return res
def as_record(self):
from collections import namedtuple
return namedtuple('Record', self.keys())(**self)
class Set(set):
pass
class Bytes(bytes):
def try_new(b): # -> Result[Nat]
if isinstance(b, bytes):
return Bytes(bytes(b))
else:
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):
return Bytes(bytes.__getitem__(self, index_or_slice.into_slice()))
else:
return bytes.__getitem__(self, index_or_slice)
os_L6 = __import__("os.path")
os_L6 = __import__("os.path")

Expand Down Expand Up @@ -1123,46 +1176,75 @@ def if_tmp_func_1__():
if_tmp_0__ = None
return if_tmp_0__
urllib_L1 = __import__("urllib.request")
def match_tmp_func_5__():
urllib_L1 = __import__("urllib.request")
def if_tmp_func_5__():
if (((sys_L5).argv).__getitem__(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,)
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,)
assert contains_operator((Array)[Dict({(Str): (object),}),],jdata_L35_C8)
if_tmp_4__ = ((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,)
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,)
assert contains_operator(Dict({(Str): (object),}),jdata_L42_C8)
if_tmp_4__ = (jdata_L42_C8).__getitem__(Str("tag_name"),)
return if_tmp_4__
def match_tmp_func_7__():
match (sys_L5).platform:
case ("darwin") as __percent__p_desugar_1_L40_C4:
match_tmp_4__ = Str("erg-x86_64-apple-darwin.tar.gz")
case ("win32") as __percent__p_desugar_2_L41_C4:
match_tmp_4__ = Str("erg-x86_64-pc-windows-msvc.zip")
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:
match_tmp_6__ = Str("erg-x86_64-pc-windows-msvc.zip")
case _:
match_tmp_4__ = Str("erg-x86_64-unknown-linux-gnu.tar.gz")
return match_tmp_4__
match_tmp_6__ = Str("erg-x86_64-unknown-linux-gnu.tar.gz")
return match_tmp_6__
urllib_L1 = __import__("urllib.request")
def if_tmp_func_7__():
def if_tmp_func_9__():
if ((sys_L5).platform == Str("win32")):
(print)(((Str("Extracting ") + (str__)(filename_L39,)) + Str(" ...")),)
global bytesio_L51_C8
bytesio_L51_C8 = (io_L7).BytesIO((stream_L47).read(),)
global zipfile_L52_C8
zipfile_L52_C8 = (zf_L3).ZipFile(bytesio_L51_C8,)
(zipfile_L52_C8).extractall(erg_tmp_dir_L14,)
(zipfile_L52_C8).close()
(print)(((Str("Extracting ") + (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).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_6__ = (su_L8).rmtree(erg_tmp_dir_L14,)
if_tmp_8__ = (su_L8).rmtree(erg_tmp_dir_L14,)
else:
(print)(((Str("Extracting ") + (str__)(filename_L39,)) + Str(" ...")),)
global tarfile_L60_C8
tarfile_L60_C8 = (tf_L2).open(fileobj=stream_L47,mode=Str("r|gz"),)
(tarfile_L60_C8).extractall(erg_tmp_dir_L14,)
(tarfile_L60_C8).close()
(print)(((Str("Extracting ") + (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).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_6__ = (su_L8).rmtree(erg_tmp_dir_L14,)
return if_tmp_6__
if_tmp_8__ = (su_L8).rmtree(erg_tmp_dir_L14,)
return if_tmp_8__
os_L6 = __import__("os.path")
def if_tmp_func_9__():
if ((res2_L79).returncode != Nat(0)):
assert contains_operator(Bytes,(res2_L79).stderr)
if_tmp_8__ = (quit)(((Str("Failed to install poise: ") + (str__)(((res2_L79).stderr).decode(),)) + Str("")),)
def if_tmp_func_11__():
if ((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("")),)
else:
if_tmp_8__ = None
return if_tmp_8__
if_tmp_10__ = None
return if_tmp_10__
urllib_L1 = (__import__)(Str("urllib"),)
tf_L2 = (__import__)(Str("tarfile"),)
zf_L3 = (__import__)(Str("zipfile"),)
Expand All @@ -1181,35 +1263,28 @@ def if_tmp_func_9__():
if_tmp_func_1__()
(os_L6).mkdir(erg_dir_L12,)
(os_L6).mkdir(erg_bin_dir_L13,)
latest_url_L30 = Str("https://api.github.com/repos/erg-lang/erg/releases/latest")
_stream_L31 = (
(urllib_L1).request
).urlopen(latest_url_L30,)
s_L32 = ((_stream_L31).read()).decode()
jdata_L33 = (json_L4).loads(s_L32,)
assert contains_operator({(Str): (object),},jdata_L33)
latest_version_L35 = (jdata_L33).__getitem__(Str("tag_name"),)
(print)(((Str("version: ") + (str__)(latest_version_L35,)) + Str("")),)
filename_L39 = match_tmp_func_5__()
url_L43 = ((((Str("https://github.com/erg-lang/erg/releases/download/") + (str__)(latest_version_L35,)) + Str("/")) + (str__)(filename_L39,)) + Str(""))
(print)(((Str("Downloading ") + (str__)(url_L43,)) + Str(" ...")),)
stream_L47 = (
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(" ...")),)
stream_L56 = (
(urllib_L1).request
).urlopen(url_L43,)
if_tmp_func_7__()
).urlopen(url_L52,)
if_tmp_func_9__()
(print)(Str("erg installed successfully"),)
poise_git_url_L69 = Str("https://github.com/erg-lang/poise.git")
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).path
).exists(erg_tmp_dir_L14,))) else None
(os_L6).chdir(erg_tmp_dir_L14,)
res_L74 = (sub_L9).run(Array([Str("git"),Str("clone"),poise_git_url_L69,]),capture_output=Bool(True),)
(quit)(Str("Failed to clone poise repo"),) if ((res_L74).returncode != Nat(0)) else None
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
(os_L6).chdir(Str("poise"),)
(print)(Str("Building poise ..."),)
res2_L79 = (sub_L9).run(Array([((Str("") + (str__)(erg_bin_dir_L13,)) + Str("/erg")),Str("src/main.er"),Str("--"),Str("install"),]),capture_output=Bool(True),)
if_tmp_func_9__()
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),)
if_tmp_func_11__()
(print)(Str("poise installed successfully"),)
(os_L6).chdir(Str(".."),)
(su_L8).rmtree(Str("poise"),)
Expand Down

0 comments on commit 55f60d3

Please sign in to comment.