Skip to content

Commit 7358101

Browse files
committed
Merge branch 'master' of github.com:deadc0de6/dotdrop
2 parents 5946a1c + 73dd4b1 commit 7358101

File tree

9 files changed

+184
-6
lines changed

9 files changed

+184
-6
lines changed

docs/config/config-dotfiles.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ executed when the dotfile is installed (that is, when
5151
the version present in dotdrop differs from the one
5252
in the filesystem).
5353
54-
For example, let's consider
55-
[Vundle](https://github.com/VundleVim/Vundle.vim), used
54+
For example, let's consider Vundle, used
5655
to manage Vim's plugins. The following action could
5756
be set to update and install the plugins when `vimrc` is
5857
deployed:

docs/howto/test-latest-dotdrop.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Test latest dotdrop
2+
3+
If you installed dotdrop from a package but want to test
4+
you current setup with the latest version from git
5+
(or from a specific branch), you can do the following
6+
7+
```bash
8+
$ cd /tmp/
9+
$ git clone https://github.com/deadc0de6/dotdrop.git
10+
$ cd dotdrop
11+
## switch to a specific branch if needed
12+
$ git checkout <branch-name>
13+
$ ./dotdrop.sh --cfg <path-to-your-config-file.yaml>
14+
```

dotdrop/cfg_aggregator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,37 +274,48 @@ def _load(self, reloading=False):
274274
reloading=reloading,
275275
debug=self.debug)
276276

277+
self.log.dbg('parsing cfgyaml into cfg_aggregator')
278+
277279
# settings
280+
self.log.dbg('parsing settings')
278281
self.settings = Settings.parse(None, self.cfgyaml.settings)
279282
self.key_prefix = self.settings.key_prefix
280283
self.key_separator = self.settings.key_separator
281284

282285
# dotfiles
286+
self.log.dbg('parsing dotfiles')
283287
self.dotfiles = Dotfile.parse_dict(self.cfgyaml.dotfiles)
284288
debug_list('dotfiles', self.dotfiles, self.debug)
285289

286290
# profiles
291+
self.log.dbg('parsing profiles')
287292
self.profiles = Profile.parse_dict(self.cfgyaml.profiles)
288293
debug_list('profiles', self.profiles, self.debug)
289294

290295
# actions
296+
self.log.dbg('parsing actions')
291297
self.actions = Action.parse_dict(self.cfgyaml.actions)
292298
debug_list('actions', self.actions, self.debug)
293299

294300
# trans_r
301+
self.log.dbg('parsing trans_r')
295302
self.trans_r = Transform.parse_dict(self.cfgyaml.trans_r)
296303
debug_list('trans_r', self.trans_r, self.debug)
297304

298305
# trans_w
306+
self.log.dbg('parsing trans_w')
299307
self.trans_w = Transform.parse_dict(self.cfgyaml.trans_w)
300308
debug_list('trans_w', self.trans_w, self.debug)
301309

302310
# variables
311+
self.log.dbg('parsing variables')
303312
self.variables = self.cfgyaml.variables
304313
debug_dict('variables', self.variables, self.debug)
305314

315+
self.log.dbg('enrich variables')
306316
self._enrich_variables()
307317

318+
self.log.dbg('patch keys...')
308319
# patch dotfiles in profiles
309320
self._patch_keys_to_objs(self.profiles,
310321
"dotfiles", self.get_dotfile)
@@ -333,6 +344,8 @@ def _load(self, reloading=False):
333344
self._get_trans_w_args(self.get_trans_w),
334345
islist=False)
335346

347+
self.log.dbg('done parsing cfgyaml into cfg_aggregator')
348+
336349
def _enrich_variables(self):
337350
"""
338351
enrich available variables

dotdrop/cfg_yaml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def __init__(self, path, profile=None, addprofiles=None,
256256
# process imported variables (import_variables)
257257
newvars = self._import_variables()
258258
self._clear_profile_vars(newvars)
259-
self._add_variables(newvars)
259+
self._add_variables(newvars, prio=True)
260260

261261
# process imported actions (import_actions)
262262
self._import_actions()
@@ -1042,7 +1042,7 @@ def _import_variables(self):
10421042
if dvar.keys():
10431043
self._shell_exec_dvars(merged, keys=dvar.keys())
10441044
self._clear_profile_vars(merged)
1045-
newvars = self._merge_dict(newvars, merged)
1045+
newvars = self._merge_dict(merged, newvars)
10461046
if self._debug:
10471047
self._debug_dict('imported variables', newvars)
10481048
return newvars

dotdrop/options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ def __init__(self, args=None):
157157
# selected profile
158158
self.profile = self.args['--profile']
159159
self.confpath = self._get_config_path()
160+
self.confpath = os.path.abspath(self.confpath)
161+
self.log.dbg(f'config abs path: {self.confpath}')
160162
if not self.confpath:
161163
raise YamlException('no config file found')
162164
if not os.path.exists(self.confpath):

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ nav:
4343
- 'Prompt user for variables': 'howto/prompt-user-for-variables.md'
4444
- 'Share content across dotfiles': 'howto/sharing-content.md'
4545
- 'Symlink dotfiles': 'howto/symlink-dotfiles.md'
46+
- 'Test latest dotdrop': 'howto/test-latest-dotdrop.md'
4647
- '': ''
4748
- '': ''
4849
markdown_extensions:

tests-ng/import-variables.sh

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#!/usr/bin/env bash
2+
# author: deadc0de6 (https://github.com/deadc0de6)
3+
# Copyright (c) 2023, deadc0de6
4+
#
5+
# test import_variables
6+
# returns 1 in case of error
7+
# see issue 380
8+
#
9+
10+
# exit on first error
11+
set -e
12+
13+
# all this crap to get current path
14+
rl="readlink -f"
15+
if ! ${rl} "${0}" >/dev/null 2>&1; then
16+
rl="realpath"
17+
18+
if ! hash ${rl}; then
19+
echo "\"${rl}\" not found !" && exit 1
20+
fi
21+
fi
22+
cur=$(dirname "$(${rl} "${0}")")
23+
24+
#hash dotdrop >/dev/null 2>&1
25+
#[ "$?" != "0" ] && echo "install dotdrop to run tests" && exit 1
26+
27+
#echo "called with ${1}"
28+
29+
# dotdrop path can be pass as argument
30+
ddpath="${cur}/../"
31+
[ "${1}" != "" ] && ddpath="${1}"
32+
[ ! -d "${ddpath}" ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1
33+
34+
export PYTHONPATH="${ddpath}:${PYTHONPATH}"
35+
bin="python3 -m dotdrop.dotdrop"
36+
if hash coverage 2>/dev/null; then
37+
bin="coverage run -p --source=dotdrop -m dotdrop.dotdrop"
38+
fi
39+
40+
echo "dotdrop path: ${ddpath}"
41+
echo "pythonpath: ${PYTHONPATH}"
42+
43+
# get the helpers
44+
# shellcheck source=tests-ng/helpers
45+
source "${cur}"/helpers
46+
47+
echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
48+
49+
################################################################
50+
# this is the test
51+
################################################################
52+
53+
# the dotfile source
54+
tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
55+
mkdir -p "${tmps}"/dotfiles
56+
# the dotfile destination
57+
tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
58+
59+
clear_on_exit "${tmps}"
60+
clear_on_exit "${tmpd}"
61+
62+
# create the config file
63+
cfg="${tmps}/config.yaml"
64+
cfgvar1="${tmps}/var1.yaml"
65+
cfgvar2="${tmps}/var2.yaml"
66+
67+
cat << _EOF > "${tmps}/dotfiles/abc"
68+
var1: {{@@ var1 @@}}
69+
var2: {{@@ var2 @@}}
70+
var3: {{@@ var3 @@}}
71+
var4: {{@@ var4 @@}}
72+
var5: {{@@ var5 @@}}
73+
var6: {{@@ var6 @@}}
74+
_EOF
75+
76+
cat > "${cfg}" << _EOF
77+
config:
78+
backup: true
79+
create: true
80+
dotpath: dotfiles
81+
import_variables:
82+
- ${cfgvar1}
83+
- ${cfgvar2}
84+
variables:
85+
var1: "this is var1 from main config"
86+
var2: "this is var2 from main config"
87+
var3: "this is var3 from main config"
88+
dotfiles:
89+
f_abc:
90+
dst: ${tmpd}/abc
91+
src: 'abc'
92+
profiles:
93+
p1:
94+
dotfiles:
95+
- f_abc
96+
_EOF
97+
echo "main config: ${cfg}"
98+
cat "${cfg}"
99+
100+
cat << _EOF > "${cfgvar1}"
101+
variables:
102+
var2: "this is var2 from sub1"
103+
var3: "this is var3 from sub1"
104+
var4: "this is var4 from sub1"
105+
var5: "this is var5 from sub1"
106+
_EOF
107+
echo "cfgvar1: ${cfgvar1}"
108+
cat "${cfgvar1}"
109+
110+
cat << _EOF > "${cfgvar2}"
111+
variables:
112+
var3: "this is var3 from sub2"
113+
var4: "this is var4 from sub2"
114+
var6: "this is var6 from sub2"
115+
_EOF
116+
echo "cfgvar2: ${cfgvar2}"
117+
cat "${cfgvar2}"
118+
119+
# install
120+
cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 --verbose
121+
122+
# test file existence
123+
[ -f "${tmpd}/abc" ] || {
124+
echo 'Dotfile not installed'
125+
exit 1
126+
}
127+
128+
# test file content
129+
cat "${tmpd}"/abc
130+
echo "----------------------"
131+
grep '^var1: this is var1 from main config$' "${tmpd}"/abc >/dev/null
132+
echo "var1 ok"
133+
grep '^var2: this is var2 from sub1$' "${tmpd}"/abc >/dev/null
134+
echo "var2 ok"
135+
grep '^var3: this is var3 from sub2$' "${tmpd}"/abc >/dev/null
136+
echo "var3 ok"
137+
grep '^var4: this is var4 from sub2$' "${tmpd}"/abc >/dev/null
138+
echo "var4 ok"
139+
grep '^var5: this is var5 from sub1$' "${tmpd}"/abc >/dev/null
140+
echo "var5 ok"
141+
grep '^var6: this is var6 from sub2$' "${tmpd}"/abc >/dev/null
142+
echo "var6 ok"
143+
144+
echo "OK"
145+
exit 0

tests-requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ coveralls; python_version > '3.5'
55
pyflakes; python_version > '3.5'
66
pylint; python_version > '3.5'
77
halo; python_version > '3.5'
8-
distro; python_version > '3.5'
8+
distro; python_version > '3.5'
9+
urllib3; python_version > '3.5'

tests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ if [ "${dotdrop_version}" != "${man_version}" ]; then
2323
echo "ERROR version.py (${dotdrop_version}) and manpage (${man_version}) differ!"
2424
exit 1
2525
fi
26-
echo "current version ${dotdrop_version}"
26+
echo "current dotdrop version ${dotdrop_version}"
27+
28+
echo "=> python version:"
29+
python3 --version
2730

2831
# test syntax
2932
echo "checking syntax..."

0 commit comments

Comments
 (0)