Skip to content

Commit 88a2ca6

Browse files
committed
PEP 440 versions
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent a766ae7 commit 88a2ca6

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

setup.py

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
import os
66
import platform
7-
import sys
7+
import re
88
import subprocess
9+
import sys
910

1011
from distutils.command.build import build
1112
from setuptools import setup
@@ -34,6 +35,52 @@
3435

3536

3637
# version handling
38+
39+
40+
def git_describe_to_python_version(version):
41+
"""Convert output from git describe to PEP 440 conforming versions."""
42+
43+
version_info = version.split('-')
44+
if len(version_info) < 2:
45+
return 'unknown'
46+
47+
# we always have $version-$release
48+
release_type = version_info[1]
49+
50+
version_data = {
51+
'version': version_info[0],
52+
'release_type': release_type,
53+
}
54+
if len(version_info) == 4:
55+
version_data['commits'] = version_info[2]
56+
else:
57+
version_data['commits'] = 0
58+
59+
if release_type == 'release':
60+
if len(version_info) == 2:
61+
# format: $version-release
62+
# This is the case at time of the release.
63+
fmt = '{version}'
64+
elif len(version_info) == 4:
65+
# format: $version-release-$commits-$hash
66+
# This is the case after a release.
67+
fmt = '{version}-{commits}'
68+
elif release_type == 'dev':
69+
# format: $version-dev-$commits-$hash or $version-dev
70+
fmt = '{version}.dev{commits}'
71+
else:
72+
match = re.match(r'^(alpha|beta|rc)(\d*)$', release_type)
73+
if match is None:
74+
return 'unknown'
75+
76+
if len(version_info) == 2:
77+
fmt = '{version}{release_type}'
78+
elif len(version_info) == 4:
79+
fmt = '{version}{release_type}-{commits}'
80+
81+
return fmt.format(**version_data)
82+
83+
3784
version_file = 'bpython/_version.py'
3885
version = 'unknown'
3986

@@ -46,13 +93,7 @@
4693
stdout = stdout.decode('ascii')
4794

4895
if proc.returncode == 0:
49-
version_split = stdout.split('-')
50-
if len(version_split) == 4:
51-
# format: version-release-commits-hash
52-
version = '-'.join((version_split[0], version_split[2]))
53-
elif len(version_split) == 2:
54-
# format: version-release
55-
version = version_split[0]
96+
version = git_describe_to_python_version(stdout)
5697
except OSError:
5798
pass
5899

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy