Skip to content

Commit 31056f0

Browse files
authored
Merge pull request #12 from mailjet/package-version
Improve Package version
2 parents 78ac86f + 4ebe4d2 commit 31056f0

File tree

7 files changed

+33
-23
lines changed

7 files changed

+33
-23
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/__init__.py

Whitespace-only changes.

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: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,22 @@
22
# coding=utf-8
33

44
import os
5-
import re
6-
from setuptools import setup
5+
from setuptools import find_packages, 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+
# Dynamically calculate the version based on mailjet_rest.VERSION.
11+
version = __import__('mailjet_rest').get_version()
1512

1613
setup(
1714
name=PACKAGE_NAME,
18-
version=__version__,
15+
version=version,
1916
author='starenka',
2017
author_email='[email protected]',
2118
maintainer='Mailjet',
2219
maintainer_email='[email protected]',
23-
download_url='https://github.com/mailjet/mailjet-apiv3-python/releases/tag/v'+__version__,
20+
download_url='https://github.com/mailjet/mailjet-apiv3-python/releases/tag/v' + version,
2421
url='https://github.com/mailjet/mailjet-apiv3-python',
2522
description=('Mailjet V3 API wrapper'),
2623
classifiers=['Development Status :: 3 - Alpha',
@@ -41,5 +38,5 @@
4138
install_requires=['requests>=2.4.3'],
4239
tests_require=['unittest'],
4340
entry_points={},
44-
packages=['mailjet_rest'],
41+
packages=find_packages(),
4542
)

test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from mailjet_rest import Client, __version__
2+
from mailjet_rest import Client
33
import os
44
import random
55
import string
@@ -52,12 +52,12 @@ def test_get_with_action(self):
5252
list_id = post_contact_list.json()['Data'][0]['ID']
5353

5454
data = {
55-
'ContactsLists': [
56-
{
57-
"ListID": list_id,
58-
"Action": "addnoforce"
59-
}
60-
]
55+
'ContactsLists': [
56+
{
57+
"ListID": list_id,
58+
"Action": "addnoforce"
59+
}
60+
]
6161
}
6262
result_add_list = self.client.contact_managecontactslists.create(id=contact_id, data=data)
6363
self.assertTrue(result_add_list.status_code == 201)
@@ -90,7 +90,7 @@ def test_user_agent(self):
9090
auth=self.auth,
9191
version='v3.1'
9292
)
93-
self.assertEqual(self.client.config.user_agent, 'mailjet-apiv3-python/'+__version__)
93+
self.assertEqual(self.client.config.user_agent, 'mailjet-apiv3-python/v1.3.0')
9494

9595

9696
if __name__ == '__main__':

0 commit comments

Comments
 (0)