-
Notifications
You must be signed in to change notification settings - Fork 152
Fix __init.py__ version import error #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Simple import fix allows segment.io analytics to import on Python 3.3.2
Adding .travis.yml to root to allow automated builds to check compatibility with Python 2.
```
>BEFORE<
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import analytics
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "REDACTED\python\3.3.2\lib\site-packages\analytics\__init__.py", line 2, in <module>
import version
ImportError: No module named 'version'
>>>
>AFTER<
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import analytics
>>>
```
Initial travis script.
* missing key language, defaulting to ruby * specified python, but setting is not relevant for ruby
Install analytics-python on travis
Test analytics import.
Weblint did not detect this. Not sure if this is causing travis not to build properly. https://travis-ci.org/duly/analytics-python
Please override the script: key in your .travis.yml to run tests.
|
segment.io's python analytics software fails Python 3.2 and 3.3 |
```
$ python -c "import analytics"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "analytics/__init__.py", line 9, in <module>
from stats import Statistics
ImportError: No module named stats
```
|
This pull request makes segmentio / analytics-python minimally compatible with Python 2.6, 2.7, 3.3 and 3.4. |
```
>>> analytics.init('testsecret', async=False, flush_at=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\REDACTED\analytics\__init__.py", line 33, in init
from client import Client
ImportError: No module named 'client'
```
Relegate python -c "import analytics" to a before_script. Actually run the test.py script in preparation for nose_tests.
|
Since test .py was added in 453b26d Python 3.2.3 and 3.4 builds fail. Python 3 fails. Python 2.6 and 2.7 are successful. |
Include brackets around print function for Python 3. There still may be Python 2to3 issues for Python 3 compatibility.
```
File "test.py", line 64
'unicode': u'woo',
^
SyntaxError: invalid syntax
```
11 Tests Fail due to the issues on Lines 11-13.
>EXAMPLE<
```
Traceback (most recent call last):
File "test.py", line 37, in setUp
analytics.init(secret, log_level=logging.DEBUG)
File "/home/travis/build/duly/analytics-python/analytics/__init__.py", line 33, in init
from analytics.client import Client
File "/home/travis/build/duly/analytics-python/analytics/client.py", line 11, in <module>
from stats import Statistics
ImportError: No module named stats
```
Python 2.7 and 2.6 fail horribly due to this modification.
importing as to avoid naming issues.
```
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/home/travis/build/duly/analytics-python/analytics/client.py", line 96, in run
self.client._sync_flush()
File "/home/travis/build/duly/analytics-python/analytics/client.py", line 484, in _sync_flush
url = options.host + options.endpoints['batch']
NameError: global name 'options' is not defined
```
Attempting to provide python 3 compatibility with six. ``` NameError: global name 'unicode' is not defined ```
``` NameError: global name 'long' is not defined ```
``` AttributeError: 'dict' object has no attribute 'iteritems' ```
Similar to: duly/pyjs@311f7c6 One (1) test fails in each Python 3.3 and 3.4. ``` Traceback (most recent call last): File "test.py", line 77, in test_clean combined = dict(simple.items() + complicated.items()) TypeError: unsupported operand type(s) for +: 'dict_items' and 'dict_items' ```
``` NameError: global name 'unicode' is not defined ``` https://travis-ci.org/duly/analytics-python/jobs/21861913#L1198 http://pythonhosted.org//six/#six.u
http://docs.python.org/2/howto/unicode.html http://docs.python.org/release/3.0.1/howto/unicode.html ``` Traceback (most recent call last): File "test.py", line 82, in test_clean analytics.default_client._clean(combined) File "/home/travis/build/duly/analytics-python/analytics/client.py", line 203, in _clean return self._clean_dict(item) File "/home/travis/build/duly/analytics-python/analytics/client.py", line 189, in _clean_dict data[k] = self._clean(v) File "/home/travis/build/duly/analytics-python/analytics/client.py", line 205, in _clean return self._coerce_unicode(item) File "/home/travis/build/duly/analytics-python/analytics/client.py", line 180, in _coerce_unicode return six.u(cmplx) File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/six.py", line 528, in u return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape") AttributeError: 'exceptions.Exception' object has no attribute 'replace' ```
Determine what is causing the exception by encapsulating cmplx in a try-except block.
```
Traceback (most recent call last):
File "test.py", line 82, in test_clean
analytics.default_client._clean(combined)
File "/home/travis/build/duly/analytics-python/analytics/client.py", line 203, in _clean
return self._clean_dict(item)
File "/home/travis/build/duly/analytics-python/analytics/client.py", line 189, in _clean_dict
data[k] = self._clean(v)
File "/home/travis/build/duly/analytics-python/analytics/client.py", line 205, in _clean
return self._coerce_unicode(item)
File "/home/travis/build/duly/analytics-python/analytics/client.py", line 180, in _coerce_unicode
return cmplx.decode("utf-8", "strict")
AttributeError: 'exceptions.Exception' object has no attribute 'decode'
```
Since the key is exception and the value is an Exception. Run decode on the Exception arguments as opposed to the Exception itself which does not contain a 'decode' attribute.
```
python/analytics/client.py", line 209, in _clean
return self._coerce_unicode(item)
File "/home/travis/build/duly/analytics-python/analytics/client.py", line 181, in _coerce_unicode
item = cmplx.decode("utf-8", "strict")
AttributeError: 'exceptions.Exception' object has no attribute 'decode'
```
http://stackoverflow.com/questions/5099551/error-in-python-replace-attributeerror-tuple-object-has-no-attribute-repla ``` line 183, in _coerce_unicode item = exception.args.decode("utf-8", "strict") AttributeError: 'tuple' object has no attribute 'decode' ```
Python 3.3 and 3.4 throw attribute errors ``` AttributeError: 'str' object has no attribute 'decode' ```
|
segmentio/analytics-python is now fully compatible with four version of Python. Python 2.6, Python 2.7, Python 3.2, Python 3.3. There are some warnings that should be resolved before merging into |
|
For reference: |
alleviate deprecation warning in 3.4. ``` ./home/travis/build/duly/analytics-python/analytics/client.py:27: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead method(*args, **kwargs) ```
Change log('warn', ...) to 'warning'.
```
./home/travis/build/duly/analytics-python/analytics/client.py:27: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
method(*args, **kwargs)
```
|
Eliminated deprecation warnings about 'warn'. Main build: |
Python 3.4 and 2.6.
Remove Python 3.4 due to errored job on travis. https://travis-ci.org/duly/analytics-python/jobs/21865893
2.5 and 3.4 have a lack of support for virtualenv.
|
Awesome! Looks okay to me, can you rebase and squash into one commit? |
|
Hey @duly, awesome stuff, these updates are great. Any chance you can squash them into 1 commit? Then I'll happily merge this, otherwise we'll just apply the patch. |
|
@duly bump |
|
👍 |
|
If someone else wants to take this on, we would welcome it. We don't have On Mon, Aug 18, 2014 at 7:40 PM, Sam Bolgert notifications@github.com
|
|
sorry about the delay, just did a major re-write! fixed in #25, thanks for the help! |
Simple import fix allows segment.io analytics to import on Python 3.3.2
Adding .travis.yml to root to allow automated builds to check compatibility with Python 2.