From 2eb1801eff77ad5e12658785b4cad5f2e4f16fc7 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Thu, 10 Aug 2023 14:25:07 +0200 Subject: [PATCH] virtualenv use --- docs/installation.md | 20 ++++++++++++++------ dotdrop.sh | 12 ++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/docs/installation.md b/docs/installation.md index 4059a77..190ced7 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -1,6 +1,8 @@ # Installation * [As a submodule](#as-a-submodule) +* [As a submodule in a virtualenv](#as-a-submodule-in-a-virtualenv) +* [Submodule upgrade/downgrade](#submodule-upgradedowngrade) * [PyPI package](#pypi-package) * [Homebrew package](#homebrew-package) * [Debian unstable (sid)](#debian) @@ -54,7 +56,7 @@ shell with the config file path; for example: alias dotdrop= --cfg=' ``` -### As a submodule in a virtualenv +## As a submodule in a virtualenv To install it in a [virtualenv](https://virtualenv.pypa.io): ```bash @@ -65,23 +67,29 @@ $ git init ## install dotdrop as a submodule $ git submodule add https://github.com/deadc0de6/dotdrop.git $ virtualenv -p python3 env -$ echo 'env' > .gitignore -$ source env/bin/activate -$ pip install -r dotdrop/requirements.txt +$ echo 'env' >> .gitignore +$ env/bin/pip install -r dotdrop/requirements.txt $ ./dotdrop/bootstrap.sh +# add the following in your .bashrc/.zshrc/etc +# or hardcode it in the dotdrop.sh script +$ export DOTDROP_VIRTUALENV=env + ## use dotdrop $ ./dotdrop.sh --help ``` -When using a virtualenv, make sure to source the environment before using dotdrop: +When using a virtualenv, make sure to export the `DOTDROP_VIRTUALENV` +variable with the directory name of your virtualenv: ```bash -$ source env/bin/activate +$ export DOTDROP_VIRTUALENV=env $ ./dotdrop.sh --help ``` Then follow the instructions under [As a submodule](#as-a-submodule). +## Submodule upgrade/downgrade + ### Upgrade dotdrop submodule If using dotdrop as a submodule, one can control if dotdrop diff --git a/dotdrop.sh b/dotdrop.sh index a4b86e5..e9e5522 100755 --- a/dotdrop.sh +++ b/dotdrop.sh @@ -2,6 +2,8 @@ # author: deadc0de6 (https://github.com/deadc0de6) # Copyright (c) 2017, deadc0de6 +ENV_DIR=${DOTDROP_VIRTUALENV:-} + # setup variables args=("$@") cur=$(cd "$(dirname "${0}")" && pwd) @@ -18,8 +20,14 @@ fi # check python executable pybin="python3" -hash ${pybin} 2>/dev/null || pybin="python" -[[ "$(${pybin} -V 2>&1)" =~ "Python 3" ]] || { echo "install Python 3" && exit 1; } +if [ -z "${ENV_DIR}" ]; then + hash ${pybin} 2>/dev/null || pybin="python" + [[ "$(${pybin} -V 2>&1)" =~ "Python 3" ]] || { echo "install Python 3" && exit 1; } +else + # virtualenv + pybin="${ENV_DIR}/bin/python" +fi +hash "${pybin}" 2>/dev/null || (echo "python executable not found" && exit 1) # launch dotdrop PYTHONPATH=dotdrop:${PYTHONPATH} ${pybin} -m dotdrop.dotdrop "${args[@]}"