-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_readmes
executable file
·86 lines (58 loc) · 1.67 KB
/
update_readmes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
shopt -s nullglob
if [[ ! -d .exercism ]]; then
printf "ERROR: Run from inside a project directory.\n\n"
exit 1
fi
declare package_name
declare project_dir
get_python_package_name() {
basename "${PWD}"
} # get_python_package_name()
package_name="$(get_python_package_name)"
project_dir="$(basename "${PWD}")"
if ! grep -q ./"${project_dir}"/README.md ../README.md; then
cat >>../README.md <<EOF
- [${project_dir}](./${project_dir}/README.md)
EOF
fi
if ! grep -q "my solution" ./README.md; then
# Two empty spaces because the file is missing a trailing new line.
cat >>./README.md <<EOF
### My Solution
- [my solution]($(printf "%s\n" ./*[.]py | grep -v "_test[.]py"))
EOF
cat >>./README.md <<EOF
- [run-tests](./run-tests-python.txt)
EOF
fi
printf "\n"
git add ../README.md ./README.md
git diff --cached ../README.md ./README.md
printf "\n"
mkdir -pv "./src/${package_name//-/_}" ./test
[[ -d src/${package_name//-/_}/__init__.py ]] || touch "src/${package_name//-/_}/__init__.py"
[[ -d test/__init__.py ]] || touch test/__init__.py
declare -a SOLUTION_FILES
mapfile -t SOLUTION_FILES < <(jq -r '.files.solution[]' .exercism/config.json)
for f in "${SOLUTION_FILES[@]}"; do
ln -svf ../../"${f}" "src/${package_name//-/_}/"
done
declare -a TEST_FILES
mapfile -t TEST_FILES < <(jq -r '.files.test[]' .exercism/config.json)
for f in "${TEST_FILES[@]}"; do
ln -svf "../${f}" "./test/"
done
[[ -f .coveragerc ]] || cp -v ../.coveragerc .
cat >pytest.ini <<EOF
[pytest]
pythonpath = .
addopts = --doctest-modules
markers =
task: exercise task/step
EOF
ln -svf ../.pylintrc .pylintrc
git add ./src ./test .coveragerc pytest.ini .pylintrc
printf "\n"
cd ..
printf "\n"