From 8f76ceb5b689db9c0b16a819e49930a4be6950e6 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 27 Feb 2023 22:21:15 +0100 Subject: [PATCH 1/8] doc on testing latest dotdrop --- docs/howto/test-latest-dotdrop.md | 14 ++++++++++++++ mkdocs.yml | 1 + 2 files changed, 15 insertions(+) create mode 100644 docs/howto/test-latest-dotdrop.md diff --git a/docs/howto/test-latest-dotdrop.md b/docs/howto/test-latest-dotdrop.md new file mode 100644 index 000000000..aef20d316 --- /dev/null +++ b/docs/howto/test-latest-dotdrop.md @@ -0,0 +1,14 @@ +# Test latest dotdrop + +If you installed dotdrop from a package but want to test +you current setup with the latest version from git +(or from a specific branch), you can do the following + +```bash +$ cd /tmp/ +$ git clone https://github.com/deadc0de6/dotdrop.git +$ cd dotdrop +## switch to a specific branch if needed +$ git checkout +$ ./dotdrop.sh --config +``` \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index dd0e65762..8b8251989 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -43,6 +43,7 @@ nav: - 'Prompt user for variables': 'howto/prompt-user-for-variables.md' - 'Share content across dotfiles': 'howto/sharing-content.md' - 'Symlink dotfiles': 'howto/symlink-dotfiles.md' + - 'Test latest dotdrop': 'howto/test-latest-dotdrop.md' - '': '' - '': '' markdown_extensions: From e671e82a259549858b40632b76724e5bf593a5a4 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 27 Feb 2023 22:21:24 +0100 Subject: [PATCH 2/8] urllib3 deps --- tests-requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests-requirements.txt b/tests-requirements.txt index 36e454583..d496cecac 100644 --- a/tests-requirements.txt +++ b/tests-requirements.txt @@ -5,4 +5,5 @@ coveralls; python_version > '3.5' pyflakes; python_version > '3.5' pylint; python_version > '3.5' halo; python_version > '3.5' -distro; python_version > '3.5' \ No newline at end of file +distro; python_version > '3.5' +urllib3; python_version > '3.5' \ No newline at end of file From 46fc9757003edb790fe8ca54acaaec775adc2136 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 27 Feb 2023 22:21:35 +0100 Subject: [PATCH 3/8] python version --- tests.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests.sh b/tests.sh index d2c28663e..d01d54200 100755 --- a/tests.sh +++ b/tests.sh @@ -23,7 +23,10 @@ if [ "${dotdrop_version}" != "${man_version}" ]; then echo "ERROR version.py (${dotdrop_version}) and manpage (${man_version}) differ!" exit 1 fi -echo "current version ${dotdrop_version}" +echo "current dotdrop version ${dotdrop_version}" + +echo "=> python version:" +python3 --version # test syntax echo "checking syntax..." From 253eab55d21916ef28bf6a431ec31e7f450643d9 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 27 Feb 2023 22:21:45 +0100 Subject: [PATCH 4/8] fix dead link --- docs/config/config-dotfiles.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/config/config-dotfiles.md b/docs/config/config-dotfiles.md index 82c801b05..e5916281e 100644 --- a/docs/config/config-dotfiles.md +++ b/docs/config/config-dotfiles.md @@ -51,8 +51,7 @@ executed when the dotfile is installed (that is, when the version present in dotdrop differs from the one in the filesystem). -For example, let's consider -[Vundle](https://github.com/VundleVim/Vundle.vim), used +For example, let's consider Vundle, used to manage Vim's plugins. The following action could be set to update and install the plugins when `vimrc` is deployed: From 6fb643590eef5b3eb22c77683a4feb6480341d8d Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 27 Feb 2023 22:22:07 +0100 Subject: [PATCH 5/8] fix bug #380 --- dotdrop/cfg_aggregator.py | 13 +++++++++++++ dotdrop/cfg_yaml.py | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/dotdrop/cfg_aggregator.py b/dotdrop/cfg_aggregator.py index fa18a443f..c1a79c470 100644 --- a/dotdrop/cfg_aggregator.py +++ b/dotdrop/cfg_aggregator.py @@ -274,37 +274,48 @@ def _load(self, reloading=False): reloading=reloading, debug=self.debug) + self.log.dbg('parsing cfgyaml into cfg_aggregator') + # settings + self.log.dbg('parsing settings') self.settings = Settings.parse(None, self.cfgyaml.settings) self.key_prefix = self.settings.key_prefix self.key_separator = self.settings.key_separator # dotfiles + self.log.dbg('parsing dotfiles') self.dotfiles = Dotfile.parse_dict(self.cfgyaml.dotfiles) debug_list('dotfiles', self.dotfiles, self.debug) # profiles + self.log.dbg('parsing profiles') self.profiles = Profile.parse_dict(self.cfgyaml.profiles) debug_list('profiles', self.profiles, self.debug) # actions + self.log.dbg('parsing actions') self.actions = Action.parse_dict(self.cfgyaml.actions) debug_list('actions', self.actions, self.debug) # trans_r + self.log.dbg('parsing trans_r') self.trans_r = Transform.parse_dict(self.cfgyaml.trans_r) debug_list('trans_r', self.trans_r, self.debug) # trans_w + self.log.dbg('parsing trans_w') self.trans_w = Transform.parse_dict(self.cfgyaml.trans_w) debug_list('trans_w', self.trans_w, self.debug) # variables + self.log.dbg('parsing variables') self.variables = self.cfgyaml.variables debug_dict('variables', self.variables, self.debug) + self.log.dbg('enrich variables') self._enrich_variables() + self.log.dbg('patch keys...') # patch dotfiles in profiles self._patch_keys_to_objs(self.profiles, "dotfiles", self.get_dotfile) @@ -333,6 +344,8 @@ def _load(self, reloading=False): self._get_trans_w_args(self.get_trans_w), islist=False) + self.log.dbg('done parsing cfgyaml into cfg_aggregator') + def _enrich_variables(self): """ enrich available variables diff --git a/dotdrop/cfg_yaml.py b/dotdrop/cfg_yaml.py index 8c57964c6..ade9add96 100644 --- a/dotdrop/cfg_yaml.py +++ b/dotdrop/cfg_yaml.py @@ -256,7 +256,7 @@ def __init__(self, path, profile=None, addprofiles=None, # process imported variables (import_variables) newvars = self._import_variables() self._clear_profile_vars(newvars) - self._add_variables(newvars) + self._add_variables(newvars, prio=True) # process imported actions (import_actions) self._import_actions() @@ -1042,7 +1042,7 @@ def _import_variables(self): if dvar.keys(): self._shell_exec_dvars(merged, keys=dvar.keys()) self._clear_profile_vars(merged) - newvars = self._merge_dict(newvars, merged) + newvars = self._merge_dict(merged, newvars) if self._debug: self._debug_dict('imported variables', newvars) return newvars From 33cf78c3aea8f6b16971077ee19e89a45049d3b3 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 27 Feb 2023 22:22:19 +0100 Subject: [PATCH 6/8] add test for #380 --- tests-ng/import-variables.sh | 145 +++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100755 tests-ng/import-variables.sh diff --git a/tests-ng/import-variables.sh b/tests-ng/import-variables.sh new file mode 100755 index 000000000..bd5f91ce1 --- /dev/null +++ b/tests-ng/import-variables.sh @@ -0,0 +1,145 @@ +#!/usr/bin/env bash +# author: deadc0de6 (https://github.com/deadc0de6) +# Copyright (c) 2023, deadc0de6 +# +# test import_variables +# returns 1 in case of error +# see issue 380 +# + +# exit on first error +set -e + +# all this crap to get current path +rl="readlink -f" +if ! ${rl} "${0}" >/dev/null 2>&1; then + rl="realpath" + + if ! hash ${rl}; then + echo "\"${rl}\" not found !" && exit 1 + fi +fi +cur=$(dirname "$(${rl} "${0}")") + +#hash dotdrop >/dev/null 2>&1 +#[ "$?" != "0" ] && echo "install dotdrop to run tests" && exit 1 + +#echo "called with ${1}" + +# dotdrop path can be pass as argument +ddpath="${cur}/../" +[ "${1}" != "" ] && ddpath="${1}" +[ ! -d "${ddpath}" ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1 + +export PYTHONPATH="${ddpath}:${PYTHONPATH}" +bin="python3 -m dotdrop.dotdrop" +if hash coverage 2>/dev/null; then + bin="coverage run -p --source=dotdrop -m dotdrop.dotdrop" +fi + +echo "dotdrop path: ${ddpath}" +echo "pythonpath: ${PYTHONPATH}" + +# get the helpers +# shellcheck source=tests-ng/helpers +source "${cur}"/helpers + +echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)" + +################################################################ +# this is the test +################################################################ + +# the dotfile source +tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) +mkdir -p "${tmps}"/dotfiles +# the dotfile destination +tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) + +clear_on_exit "${tmps}" +clear_on_exit "${tmpd}" + +# create the config file +cfg="${tmps}/config.yaml" +cfgvar1="${tmps}/var1.yaml" +cfgvar2="${tmps}/var2.yaml" + +cat << _EOF > "${tmps}/dotfiles/abc" +var1: {{@@ var1 @@}} +var2: {{@@ var2 @@}} +var3: {{@@ var3 @@}} +var4: {{@@ var4 @@}} +var5: {{@@ var5 @@}} +var6: {{@@ var6 @@}} +_EOF + +cat > "${cfg}" << _EOF +config: + backup: true + create: true + dotpath: dotfiles + import_variables: + - ${cfgvar1} + - ${cfgvar2} +variables: + var1: "this is var1 from main config" + var2: "this is var2 from main config" + var3: "this is var3 from main config" +dotfiles: + f_abc: + dst: ${tmpd}/abc + src: 'abc' +profiles: + p1: + dotfiles: + - f_abc +_EOF +echo "main config: ${cfg}" +cat "${cfg}" + +cat << _EOF > "${cfgvar1}" +variables: + var2: "this is var2 from sub1" + var3: "this is var3 from sub1" + var4: "this is var4 from sub1" + var5: "this is var5 from sub1" +_EOF +echo "cfgvar1: ${cfgvar1}" +cat "${cfgvar1}" + +cat << _EOF > "${cfgvar2}" +variables: + var3: "this is var3 from sub2" + var4: "this is var4 from sub2" + var6: "this is var6 from sub2" +_EOF +echo "cfgvar2: ${cfgvar2}" +cat "${cfgvar2}" + +# install +cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 --verbose + +# test file existence +[ -f "${tmpd}/abc" ] || { + echo 'Dotfile not installed' + exit 1 +} + +# test file content +cat "${tmpd}"/abc +echo "----------------------" +grep '^var1: this is var1 from main config$' "${tmpd}"/abc >/dev/null +echo "var1 ok" +grep '^var2: this is var2 from sub1$' "${tmpd}"/abc >/dev/null +echo "var2 ok" +grep '^var3: this is var3 from sub2$' "${tmpd}"/abc >/dev/null +echo "var3 ok" +grep '^var4: this is var4 from sub2$' "${tmpd}"/abc >/dev/null +echo "var4 ok" +grep '^var5: this is var5 from sub1$' "${tmpd}"/abc >/dev/null +echo "var5 ok" +grep '^var6: this is var6 from sub2$' "${tmpd}"/abc >/dev/null +echo "var6 ok" + +echo "OK" +exit 0 From 5f42c6370bbf3ba2542af139903ce0fd943811b1 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 27 Feb 2023 22:28:28 +0100 Subject: [PATCH 7/8] fix doc --- docs/howto/test-latest-dotdrop.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/howto/test-latest-dotdrop.md b/docs/howto/test-latest-dotdrop.md index aef20d316..abe4cfa25 100644 --- a/docs/howto/test-latest-dotdrop.md +++ b/docs/howto/test-latest-dotdrop.md @@ -10,5 +10,5 @@ $ git clone https://github.com/deadc0de6/dotdrop.git $ cd dotdrop ## switch to a specific branch if needed $ git checkout -$ ./dotdrop.sh --config +$ ./dotdrop.sh --cfg ``` \ No newline at end of file From 73dd4b154915bdf8d3095568f4514efe160e874b Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Tue, 28 Feb 2023 09:59:51 +0100 Subject: [PATCH 8/8] more logs --- dotdrop/options.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dotdrop/options.py b/dotdrop/options.py index 76cd7eea5..2ea823146 100644 --- a/dotdrop/options.py +++ b/dotdrop/options.py @@ -157,6 +157,8 @@ def __init__(self, args=None): # selected profile self.profile = self.args['--profile'] self.confpath = self._get_config_path() + self.confpath = os.path.abspath(self.confpath) + self.log.dbg(f'config abs path: {self.confpath}') if not self.confpath: raise YamlException('no config file found') if not os.path.exists(self.confpath):