From c3f271481aa7740e54342b663dce0e1a1306f5f0 Mon Sep 17 00:00:00 2001 From: Anish Athalye Date: Thu, 24 May 2018 12:00:13 -0400 Subject: [PATCH 1/2] Fix handling of base directory Prior to this patch, Dotbot was relying on running with the base directory being the current working directory. In practice, it was relying on the install shim to set up this context. It makes more sense sense to actually execute `chdir()` within Dotbot itself, rather than relying on the install shim to do so. --- dotbot/cli.py | 9 +++++---- test/test-lib.bash | 10 ++++------ test/tests/plugin-dir.bash | 2 +- test/tests/plugin.bash | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/dotbot/cli.py b/dotbot/cli.py index d77ab42..8febb26 100644 --- a/dotbot/cli.py +++ b/dotbot/cli.py @@ -14,10 +14,10 @@ def add_options(parser): help='suppress most output') parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='enable verbose output') - parser.add_argument('-d', '--base-directory', nargs=1, + parser.add_argument('-d', '--base-directory', dest='base_directory', help='execute commands from within BASEDIR', metavar='BASEDIR', required=True) - parser.add_argument('-c', '--config-file', nargs=1, dest='config_file', + parser.add_argument('-c', '--config-file', dest='config_file', help='run commands given in CONFIGFILE', metavar='CONFIGFILE', required=True) parser.add_argument('-p', '--plugin', action='append', dest='plugins', default=[], @@ -55,10 +55,11 @@ def main(): for plugin_path in plugin_paths: abspath = os.path.abspath(plugin_path) module.load(abspath) - tasks = read_config(options.config_file[0]) + tasks = read_config(options.config_file) if not isinstance(tasks, list): raise ReadingError('Configuration file must be a list of tasks') - dispatcher = Dispatcher(options.base_directory[0]) + os.chdir(options.base_directory) + dispatcher = Dispatcher(options.base_directory) success = dispatcher.dispatch(tasks) if success: log.info('\n==> All tasks executed successfully') diff --git a/test/test-lib.bash b/test/test-lib.bash index 008c2f8..3a24510 100644 --- a/test/test-lib.bash +++ b/test/test-lib.bash @@ -51,17 +51,15 @@ initialize() { run_dotbot() { ( - cd "${DOTFILES}" - cat > "${INSTALL_CONF}" - ${DOTBOT_EXEC} -d . -c "${INSTALL_CONF}" "${@}" + cat > "${DOTFILES}/${INSTALL_CONF}" + ${DOTBOT_EXEC} -d "${DOTFILES}" -c "${DOTFILES}/${INSTALL_CONF}" "${@}" ) } run_dotbot_json() { ( - cd "${DOTFILES}" - cat > "${INSTALL_CONF_JSON}" - ${DOTBOT_EXEC} -d . -c "${INSTALL_CONF_JSON}" "${@}" + cat > "${DOTFILES}/${INSTALL_CONF_JSON}" + ${DOTBOT_EXEC} -d "${DOTFILES}" -c "${DOTFILES}/${INSTALL_CONF_JSON}" "${@}" ) } diff --git a/test/tests/plugin-dir.bash b/test/tests/plugin-dir.bash index 299f144..f3a5e94 100644 --- a/test/tests/plugin-dir.bash +++ b/test/tests/plugin-dir.bash @@ -19,7 +19,7 @@ EOF ' test_expect_success 'run' ' -run_dotbot --plugin-dir plugins < Date: Thu, 24 May 2018 10:30:24 -0400 Subject: [PATCH 2/2] Point PyYAML dependency to official repository Previously, PyYAML was hosted on BitBucket, so we had a mirror of the repo on GitHub. Now, official hosting has moved to GitHub, so we can point to the official repository instead. Thanks to Marco A. Feliu for pointing this out. This patch also updates the install shim to update submodule URLs. To preserve the functionality of earlier Dotbot versions, we will need to maintain 'https://github.com/anishathalye/pyyaml'. Because old versions of the install shim used with new Dotbot versions will not update submodule URLs, we will need to keep the old repository in sync with the upstream repository as we upgrade PyYAML versions. This patch also upgrades the dependency to PyYAML 3.12. --- .gitmodules | 2 +- lib/pyyaml | 2 +- test/Vagrantfile | 3 +-- test/test-lib.bash | 6 +----- test/test_travis | 2 +- test/tests/shim.bash | 29 +++++++++++++++++++++++++++++ tools/git-submodule/install | 1 + 7 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 test/tests/shim.bash diff --git a/.gitmodules b/.gitmodules index 111c39c..ffb9af9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "lib/pyyaml"] path = lib/pyyaml - url = https://github.com/anishathalye/pyyaml + url = https://github.com/yaml/pyyaml ignore = dirty diff --git a/lib/pyyaml b/lib/pyyaml index f30c956..7e026bf 160000 --- a/lib/pyyaml +++ b/lib/pyyaml @@ -1 +1 @@ -Subproject commit f30c956c11aa6b5e7827fe5840cc9ed40b938d17 +Subproject commit 7e026bfee9cc0bddeb1bbca0c4a0bcd826c2bfdf diff --git a/test/Vagrantfile b/test/Vagrantfile index 8ce1739..05d6747 100644 --- a/test/Vagrantfile +++ b/test/Vagrantfile @@ -2,8 +2,7 @@ Vagrant.configure(2) do |config| config.vm.box = 'debian/stretch64' # sync by copying for isolation - config.vm.synced_folder "..", "/dotbot", type: "rsync", - rsync__exclude: ".git/" + config.vm.synced_folder "..", "/dotbot", type: "rsync" # disable default synced folder config.vm.synced_folder ".", "/vagrant", disabled: true diff --git a/test/test-lib.bash b/test/test-lib.bash index 008c2f8..b334b81 100644 --- a/test/test-lib.bash +++ b/test/test-lib.bash @@ -1,10 +1,6 @@ DEBUG=${DEBUG:-false} USE_VAGRANT=${USE_VAGRANT:-true} -if ${USE_VAGRANT}; then - DOTBOT_EXEC=${DOTBOT_EXEC:-"python /dotbot/bin/dotbot"} -else - DOTBOT_EXEC=${DOTBOT_EXEC:-"/dotbot/bin/dotbot"} -fi +DOTBOT_EXEC=${DOTBOT_EXEC:-"python /dotbot/bin/dotbot"} DOTFILES="/home/$(whoami)/dotfiles" INSTALL_CONF='install.conf.yaml' INSTALL_CONF_JSON='install.conf.json' diff --git a/test/test_travis b/test/test_travis index 20ec1ae..79439e1 100755 --- a/test/test_travis +++ b/test/test_travis @@ -6,7 +6,7 @@ set -e # set -x # set -v -BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +export BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # Prevent execution outside of Travis CI builds if [[ "${TRAVIS}" != true || "${CI}" != true ]]; then diff --git a/test/tests/shim.bash b/test/tests/shim.bash new file mode 100644 index 0000000..2ed7d54 --- /dev/null +++ b/test/tests/shim.bash @@ -0,0 +1,29 @@ +test_description='install shim works' +. '../test-lib.bash' + +test_expect_success 'setup' ' +cd ${DOTFILES} +git init +if ${USE_VAGRANT}; then + git submodule add /dotbot dotbot +else + git submodule add ${BASEDIR} dotbot +fi +cp ./dotbot/tools/git-submodule/install . +echo "pear" > ${DOTFILES}/foo +' + +test_expect_success 'run' ' +cat > ${DOTFILES}/install.conf.yaml <