Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 1 | From 07fce2101d83b5334de78e661ba0361c2874ebdf Mon Sep 17 00:00:00 2001 |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 2 | From: Alistair Francis <alistair.francis@wdc.com> |
| 3 | Date: Mon, 18 Mar 2019 16:30:45 -0700 |
Brad Bishop | 2d39a06 | 2019-10-28 08:33:36 -0400 | [diff] [blame] | 4 | Subject: [PATCH 1/7] Remove python venv |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 5 | |
| 6 | Remove the python venv requirements and instead just use the native |
| 7 | python and pip pacakges. |
| 8 | |
| 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
| 10 | Upstream-Status: Inappropriate [embedded specific] |
| 11 | --- |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 12 | dev_setup.sh | 39 --------------------------------------- |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 13 | start-mycroft.sh | 13 ------------- |
| 14 | venv-activate.sh | 44 +------------------------------------------- |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 15 | 3 files changed, 1 insertion(+), 95 deletions(-) |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 16 | |
| 17 | diff --git a/dev_setup.sh b/dev_setup.sh |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 18 | index cf81ed25f0f..99a44bfd8a7 100755 |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 19 | --- a/dev_setup.sh |
| 20 | +++ b/dev_setup.sh |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 21 | @@ -338,18 +338,6 @@ ${YELLOW}Make sure to manually install:$BLUE git python3 python-setuptools pytho |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 22 | fi |
| 23 | } |
| 24 | |
| 25 | -VIRTUALENV_ROOT=${VIRTUALENV_ROOT:-"${TOP}/.venv"} |
| 26 | - |
| 27 | -function install_venv() { |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 28 | - $opt_python -m venv "${VIRTUALENV_ROOT}/" --without-pip |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 29 | - # Force version of pip for reproducability, but there is nothing special |
| 30 | - # about this version. Update whenever a new version is released and |
| 31 | - # verified functional. |
| 32 | - curl https://bootstrap.pypa.io/3.3/get-pip.py | "${VIRTUALENV_ROOT}/bin/python" - 'pip==18.0.0' |
| 33 | - # Function status depending on if pip exists |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 34 | - [[ -x ${VIRTUALENV_ROOT}/bin/pip ]] |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 35 | -} |
| 36 | - |
| 37 | install_deps |
| 38 | |
| 39 | # Configure to use the standard commit template for |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 40 | @@ -383,17 +371,6 @@ else |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 41 | fi |
| 42 | fi |
| 43 | |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 44 | -if [[ ! -x ${VIRTUALENV_ROOT}/bin/activate ]] ; then |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 45 | - if ! install_venv ; then |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 46 | - echo 'Failed to set up virtualenv for mycroft, exiting setup.' |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 47 | - exit 1 |
| 48 | - fi |
| 49 | -fi |
| 50 | - |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 51 | -# Start the virtual environment |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 52 | -source "${VIRTUALENV_ROOT}/bin/activate" |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 53 | -cd "$TOP" |
| 54 | - |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 55 | # Install pep8 pre-commit hook |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 56 | HOOK_FILE='./.git/hooks/pre-commit' |
| 57 | if [[ -n $INSTALL_PRECOMMIT_HOOK ]] || grep -q 'MYCROFT DEV SETUP' $HOOK_FILE; then |
| 58 | @@ -408,22 +385,6 @@ fi |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 59 | |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 60 | PYTHON=$(python -c "import sys;print('python{}.{}'.format(sys.version_info[0], sys.version_info[1]))") |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 61 | |
| 62 | -# Add mycroft-core to the virtualenv path |
| 63 | -# (This is equivalent to typing 'add2virtualenv $TOP', except |
| 64 | -# you can't invoke that shell function from inside a script) |
| 65 | -VENV_PATH_FILE="${VIRTUALENV_ROOT}/lib/$PYTHON/site-packages/_virtualenv_path_extensions.pth" |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 66 | -if [[ ! -f $VENV_PATH_FILE ]] ; then |
| 67 | - echo 'import sys; sys.__plen = len(sys.path)' > "$VENV_PATH_FILE" || return 1 |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 68 | - echo "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)" >> "$VENV_PATH_FILE" || return 1 |
| 69 | -fi |
| 70 | - |
| 71 | -if ! grep -q "$TOP" $VENV_PATH_FILE ; then |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 72 | - echo 'Adding mycroft-core to virtualenv path' |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 73 | - sed -i.tmp '1 a\ |
| 74 | -'"$TOP"' |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 75 | -' "$VENV_PATH_FILE" |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 76 | -fi |
| 77 | - |
| 78 | # install required python modules |
| 79 | if ! pip install -r requirements.txt ; then |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 80 | echo 'Warning: Failed to install all requirements. Continue? y/N' |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 81 | diff --git a/start-mycroft.sh b/start-mycroft.sh |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 82 | index 0f88430982e..3aed2f189d4 100755 |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 83 | --- a/start-mycroft.sh |
| 84 | +++ b/start-mycroft.sh |
| 85 | @@ -20,7 +20,6 @@ script=${0} |
| 86 | script=${script##*/} |
| 87 | cd -P "$( dirname "$SOURCE" )" |
| 88 | DIR="$( pwd )" |
| 89 | -VIRTUALENV_ROOT=${VIRTUALENV_ROOT:-"${DIR}/.venv"} |
| 90 | |
| 91 | function help() { |
| 92 | echo "${script}: Mycroft command/service launcher" |
| 93 | @@ -76,19 +75,11 @@ function name-to-script-path() { |
| 94 | esac |
| 95 | } |
| 96 | |
| 97 | -function source-venv() { |
| 98 | - # Enter Python virtual environment, unless under Docker |
| 99 | - if [ ! -f "/.dockerenv" ] ; then |
| 100 | - source ${VIRTUALENV_ROOT}/bin/activate |
| 101 | - fi |
| 102 | -} |
| 103 | - |
| 104 | first_time=true |
| 105 | function init-once() { |
| 106 | if ($first_time) ; then |
| 107 | echo "Initializing..." |
| 108 | "${DIR}/scripts/prepare-msm.sh" |
| 109 | - source-venv |
| 110 | first_time=false |
| 111 | fi |
| 112 | } |
| 113 | @@ -225,15 +216,12 @@ case ${_opt} in |
| 114 | # launch-background ${_opt} |
| 115 | # ;; |
| 116 | "unittest") |
| 117 | - source-venv |
| 118 | pytest test/unittests/ --cov=mycroft "$@" |
| 119 | ;; |
| 120 | "singleunittest") |
| 121 | - source-venv |
| 122 | pytest "$@" |
| 123 | ;; |
| 124 | "skillstest") |
| 125 | - source-venv |
| 126 | pytest test/integrationtests/skills/discover_tests.py "$@" |
| 127 | ;; |
| 128 | "audiotest") |
| 129 | @@ -243,7 +231,6 @@ case ${_opt} in |
| 130 | launch-process ${_opt} |
| 131 | ;; |
| 132 | "sdkdoc") |
| 133 | - source-venv |
| 134 | cd doc |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 135 | make ${_params} |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 136 | cd .. |
| 137 | diff --git a/venv-activate.sh b/venv-activate.sh |
| 138 | index d1e7bcb44e7..10b46d4de3b 100644 |
| 139 | --- a/venv-activate.sh |
| 140 | +++ b/venv-activate.sh |
| 141 | @@ -22,49 +22,7 @@ |
| 142 | |
| 143 | # wrap in function to allow local variables, since this file will be source'd |
| 144 | function main() { |
| 145 | - local quiet=0 |
| 146 | - |
| 147 | - for arg in "$@" |
| 148 | - do |
| 149 | - case $arg in |
| 150 | - "-q"|"--quiet" ) |
| 151 | - quiet=1 |
| 152 | - ;; |
| 153 | - |
| 154 | - "-h"|"--help" ) |
| 155 | - echo "venv-activate.sh: Enter the Mycroft virtual environment" |
| 156 | - echo "Usage:" |
| 157 | - echo " source venv-activate.sh" |
| 158 | - echo "or" |
| 159 | - echo " . venv-activate.sh" |
| 160 | - echo "" |
| 161 | - echo "Options:" |
| 162 | - echo " -q | --quiet Don't show instructions." |
| 163 | - echo " -h | --help Show help." |
| 164 | - return 0 |
| 165 | - ;; |
| 166 | - |
| 167 | - *) |
| 168 | - echo "ERROR: Unrecognized option: $@" |
| 169 | - return 1 |
| 170 | - ;; |
| 171 | - esac |
| 172 | - done |
| 173 | - |
| 174 | - if [ "$0" == "$BASH_SOURCE" ] ; then |
| 175 | - # Prevent running in script then exiting immediately |
| 176 | - echo "ERROR: Invoke with 'source venv-activate.sh' or '. venv-activate.sh'" |
| 177 | - else |
| 178 | - local SRC_DIR="$( builtin cd "$( dirname "${BASH_SOURCE}" )" ; pwd -P )" |
| 179 | - source ${SRC_DIR}/.venv/bin/activate |
| 180 | - |
| 181 | - # Provide an easier to find "mycroft-" prefixed command. |
| 182 | - unalias mycroft-venv-activate 2>/dev/null |
| 183 | - alias mycroft-venv-deactivate="deactivate && unalias mycroft-venv-deactivate 2>/dev/null && alias mycroft-venv-activate=\"source '${SRC_DIR}/venv-activate.sh'\"" |
| 184 | - if [ $quiet -eq 0 ] ; then |
| 185 | - echo "Entering Mycroft virtual environment. Run 'mycroft-venv-deactivate' to exit" |
| 186 | - fi |
| 187 | - fi |
| 188 | + echo "Not entering Python VENV" |
| 189 | } |
| 190 | |
| 191 | main $@ |
| 192 | -- |
Brad Bishop | 6a62e0e | 2019-10-21 08:11:42 -0400 | [diff] [blame] | 193 | 2.23.0 |
Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame] | 194 | |