From 0668d0a49bb8832216669fc823ea5f6391e3a7b5 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Fri, 11 Sep 2020 15:05:49 -0700 Subject: [PATCH] install: add option to support building a wheel from poetry and installing locally --- daemon/pyproject.toml | 9 ++++++- install.sh | 9 +++++-- tasks.py | 55 +++++++++++++++++++++++++------------------ 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/daemon/pyproject.toml b/daemon/pyproject.toml index 55bfabe4..2bea0b89 100644 --- a/daemon/pyproject.toml +++ b/daemon/pyproject.toml @@ -6,7 +6,14 @@ authors = ["Boeing Research and Technology"] license = "BSD-2-Clause" repository = "https://github.com/coreemu/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] python = "^3.6" diff --git a/install.sh b/install.sh index 5e5a9b11..59584afa 100755 --- a/install.sh +++ b/install.sh @@ -14,7 +14,8 @@ fi dev="" verbose="" prefix="" -while getopts "dvp:" opt; do +local="" +while getopts "dvlp:" opt; do case ${opt} in d) dev="-d" @@ -22,6 +23,9 @@ while getopts "dvp:" opt; do v) verbose="-v" ;; + l) + local="-l" + ;; p) prefix="-p ${OPTARG}" ;; @@ -30,6 +34,7 @@ while getopts "dvp:" opt; do echo "" >&2 echo "-v enable verbose 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 exit 1 ;; @@ -54,4 +59,4 @@ python3 -m pip install --user pipx python3 -m pipx ensurepath export PATH=$PATH:~/.local/bin pipx install invoke -inv install ${dev} ${verbose} ${prefix} +inv install ${dev} ${verbose} ${local} ${prefix} diff --git a/tasks.py b/tasks.py index 0a0f685b..71bab859 100644 --- a/tasks.py +++ b/tasks.py @@ -171,13 +171,18 @@ def install_core(c: Context, hide: bool) -> None: 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) - 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) + if local: + with c.cd(DAEMON_DIR): + c.run("poetry build -f wheel", hide=hide) + c.run("python3 -m pip install dist/*") + 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: @@ -243,10 +248,11 @@ def install_service(c, verbose=False, prefix=DEFAULT_PREFIX): @task( help={ "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 """ @@ -259,7 +265,7 @@ def install_scripts(c, verbose=False, prefix=DEFAULT_PREFIX): lines = f.readlines() first = lines[0].strip() # 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" temp = NamedTemporaryFile("w", delete=False) 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) # setup core python helper - core_python = bin_dir.joinpath("core-python") - temp = NamedTemporaryFile("w", delete=False) - temp.writelines([ - "#!/bin/bash\n", - f'exec "{python}" "$@"\n', - ]) - temp.close() - c.run(f"sudo cp {temp.name} {core_python}", hide=hide) - c.run(f"sudo chmod 755 {core_python}", hide=hide) - os.unlink(temp.name) + if not local: + core_python = bin_dir.joinpath("core-python") + temp = NamedTemporaryFile("w", delete=False) + temp.writelines([ + "#!/bin/bash\n", + f'exec "{python}" "$@"\n', + ]) + temp.close() + c.run(f"sudo cp {temp.name} {core_python}", hide=hide) + c.run(f"sudo chmod 755 {core_python}", hide=hide) + os.unlink(temp.name) # install core configuration file config_dir = "/etc/core" @@ -295,13 +302,15 @@ def install_scripts(c, verbose=False, prefix=DEFAULT_PREFIX): help={ "dev": "install development mode", "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 """ + print(f"installing core locally: {local}") print(f"installing core with prefix: {prefix}") c.run("sudo -v", hide=True) p = Progress(verbose) @@ -318,9 +327,9 @@ def install(c, dev=False, verbose=False, prefix=DEFAULT_PREFIX): with p.start("installing vcmd/gui"): install_core(c, hide) 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"): - install_scripts(c, hide, prefix) + install_scripts(c, local, hide, prefix) with p.start("installing systemd service"): install_service(c, hide, prefix) with p.start("installing ospf mdr"):