Skip to content

Commit 2b1f45b

Browse files
committed
Calculate version dinamically from a tuple
1 parent 78ac86f commit 2b1f45b

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

mailjet_rest/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env python
22
# coding=utf-8
3+
from mailjet_rest.client import Client
4+
from mailjet_rest.utils.version import get_version
35

4-
from .client import Client
6+
__version__ = get_version()
57

6-
from ._version import __version__
7-
__all__ = (Client,)
8+
__all__ = (Client, get_version)

mailjet_rest/_version.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

mailjet_rest/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import requests
88
from requests.compat import urljoin
9-
from ._version import __version__
9+
from .utils.version import get_version
1010

1111
requests.packages.urllib3.disable_warnings()
1212

@@ -15,7 +15,7 @@ class Config(object):
1515
API_URL = 'https://api.mailjet.com/'
1616
API_REF = 'http://dev.mailjet.com/email-api/v3/'
1717
version = 'v3'
18-
user_agent = 'mailjet-apiv3-python/' + __version__
18+
user_agent = 'mailjet-apiv3-python/' + get_version()
1919

2020
def __init__(self, version=None):
2121
if version is not None:

mailjet_rest/utils/version.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
VERSION = (1, 3, 0)
2+
3+
4+
def get_version(version=None):
5+
'''
6+
Calculate package version based on a 3 item tuple.
7+
In addition verify that the tuple contains 3 items
8+
'''
9+
if version is None:
10+
version = VERSION
11+
else:
12+
assert len(version) == 3
13+
return 'v{0}.{1}.{2}'.format(*(x for x in version))

setup.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22
# coding=utf-8
33

44
import os
5-
import re
65
from setuptools import setup
76

87
HERE = os.path.abspath(os.path.dirname(__file__))
98
PACKAGE_NAME = 'mailjet_rest'
109

11-
# Taken from https://stackoverflow.com/a/39671214/1506051
12-
__version__ = re.search(
13-
r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]', # It excludes inline comment too
14-
open('mailjet_rest/_version.py').read()).group(1)
10+
import ipdb; ipdb.set_trace()
11+
# Dynamically calculate the version based on mailjet_rest.VERSION.
12+
version = __import__('mailjet_rest').get_version()
1513

1614
setup(
1715
name=PACKAGE_NAME,
18-
version=__version__,
16+
version=version,
1917
author='starenka',
2018
author_email='[email protected]',
2119
maintainer='Mailjet',
2220
maintainer_email='[email protected]',
23-
download_url='https://github.com/mailjet/mailjet-apiv3-python/releases/tag/v'+__version__,
21+
download_url='https://github.com/mailjet/mailjet-apiv3-python/releases/tag/v' + version,
2422
url='https://github.com/mailjet/mailjet-apiv3-python',
2523
description=('Mailjet V3 API wrapper'),
2624
classifiers=['Development Status :: 3 - Alpha',

0 commit comments

Comments
 (0)