mycroft-core/venv-activate.sh

71 lines
2.3 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
#
# Copyright 2018 Mycroft AI Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script places the user in the mycroft-core virtual environment,
# necessary to run unit tests or to interact directly with mycroft-core
# via an interactive Python shell.
Unify the command line experience across platforms (#1784) * Unify the command line experience across platforms Interacting with Mycroft was slightly different on different platforms (Mark 1, Github, Picroft), which resulted in confusion and the beginnings of a documentation/support nightmare. This moves several of the common commands into a mycroft-core/bin folder instead of being build in packaging or part of the Picroft package only. This required a small changes to the common scripts, in addition to adding the new scripts. Here are details: * dev_setup.sh - Stubbed out a setup wizard (TODO) - Jumped to latest version of pip (18.0) - Set execution flags for new scripts * start-mycroft.sh - Allow auto-execution of dev_setup.sh - De-sourced the stop-mycroft.sh calls (not needed) - Add quotes to better handle paths with spaces * stop-mycroft.sh - Return exit code to show if a service was stopped or killed - Extend the time to wait for a gently shutdown from 2 secs to 5 - Changed to say "messagebus.service" instead of just "service" to be more clear (the name "service" means nothing to users, but "bus does") * venv-activate.sh - Added help - Added -q or --quiet mode - Added toggled availability of 'mycroft-venv-activate' and 'mycroft-venv-deactivate' aliases. Only one is available at any given time. New scripts: * mycroft-cli-client: start up the CLI * mycroft-help: shows hints on using mycroft * mycroft-mic-test: runs the basic record/playback, playing nicely with a running Mycroft by stopping and restarting services as appropriate * mycroft-pip: manage the venv via pip * mycroft-say-to: send utterances, like a user spoke them * mycroft-speak: speaks the given phrase using Mycroft * mycroft-skill-testrunner: invoke the single-skill test runner All of these scripts are easy to discover by typing "mycroft-" then hitting the TAB key. ==== INSTALLER NOTES ==== * We no longer need to create mycroft-cli-client and mycroft-pip in the Debian packages. * mycroft-core/bin should be added to the path * Corrections after review Several minor corrections, plus added wrappers for the 'msm' and 'msk' utilities. * Set executable flag on script files in bin/ The scripts in the bin/ folder needed to be changed to executable within git to prevent looking dirty after dev_setup.sh has been run. * Add executable flag to one more script
2018-09-09 21:55:01 +00:00
# wrap in function to allow local variables, since this file will be source'd
function main() {
local quiet=0
for arg in "$@"
do
case $arg in
"-q"|"--quiet" )
quiet=1
;;
"-h"|"--help" )
echo "venv-activate.sh: Enter the Mycroft virtual environment"
echo "Usage:"
echo " source venv-activate.sh"
echo "or"
echo " . venv-activate.sh"
echo ""
echo "Options:"
echo " -q | --quiet Don't show instructions."
echo " -h | --help Show help."
return 0
;;
*)
echo "ERROR: Unrecognized option: $@"
return 1
;;
esac
done
if [[ "$0" == "$BASH_SOURCE" ]] ; then
Unify the command line experience across platforms (#1784) * Unify the command line experience across platforms Interacting with Mycroft was slightly different on different platforms (Mark 1, Github, Picroft), which resulted in confusion and the beginnings of a documentation/support nightmare. This moves several of the common commands into a mycroft-core/bin folder instead of being build in packaging or part of the Picroft package only. This required a small changes to the common scripts, in addition to adding the new scripts. Here are details: * dev_setup.sh - Stubbed out a setup wizard (TODO) - Jumped to latest version of pip (18.0) - Set execution flags for new scripts * start-mycroft.sh - Allow auto-execution of dev_setup.sh - De-sourced the stop-mycroft.sh calls (not needed) - Add quotes to better handle paths with spaces * stop-mycroft.sh - Return exit code to show if a service was stopped or killed - Extend the time to wait for a gently shutdown from 2 secs to 5 - Changed to say "messagebus.service" instead of just "service" to be more clear (the name "service" means nothing to users, but "bus does") * venv-activate.sh - Added help - Added -q or --quiet mode - Added toggled availability of 'mycroft-venv-activate' and 'mycroft-venv-deactivate' aliases. Only one is available at any given time. New scripts: * mycroft-cli-client: start up the CLI * mycroft-help: shows hints on using mycroft * mycroft-mic-test: runs the basic record/playback, playing nicely with a running Mycroft by stopping and restarting services as appropriate * mycroft-pip: manage the venv via pip * mycroft-say-to: send utterances, like a user spoke them * mycroft-speak: speaks the given phrase using Mycroft * mycroft-skill-testrunner: invoke the single-skill test runner All of these scripts are easy to discover by typing "mycroft-" then hitting the TAB key. ==== INSTALLER NOTES ==== * We no longer need to create mycroft-cli-client and mycroft-pip in the Debian packages. * mycroft-core/bin should be added to the path * Corrections after review Several minor corrections, plus added wrappers for the 'msm' and 'msk' utilities. * Set executable flag on script files in bin/ The scripts in the bin/ folder needed to be changed to executable within git to prevent looking dirty after dev_setup.sh has been run. * Add executable flag to one more script
2018-09-09 21:55:01 +00:00
# Prevent running in script then exiting immediately
echo "ERROR: Invoke with 'source venv-activate.sh' or '. venv-activate.sh'"
else
local SRC_DIR="$( builtin cd "$( dirname "${BASH_SOURCE}" )" ; pwd -P )"
Unify the command line experience across platforms (#1784) * Unify the command line experience across platforms Interacting with Mycroft was slightly different on different platforms (Mark 1, Github, Picroft), which resulted in confusion and the beginnings of a documentation/support nightmare. This moves several of the common commands into a mycroft-core/bin folder instead of being build in packaging or part of the Picroft package only. This required a small changes to the common scripts, in addition to adding the new scripts. Here are details: * dev_setup.sh - Stubbed out a setup wizard (TODO) - Jumped to latest version of pip (18.0) - Set execution flags for new scripts * start-mycroft.sh - Allow auto-execution of dev_setup.sh - De-sourced the stop-mycroft.sh calls (not needed) - Add quotes to better handle paths with spaces * stop-mycroft.sh - Return exit code to show if a service was stopped or killed - Extend the time to wait for a gently shutdown from 2 secs to 5 - Changed to say "messagebus.service" instead of just "service" to be more clear (the name "service" means nothing to users, but "bus does") * venv-activate.sh - Added help - Added -q or --quiet mode - Added toggled availability of 'mycroft-venv-activate' and 'mycroft-venv-deactivate' aliases. Only one is available at any given time. New scripts: * mycroft-cli-client: start up the CLI * mycroft-help: shows hints on using mycroft * mycroft-mic-test: runs the basic record/playback, playing nicely with a running Mycroft by stopping and restarting services as appropriate * mycroft-pip: manage the venv via pip * mycroft-say-to: send utterances, like a user spoke them * mycroft-speak: speaks the given phrase using Mycroft * mycroft-skill-testrunner: invoke the single-skill test runner All of these scripts are easy to discover by typing "mycroft-" then hitting the TAB key. ==== INSTALLER NOTES ==== * We no longer need to create mycroft-cli-client and mycroft-pip in the Debian packages. * mycroft-core/bin should be added to the path * Corrections after review Several minor corrections, plus added wrappers for the 'msm' and 'msk' utilities. * Set executable flag on script files in bin/ The scripts in the bin/ folder needed to be changed to executable within git to prevent looking dirty after dev_setup.sh has been run. * Add executable flag to one more script
2018-09-09 21:55:01 +00:00
source ${SRC_DIR}/.venv/bin/activate
# Provide an easier to find "mycroft-" prefixed command.
unalias mycroft-venv-activate 2>/dev/null
alias mycroft-venv-deactivate="deactivate && unalias mycroft-venv-deactivate 2>/dev/null && alias mycroft-venv-activate=\"source '${SRC_DIR}/venv-activate.sh'\""
if [ $quiet -eq 0 ] ; then
echo "Entering Mycroft virtual environment. Run 'mycroft-venv-deactivate' to exit"
fi
fi
}
main $@