Skip to content

Commit 4b40857

Browse files
committed
Fix __version__ import.
There were circular import issues most notably during install. `setup.py` now grabs the version information without having to import the module (which led to importing other modules which isn't appropriate during setup.py activities).
1 parent 40be69d commit 4b40857

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
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
@@ -37,7 +38,7 @@ def __init__(self, key=None, user_agent=USER_AGENT, timeout=60):
3738
3839
:returns: None
3940
"""
40-
self.user_agent = user_agent
41+
self.user_agent = user_agent or get_user_agent()
4142
self.timeout = timeout
4243
self.key = key
4344
self.services = []

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='support@embed.ly',
2630
description='Python Library for Embedly',

0 commit comments

Comments
 (0)