install: add option to support building a wheel from poetry and installing locally

This commit is contained in:
Blake Harnden 2020-09-11 15:05:49 -07:00
parent b9a14fbe0c
commit 0668d0a49b
3 changed files with 47 additions and 26 deletions

View file

@ -6,7 +6,14 @@ authors = ["Boeing Research and Technology"]
license = "BSD-2-Clause" license = "BSD-2-Clause"
repository = "https://github.com/coreemu/core" repository = "https://github.com/coreemu/core"
documentation = "https://coreemu.github.io/core/" documentation = "https://coreemu.github.io/core/"
include = ["core/gui/data/**/*", "core/configservices/*/templates"] include = [
"core/api/grpc/*",
"core/configservices/*/templates",
"core/constants.py",
"core/gui/data/**/*",
]
exclude = ["core/constants.py.in"]
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.6" python = "^3.6"

View file

@ -14,7 +14,8 @@ fi
dev="" dev=""
verbose="" verbose=""
prefix="" prefix=""
while getopts "dvp:" opt; do local=""
while getopts "dvlp:" opt; do
case ${opt} in case ${opt} in
d) d)
dev="-d" dev="-d"
@ -22,6 +23,9 @@ while getopts "dvp:" opt; do
v) v)
verbose="-v" verbose="-v"
;; ;;
l)
local="-l"
;;
p) p)
prefix="-p ${OPTARG}" prefix="-p ${OPTARG}"
;; ;;
@ -30,6 +34,7 @@ while getopts "dvp:" opt; do
echo "" >&2 echo "" >&2
echo "-v enable verbose install" >&2 echo "-v enable verbose install" >&2
echo "-d enable developer install" >&2 echo "-d enable developer install" >&2
echo "-l enable local install, not compatible with developer install" >&2
echo "-p install prefix, defaults to /usr/local" >&2 echo "-p install prefix, defaults to /usr/local" >&2
exit 1 exit 1
;; ;;
@ -54,4 +59,4 @@ python3 -m pip install --user pipx
python3 -m pipx ensurepath python3 -m pipx ensurepath
export PATH=$PATH:~/.local/bin export PATH=$PATH:~/.local/bin
pipx install invoke pipx install invoke
inv install ${dev} ${verbose} ${prefix} inv install ${dev} ${verbose} ${local} ${prefix}

View file

@ -171,13 +171,18 @@ def install_core(c: Context, hide: bool) -> None:
c.run("sudo make install", hide=hide) c.run("sudo make install", hide=hide)
def install_poetry(c: Context, dev: bool, hide: bool) -> None: def install_poetry(c: Context, dev: bool, local: bool, hide: bool) -> None:
c.run("pipx install poetry", hide=hide) c.run("pipx install poetry", hide=hide)
args = "" if dev else "--no-dev" if local:
with c.cd(DAEMON_DIR): with c.cd(DAEMON_DIR):
c.run(f"poetry install {args}", hide=hide) c.run("poetry build -f wheel", hide=hide)
if dev: c.run("python3 -m pip install dist/*")
c.run("poetry run pre-commit install", hide=hide) else:
args = "" if dev else "--no-dev"
with c.cd(DAEMON_DIR):
c.run(f"poetry install {args}", hide=hide)
if dev:
c.run("poetry run pre-commit install", hide=hide)
def install_ospf_mdr(c: Context, os_info: OsInfo, hide: bool) -> None: def install_ospf_mdr(c: Context, os_info: OsInfo, hide: bool) -> None:
@ -243,10 +248,11 @@ def install_service(c, verbose=False, prefix=DEFAULT_PREFIX):
@task( @task(
help={ help={
"verbose": "enable verbose", "verbose": "enable verbose",
"prefix": f"prefix where scripts are installed, default is {DEFAULT_PREFIX}" "prefix": f"prefix where scripts are installed, default is {DEFAULT_PREFIX}",
"local": "determines if core will install to local system, default is False",
}, },
) )
def install_scripts(c, verbose=False, prefix=DEFAULT_PREFIX): def install_scripts(c, local=False, verbose=False, prefix=DEFAULT_PREFIX):
""" """
install core script files, modified to leverage virtual environment install core script files, modified to leverage virtual environment
""" """
@ -259,7 +265,7 @@ def install_scripts(c, verbose=False, prefix=DEFAULT_PREFIX):
lines = f.readlines() lines = f.readlines()
first = lines[0].strip() first = lines[0].strip()
# modify python scripts to point to virtual environment # modify python scripts to point to virtual environment
if first == "#!/usr/bin/env python3": if not local and first == "#!/usr/bin/env python3":
lines[0] = f"#!{python}\n" lines[0] = f"#!{python}\n"
temp = NamedTemporaryFile("w", delete=False) temp = NamedTemporaryFile("w", delete=False)
for line in lines: for line in lines:
@ -273,16 +279,17 @@ def install_scripts(c, verbose=False, prefix=DEFAULT_PREFIX):
c.run(f"sudo cp {script} {dest}", hide=hide) c.run(f"sudo cp {script} {dest}", hide=hide)
# setup core python helper # setup core python helper
core_python = bin_dir.joinpath("core-python") if not local:
temp = NamedTemporaryFile("w", delete=False) core_python = bin_dir.joinpath("core-python")
temp.writelines([ temp = NamedTemporaryFile("w", delete=False)
"#!/bin/bash\n", temp.writelines([
f'exec "{python}" "$@"\n', "#!/bin/bash\n",
]) f'exec "{python}" "$@"\n',
temp.close() ])
c.run(f"sudo cp {temp.name} {core_python}", hide=hide) temp.close()
c.run(f"sudo chmod 755 {core_python}", hide=hide) c.run(f"sudo cp {temp.name} {core_python}", hide=hide)
os.unlink(temp.name) c.run(f"sudo chmod 755 {core_python}", hide=hide)
os.unlink(temp.name)
# install core configuration file # install core configuration file
config_dir = "/etc/core" config_dir = "/etc/core"
@ -295,13 +302,15 @@ def install_scripts(c, verbose=False, prefix=DEFAULT_PREFIX):
help={ help={
"dev": "install development mode", "dev": "install development mode",
"verbose": "enable verbose", "verbose": "enable verbose",
"prefix": f"prefix where scripts are installed, default is {DEFAULT_PREFIX}" "local": "determines if core will install to local system, default is False",
"prefix": f"prefix where scripts are installed, default is {DEFAULT_PREFIX}",
}, },
) )
def install(c, dev=False, verbose=False, prefix=DEFAULT_PREFIX): def install(c, dev=False, verbose=False, local=False, prefix=DEFAULT_PREFIX):
""" """
install core, poetry, scripts, service, and ospf mdr install core, poetry, scripts, service, and ospf mdr
""" """
print(f"installing core locally: {local}")
print(f"installing core with prefix: {prefix}") print(f"installing core with prefix: {prefix}")
c.run("sudo -v", hide=True) c.run("sudo -v", hide=True)
p = Progress(verbose) p = Progress(verbose)
@ -318,9 +327,9 @@ def install(c, dev=False, verbose=False, prefix=DEFAULT_PREFIX):
with p.start("installing vcmd/gui"): with p.start("installing vcmd/gui"):
install_core(c, hide) install_core(c, hide)
with p.start("installing poetry virtual environment"): with p.start("installing poetry virtual environment"):
install_poetry(c, dev, hide) install_poetry(c, dev, local, hide)
with p.start("installing scripts and /etc/core"): with p.start("installing scripts and /etc/core"):
install_scripts(c, hide, prefix) install_scripts(c, local, hide, prefix)
with p.start("installing systemd service"): with p.start("installing systemd service"):
install_service(c, hide, prefix) install_service(c, hide, prefix)
with p.start("installing ospf mdr"): with p.start("installing ospf mdr"):