Skip to content

Commit ab90cdf

Browse files
committed
Improved package versioning.
1 parent af57ecf commit ab90cdf

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
recursive-exclude tests

graphql/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from graphql import parse
2222
from graphql.language.base import parse
2323
'''
24-
24+
from .pyutils.version import get_version
2525

2626
# The primary entry point into fulfilling a GraphQL request.
2727
from .graphql import (
@@ -157,6 +157,11 @@
157157
assert_valid_name,
158158
)
159159

160+
161+
VERSION = (0, 5, 0, 'beta', 1)
162+
163+
__version__ = get_version(VERSION)
164+
160165
__all__ = (
161166
'graphql',
162167
'GraphQLBoolean',

graphql/pyutils/version.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from __future__ import unicode_literals
2+
3+
import datetime
4+
import os
5+
import subprocess
6+
7+
8+
def get_version(version=None):
9+
"Returns a PEP 440-compliant version number from VERSION."
10+
version = get_complete_version(version)
11+
12+
# Now build the two parts of the version number:
13+
# main = X.Y[.Z]
14+
# sub = .devN - for pre-alpha releases
15+
# | {a|b|rc}N - for alpha, beta, and rc releases
16+
17+
main = get_main_version(version)
18+
19+
sub = ''
20+
if version[3] == 'alpha' and version[4] == 0:
21+
git_changeset = get_git_changeset()
22+
if git_changeset:
23+
sub = '.dev%s' % git_changeset
24+
25+
elif version[3] != 'final':
26+
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'rc'}
27+
sub = mapping[version[3]] + str(version[4])
28+
29+
return str(main + sub)
30+
31+
32+
def get_main_version(version=None):
33+
"Returns main version (X.Y[.Z]) from VERSION."
34+
version = get_complete_version(version)
35+
parts = 2 if version[2] == 0 else 3
36+
return '.'.join(str(x) for x in version[:parts])
37+
38+
39+
def get_complete_version(version=None):
40+
"""Returns a tuple of the graphql version. If version argument is non-empty,
41+
then checks for correctness of the tuple provided.
42+
"""
43+
if version is None:
44+
from graphql import VERSION as version
45+
else:
46+
assert len(version) == 5
47+
assert version[3] in ('alpha', 'beta', 'rc', 'final')
48+
49+
return version
50+
51+
52+
def get_docs_version(version=None):
53+
version = get_complete_version(version)
54+
if version[3] != 'final':
55+
return 'dev'
56+
else:
57+
return '%d.%d' % version[:2]
58+
59+
60+
def get_git_changeset():
61+
"""Returns a numeric identifier of the latest git changeset.
62+
The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
63+
This value isn't guaranteed to be unique, but collisions are very unlikely,
64+
so it's sufficient for generating the development version numbers.
65+
"""
66+
repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
67+
git_log = subprocess.Popen(
68+
'git log --pretty=format:%ct --quiet -1 HEAD',
69+
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
70+
shell=True, cwd=repo_dir, universal_newlines=True,
71+
)
72+
timestamp = git_log.communicate()[0]
73+
try:
74+
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
75+
except ValueError:
76+
return None
77+
return timestamp.strftime('%Y%m%d%H%M%S')

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from setuptools import setup, find_packages
22

3+
version = __import__('graphql').get_version()
4+
35
setup(
46
name='graphql-core',
5-
version='0.4.18',
7+
version=version,
68
description='GraphQL implementation for Python',
79
url='https://github.com/graphql-python/graphql-core',
810
download_url='https://github.com/graphql-python/graphql-core/releases',

0 commit comments

Comments
 (0)