Skip to content

Commit e8fedb3

Browse files
committed
Merge pull request #19 from joncotton/fix_version_import
Fix version import. `__init__.py` is the canonical location
2 parents 40be69d + 7848681 commit e8fedb3

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

embedly/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
from __future__ import absolute_import
2-
from .client import Embedly, __version__
2+
from .client import Embedly
3+
4+
__version__ = '0.4.3'

embedly/client.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,34 @@
1717
from .models import Url
1818

1919

20-
__version__ = '0.4.3'
21-
USER_AGENT = 'Mozilla/5.0 (compatible; embedly-python/%s;)' % __version__
20+
def get_user_agent():
21+
from . import __version__
22+
return 'Mozilla/5.0 (compatible; embedly-python/%s;)' % __version__
2223

2324

2425
class Embedly(object):
2526
"""
2627
Client
2728
2829
"""
29-
def __init__(self, key=None, user_agent=USER_AGENT, timeout=60):
30+
def __init__(self, key=None, user_agent=None, timeout=60):
3031
"""
3132
Initialize the Embedly client
3233
33-
:param user_agent: User Agent passed to Embedly
34-
:type user_agent: str
3534
:param key: Embedly Pro key
3635
:type key: str
36+
:param user_agent: User Agent passed to Embedly
37+
:type user_agent: str
38+
:param timeout: timeout for HTTP connection attempts
39+
:type timeout: int
3740
3841
:returns: None
3942
"""
40-
self.user_agent = user_agent
41-
self.timeout = timeout
4243
self.key = key
43-
self.services = []
44+
self.user_agent = user_agent or get_user_agent()
45+
self.timeout = timeout
4446

47+
self.services = []
4548
self._regex = None
4649

4750
def get_services(self):

setup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
if sys.version_info[:2] < (2, 6):
1111
required.append('simplejson')
1212

13-
version = __import__('embedly').__version__
13+
def get_version():
14+
with open(os.path.join('embedly', '__init__.py')) as f:
15+
for line in f:
16+
if line.startswith('__version__ ='):
17+
return line.split('=')[1].strip().strip('"\'')
1418

1519
if os.path.exists("README.rst"):
1620
long_description = codecs.open("README.rst", "r", "utf-8").read()
@@ -20,7 +24,7 @@
2024

2125
setup(
2226
name='Embedly',
23-
version=version,
27+
version=get_version(),
2428
author='Embed.ly, Inc.',
2529
author_email='[email protected]',
2630
description='Python Library for Embedly',

0 commit comments

Comments
 (0)