Skip to content

Commit 9cb18e8

Browse files
Merge pull request #122 from free-soellingeraj/soellingeraj/version-travis-checker
Soellingeraj/version travis checker
2 parents 7bb2f9d + 62312dd commit 9cb18e8

File tree

4 files changed

+79
-4
lines changed

4 files changed

+79
-4
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ matrix:
88
- python: 3.8
99
install:
1010
- pip install tox-travis
11-
script: tox
11+
script:
12+
- tox
13+
- /bin/bash scripts/check_version.sh $TRAVIS_PULL_REQUEST

scripts/check_version.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import argparse
2+
from packaging import version
3+
4+
5+
def compare_versions(v_str1, v_str2):
6+
"""
7+
Compares two version strings.
8+
9+
In:
10+
v_str1: str, __version__ string
11+
v_str2: str, __version__ string
12+
13+
Returns:
14+
'>' | '==' | '<', reads v_str1 (x) v_str2
15+
"""
16+
17+
p_str1 = version.parse(v_str1)
18+
p_str2 = version.parse(v_str2)
19+
if p_str1 > p_str2:
20+
return '>'
21+
22+
if p_str1 == p_str2:
23+
return '=='
24+
25+
return '<'
26+
27+
28+
if __name__ == "__main__":
29+
parser = argparse.ArgumentParser(description='Check versions.')
30+
parser.add_argument('--pr_v', type=str, help='mplfinance.__version__ for the PR')
31+
parser.add_argument('--in_v', type=str, help='mplfinance.__version__ for the `master` branch')
32+
33+
args = parser.parse_args()
34+
test_tag = 'VersionCheck:{}'
35+
outcome = compare_versions(
36+
v_str1=args.pr_v,
37+
v_str2=args.in_v
38+
)
39+
print(test_tag.format('pr{}master'.format(outcome)))

scripts/check_version.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
# Run this script test.sh from project root directory containing setup.py
3+
4+
set -ev
5+
6+
pr_branch=$1
7+
if [ "${pr_branch}" == "false" ]
8+
# All integrations pass if they're merged without a PR.
9+
then
10+
exit 0
11+
fi
12+
13+
echo "PR: branch passed in: $pr_branch"
14+
git fetch origin +refs/pull/${pr_branch}/merge
15+
git checkout FETCH_HEAD
16+
pip3 install .
17+
pr_version=$(python3 -c "import mplfinance; print(mplfinance.__version__)")
18+
git checkout master
19+
pip3 install .
20+
in_version=$(python3 -c "import mplfinance; print(mplfinance.__version__)")
21+
echo "PR: ${pr_version}; Incumbent: ${in_version}"
22+
23+
# test the versions
24+
git checkout FETCH_HEAD
25+
pip3 install .
26+
result=$(python3 scripts/check_version.py --pr_v ${pr_version} --in_v ${in_version})
27+
if [ "${result}" != "VersionCheck:pr>master" ]
28+
then
29+
# version in PR doesn't pass the test
30+
echo "${result}"
31+
exit 1
32+
fi
33+
echo "VersionCheck PASSED with response: ${result}"

src/mplfinance/_version.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
version_info = (0, 12, 4, 'alpha', 0)
21

3-
_specifier_ = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc', 'final': ''}
2+
version_info = (0, 12, 4, 'alpha', 1)
3+
4+
_specifier_ = {'alpha': 'a','beta': 'b','candidate': 'rc','final': ''}
45

56
__version__ = '%s.%s.%s%s'%(version_info[0], version_info[1], version_info[2],
6-
'' if version_info[3]=='final' else _specifier_[version_info[3]]+str(version_info[4]))
7+
'' if version_info[3]=='final' else _specifier_[version_info[3]]+str(version_info[4]))

0 commit comments

Comments
 (0)