diff --git a/setup.py b/setup.py index dd6e76a..55ba671 100755 --- a/setup.py +++ b/setup.py @@ -5,6 +5,19 @@ import glob import os import re + +def make_pep440_compliant(version: str) -> str: + """Convert the version into a PEP440 compliant version.""" + public_version_re = re.compile(r"^([0-9][0-9.]*(?:(?:a|b|rc|.post|.dev)[0-9]+)*)\+?") + _, public, local = public_version_re.split(version, maxsplit=1) + if not local: + return version + sanitized_local = re.sub("[+~]+", ".", local).strip(".") + pep440_version = f"{public}+{sanitized_local}" + assert re.match("^[a-zA-Z0-9.]+$", sanitized_local), f"'{pep440_version}' not PEP440 compliant" + return pep440_version + + # look/set what version we have changelog = "debian/changelog" if os.path.exists(changelog): @@ -67,7 +80,7 @@ data_files = [ if __name__ == '__main__': setup( name='ubuntu-dev-tools', - version=version, + version=make_pep440_compliant(version), scripts=scripts, packages=[ 'ubuntutools',