Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Make discogs_client python 2 & python 3 compatible #43

Merged
merged 21 commits into from Mar 20, 2015

Conversation

brunal
Copy link
Contributor

@brunal brunal commented Jan 16, 2015

This PR makes discogs_client python 2 and python 3 compatible.

Notables changes include:

provide a "if __main__ == '__main__'" at the bottom of each test module
so they can be executed by themselves:
    $ python discogs_client/tests/test_module.py [optional Class.test_name]
Python 2 & 3 compatibility. Memory usage may slightly increase in
python 2.
Introduce a new dependency: six
oauth2 package is python2-only while oauthlib is compatible with python
2 & 3.
parse_qs() result is non-detereministic → a different file might be
requested, making the tests fail randomnly. This commit brings symlinks
for all potential targets of the tests, thus fixing them.
It is required by the OAuth spec and it was missing.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.49%) when pulling 3f43257 on brunal:py23 into 7a97275 on discogs:master.

That's one dirty solution. The real fix would be dropping support for
python 2.6 though.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.66%) when pulling edef8e3 on brunal:py23 into 7a97275 on discogs:master.

@rodneykeeling
Copy link
Contributor

Nice! Thanks for the update, @brunal! 👍 from me.

@rodneykeeling
Copy link
Contributor

@brunal looks like there's an issue with Python 3:

>>> import discogs_client
>>> d = discogs_client.Client('Test/0.1')
>>> d.release(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/foobar/Projects/discogs_client/discogs_client/models.py", line 490, in __repr__
    return '<Release %r %r>' % (self.id, self.title)
  File "/home/foobar/Projects/discogs_client/discogs_client/models.py", line 30, in __get__
    value = instance.fetch(self.name)
  File "/home/foobar/Projects/discogs_client/discogs_client/models.py", line 241, in fetch
    self.refresh()
  File "/home/foobar/Projects/discogs_client/discogs_client/models.py", line 207, in refresh
    data = self.client._get(self.data['resource_url'])
  File "/home/foobar/Projects/discogs_client/discogs_client/client.py", line 117, in _get
    return self._request('GET', url)
  File "/home/foobar/Projects/discogs_client/discogs_client/client.py", line 109, in _request
    body = json.loads(content)
  File "/usr/lib64/python3.4/json/__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

Could you update .travis.yml to test for Python 3 as well?

utf8-decoding the (json) response happens right before parsing it.
Adapt several fetch() implementations, update test data and improve
fetch() docstring.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) when pulling 0c52119 on brunal:py23 into 7a97275 on discogs:master.

@brunal
Copy link
Contributor Author

brunal commented Jan 17, 2015

That issue is now fixed! I hoped there's not more of them lying hidden. I added python 3.{2,3,4} on travis.

I took the decision of making Client.fetch() return bytes, later decoded over Client.fetch() returning a string since the most important Client scions use requests.request, which returns bytes.

@rodneykeeling
Copy link
Contributor

Hey @brunal,

I just tried walking through the OAuth process on the README (using Python 2), but I get an error on the d.get_access_token('my_token') step. Can you look into that?

Thanks,
Rodney

@brunal
Copy link
Contributor Author

brunal commented Jan 21, 2015

Done!

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.56%) to 84.57% when pulling ff0a5d0 on brunal:py23 into 7a97275 on discogs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.49%) to 84.64% when pulling 02ec1f9 on brunal:py23 into 7a97275 on discogs:master.

@brunal
Copy link
Contributor Author

brunal commented Mar 10, 2015

Hi,
I've been using my version with success for the past month. It solves other bugs, such as a 401 error on empty searches.

Do you plan on merging it? Otherwise we might have to use my fork for beets

@rodneykeeling
Copy link
Contributor

Thanks @brunal I'll look over this one today!

@rodneykeeling
Copy link
Contributor

Following the steps on the README using Python 2.7.6, I get this error when trying to execute me.wantlist.add(ds.release(5)):

ValueError: Body contains parameters but Content-Type header was not set.

The release was successfully added to my wantlist, but this error does not show on master.

Even if it's json use application/x-www-form-urlencoded and never
application/json.
Data shall only contain strings as per oauthlib request.
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.49%) to 84.64% when pulling 05cd2e4 on brunal:py23 into 7a97275 on discogs:master.

@brunal
Copy link
Contributor Author

brunal commented Mar 11, 2015

The error message was actually incorrect: the Content-type was application/json instead of application/x-www-url-formencoded. I fixed it (as well as realease_id that should be a string and not an int for the request to be signed).

@rodneykeeling
Copy link
Contributor

Great, looks good so far! Although now you must pass get_access_token() a unicode string (e.g., get_access_token(u'abc123')) or you get a warning message. Is that necessary?

@brunal
Copy link
Contributor Author

brunal commented Mar 13, 2015

That was not necessary, but preferable in case the verifier contains non-ascii characters - which is not the case. I removed it!

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.4%) to 84.73% when pulling 43c4a3f on brunal:py23 into 7a97275 on discogs:master.

@rodneykeeling
Copy link
Contributor

@brunal Perfect! Unless any of the other Discogs devs find issues within the week, I'll merge this on Friday. I hope that's alright. Thanks again for the great work on this! 🍻

rodneykeeling added a commit that referenced this pull request Mar 20, 2015
Make discogs_client python 2 & python 3 compatible
@rodneykeeling rodneykeeling merged commit 956f82d into discogs:master Mar 20, 2015
@brunal
Copy link
Contributor Author

brunal commented Mar 25, 2015

Cool :-) It's been my pleasure.
Don't you think it would be time to tag a new version (the current one being v2.0.2)? That'd allow us folks at beets to force it.

@brunal brunal mentioned this pull request Apr 1, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants