Skip to content

Commit 88d180e

Browse files
fernandocollovamarkchalloner
authored andcommitted
Add setup.py version plugin (#37)
* Updated documentation * Ranamed plugin to ensure execution order * Fixed sed regex * Added comment about non-extended regex syntax
1 parent 4a00f79 commit 88d180e

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

PLUGINS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ The [`package.json`] file is used by [NPM], typically for [Node.js] applications
7676
}
7777
```
7878

79+
### Python `setup.py` - [`setuppy_update.sh`]
80+
81+
This plugin makes sure you never forget to update your package version.
82+
83+
When active, it will search for a setup.py file in the root of the project, and change the `version` argument passed to the setup class to the version being tagged. Then, it will commit it with a "Updated setup.py version" message.
84+
7985
## Contributing
8086

8187
A plugin can be any executable file stored in `.git-semver/plugins/`.

plugins/10-setuppy_update.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
function run() {
4+
5+
local version_new="$1"
6+
local git_root="$5"
7+
8+
local setuppy_path="${git_root}/setup.py"
9+
10+
if [ ! -e "${setuppy_path}" ]
11+
then
12+
echo "Could not find setup.py on the project root."
13+
return 112
14+
fi
15+
16+
tmpfile=$(mktemp)
17+
# Extended regexs are purposely avoided for Mac OS and Free BSD compatbility.
18+
sed "s/version[[:blank:]]*=[[:blank:]]*[\",'][0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*[\"'][[:blank:]]*,/version=\"${version_new}\",/" < "${git_root}/setup.py" > "${tmpfile}"
19+
cat "${tmpfile}" > "${setuppy_path}"
20+
rm -f "${tmpfile}"
21+
22+
git add "${setuppy_path}"
23+
git commit "${setuppy_path}" -m "Updated setup.py version"
24+
return 0
25+
26+
}
27+
28+
case "${1}" in
29+
--about)
30+
echo -n "Change the version argument of the project's setup.py to the new created version."
31+
;;
32+
*)
33+
run "$@"
34+
;;
35+
esac

0 commit comments

Comments
 (0)