Skip to content

Commit d672ccd

Browse files
committed
Move install action into a separate function
1 parent acd620b commit d672ccd

File tree

1 file changed

+51
-48
lines changed

1 file changed

+51
-48
lines changed

hererocks.py

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,56 @@ def __call__(self, parser, namespace, fname, option_string=None):
19771977

19781978
main(args_content.split("\r\n")[1:])
19791979

1980+
def install_programs(vs_already_set_up):
1981+
global temp_dir
1982+
temp_dir = tempfile.mkdtemp()
1983+
1984+
if (opts.lua or opts.luajit) and os.name == "nt" and not vs_already_set_up and using_cl():
1985+
setup_vs(opts.target)
1986+
1987+
start_dir = os.getcwd()
1988+
opts.location = os.path.abspath(opts.location)
1989+
1990+
if opts.downloads is not None:
1991+
opts.downloads = os.path.abspath(opts.downloads)
1992+
1993+
if opts.builds is not None:
1994+
opts.builds = os.path.abspath(opts.builds)
1995+
1996+
identifiers = get_installed_identifiers()
1997+
1998+
if not os.path.exists(os.path.join(opts.location, "bin")):
1999+
os.makedirs(os.path.join(opts.location, "bin"))
2000+
2001+
write_activation_scripts()
2002+
2003+
if opts.lua:
2004+
if "LuaJIT" in identifiers:
2005+
del identifiers["LuaJIT"]
2006+
2007+
if RioLua(opts.lua).update_identifiers(identifiers):
2008+
save_installed_identifiers(identifiers)
2009+
2010+
os.chdir(start_dir)
2011+
2012+
if opts.luajit:
2013+
if "lua" in identifiers:
2014+
del identifiers["lua"]
2015+
2016+
if LuaJIT(opts.luajit).update_identifiers(identifiers):
2017+
save_installed_identifiers(identifiers)
2018+
2019+
os.chdir(start_dir)
2020+
2021+
if opts.luarocks:
2022+
if LuaRocks(opts.luarocks).update_identifiers(identifiers):
2023+
save_installed_identifiers(identifiers)
2024+
2025+
os.chdir(start_dir)
2026+
2027+
remove_dir(temp_dir)
2028+
print("Done.")
2029+
19802030
def show_location():
19812031
if os.path.exists(opts.location):
19822032
all_identifiers = get_installed_identifiers()
@@ -2096,54 +2146,7 @@ def main(argv=None):
20962146
parser.error("can't install both PUC-Rio Lua and LuaJIT")
20972147

20982148
if opts.lua or opts.luajit or opts.luarocks:
2099-
global temp_dir
2100-
temp_dir = tempfile.mkdtemp()
2101-
2102-
if (opts.lua or opts.luajit) and os.name == "nt" and argv is None and using_cl():
2103-
setup_vs(opts.target)
2104-
2105-
start_dir = os.getcwd()
2106-
opts.location = os.path.abspath(opts.location)
2107-
2108-
if opts.downloads is not None:
2109-
opts.downloads = os.path.abspath(opts.downloads)
2110-
2111-
if opts.builds is not None:
2112-
opts.builds = os.path.abspath(opts.builds)
2113-
2114-
identifiers = get_installed_identifiers()
2115-
2116-
if not os.path.exists(os.path.join(opts.location, "bin")):
2117-
os.makedirs(os.path.join(opts.location, "bin"))
2118-
2119-
write_activation_scripts()
2120-
2121-
if opts.lua:
2122-
if "LuaJIT" in identifiers:
2123-
del identifiers["LuaJIT"]
2124-
2125-
if RioLua(opts.lua).update_identifiers(identifiers):
2126-
save_installed_identifiers(identifiers)
2127-
2128-
os.chdir(start_dir)
2129-
2130-
if opts.luajit:
2131-
if "lua" in identifiers:
2132-
del identifiers["lua"]
2133-
2134-
if LuaJIT(opts.luajit).update_identifiers(identifiers):
2135-
save_installed_identifiers(identifiers)
2136-
2137-
os.chdir(start_dir)
2138-
2139-
if opts.luarocks:
2140-
if LuaRocks(opts.luarocks).update_identifiers(identifiers):
2141-
save_installed_identifiers(identifiers)
2142-
2143-
os.chdir(start_dir)
2144-
2145-
remove_dir(temp_dir)
2146-
print("Done.")
2149+
install_programs(argv is not None)
21472150

21482151
if opts.show:
21492152
show_location()

0 commit comments

Comments
 (0)