Skip to content

Commit

Permalink
validate parsed version
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaslovsky committed Sep 5, 2020
1 parent 57be484 commit cbd5705
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
from setuptools import setup


Expand All @@ -22,11 +23,16 @@ def parse_version(version_str: str) -> str:
Parse the package version
:param version_str: string of the form "__version__ = 'x.y.z'"
"""
version_str = version_str.strip('\n')
try:
version = version_str.split('=')[1]
except IndexError:
return 'unknown'
return version.strip(' \'\"\n')
raise RuntimeError(f'cannot parse version from [{version_str}]')
version = version.strip(' \'\"')
# validate version
if not re.match(r'^(\d+).(\d+).(\d+)$', version):
raise RuntimeError(f'parsed invalid version [{version}] from [{version_str}]')
return version


setup(
Expand Down

0 comments on commit cbd5705

Please sign in to comment.