Skip to content

Conversation

@duly
Copy link

@duly duly commented Mar 29, 2014

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
>>>

duly added 7 commits March 29, 2014 18:32
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.
@duly
Copy link
Author

duly commented Mar 29, 2014

segment.io's python analytics software fails Python 3.2 and 3.3 import analytics.
Please accept new file .travis.yml and modified init.py which allows import to work correctly.
https://travis-ci.org/duly/analytics-python/builds/21849663
Thank you.

```
$ 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
```
@duly
Copy link
Author

duly commented Mar 29, 2014

This pull request makes segmentio / analytics-python minimally compatible with Python 2.6, 2.7, 3.3 and 3.4.

duly added 2 commits March 30, 2014 01:30
```
>>> 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.
@duly
Copy link
Author

duly commented Mar 30, 2014

Since test .py was added in 453b26d Python 3.2.3 and 3.4 builds fail.

Python 3 fails.
3.2.3: https://travis-ci.org/duly/analytics-python/jobs/21860719
3.3.3: https://travis-ci.org/duly/analytics-python/jobs/21860720

Python 2.6 and 2.7 are successful.
2.6: https://travis-ci.org/duly/analytics-python/jobs/21860718
2.7: https://travis-ci.org/duly/analytics-python/jobs/21860717

duly added 14 commits March 30, 2014 01:45
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'
```
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'
```
@duly
Copy link
Author

duly commented Mar 30, 2014

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 master.

./home/travis/build/duly/analytics-python/analytics/client.py:27: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
  method(*args, **kwargs)
WARNING:analytics:Dictionary values must be serializeable to JSON "exception" value This should show up of type <class 'Exception'> is unsupported.
WARNING:analytics:Dictionary values must be serializeable to JSON "timedelta" value 0:00:00.000020 of type <class 'datetime.timedelta'> is unsupported.

@duly
Copy link
Author

duly commented Mar 30, 2014

duly added 2 commits March 30, 2014 03:19
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)
```
@duly
Copy link
Author

duly commented Mar 30, 2014

Eliminated deprecation warnings about 'warn'.

./home/travis/build/duly/analytics-python/analytics/client.py:27: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
  method(*args, **kwargs)

Main build:
https://travis-ci.org/segmentio/analytics-python/builds/21863507
DeprecationWarning no longer presists with latest commit with Python 3.4.
https://travis-ci.org/segmentio/analytics-python/jobs/21863511

@calvinfo
Copy link
Contributor

Awesome! Looks okay to me, can you rebase and squash into one commit?

@calvinfo
Copy link
Contributor

calvinfo commented May 7, 2014

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.

@danielchatfield
Copy link

@duly bump

@asteinlein
Copy link

We're on Python 3 as well, so looking forward to a release with this... If @duly doesn't respond soon, maybe you can just do the squash/rebase when merging this @calvinfo ?

@linuxlewis
Copy link

👍

@duly
Copy link
Author

duly commented Aug 23, 2014

If someone else wants to take this on, we would welcome it. We don't have
the bandwidth at the moment to rebase the commit.

On Mon, Aug 18, 2014 at 7:40 PM, Sam Bolgert notifications@github.com
wrote:

[image: 👍]


Reply to this email directly or view it on GitHub
#22 (comment)
.

@calvinfo
Copy link
Contributor

calvinfo commented Sep 5, 2014

sorry about the delay, just did a major re-write! fixed in #25, thanks for the help!

@calvinfo calvinfo closed this Sep 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants