Skip to content
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

Fixes for Python 3 migration #211

Merged
merged 21 commits into from
Nov 11, 2019
Merged

Fixes for Python 3 migration #211

merged 21 commits into from
Nov 11, 2019

Conversation

CastagnaIT
Copy link
Owner

@CastagnaIT CastagnaIT commented Sep 13, 2019

Check if this PR fulfills these requirements:

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Feature change (non-breaking change which change behaviour of an existing functionality)
  • Improvement (non-breaking change which improve functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Porting of the PR #198
Fixes for migration to python 3, this include also fixes to allow execution with the both versions of Python:
Kodi 18.x >> Python 2
Kodi 19.x >> Python 3

Tests:
All tests are performed with a spanish profile in order to test unicode special chars cases
in follow devices:
Kodi 19.x on LibreELEC (at now the only build ready with Py3 and reuselanguageinvoker)
Kodi 18.x on Windows

List of tests:
✔Addon start
✔Cache
✔Cookies
✔Loading lists
✔Play videos
✔Library (export/remove/update context menu)
✔Auto-update all settings features
✔NFO files
✔Shared library MySQL
✔In general test all settings options
✔UpNext integration
...Other?

Who wants to give a concrete help means to verify continuously the output of the logs for every operation carried out so not only what you see on screen

In case of Feature change / Breaking change:

Describe the current behavior

Describe the new behavior

Screenshots (if appropriate):

@dagwieers

This comment has been minimized.

@CastagnaIT
Copy link
Owner Author

I had to make the corrections you didn't make

@CastagnaIT
Copy link
Owner Author

commits are temporary

@CastagnaIT
Copy link
Owner Author

you said you didn't want responsibility to break the addon so i thought I'd do it this way...

@dagwieers

This comment has been minimized.

@CastagnaIT
Copy link
Owner Author

so wait, I'll try to join

@dagwieers

This comment has been minimized.

@dagwieers
Copy link
Contributor

You know what, I'll close my PR. Since you already have been adding more commits to this PR it is probably going to be a lot easier.

@CastagnaIT
Copy link
Owner Author

I was doing the pull on your branch ... that's why it went in error... ok as you prefer

@CastagnaIT
Copy link
Owner Author

how do run integrity tests under windows?

@dagwieers
Copy link
Contributor

dagwieers commented Sep 14, 2019

Look in the Makefile for the right commands. In Linux you can just do make test or make run.
But on Windows you have to run the actual commands manually.

@dagwieers
Copy link
Contributor

BTW I still need to add routing integration tests, but I added the test/run.py so you can start the service in the background and then run the plugin with different routes to see how it behaves.

@CastagnaIT CastagnaIT mentioned this pull request Sep 14, 2019
@CastagnaIT
Copy link
Owner Author

I'd like to make a release, do you think it's better to wait and include this PR or can i proceed?

@Smeulf
Copy link

Smeulf commented Sep 14, 2019

I have to check for MySQL again with some specific use cases if you don't mind, but I think I can do it before the evening.

@dagwieers
Copy link
Contributor

As long as everything has been tested on Python 2.7 I think we're good. I haven't seen any issues (run-time or visual defects) on Python 2.7 with my PR during end-to-end testing. But we currently do not test all code-paths as we should so there's no real guarantee. (And there wasn't a guarantee before either ;-))

@CastagnaIT
Copy link
Owner Author

I only did a quick test with mysql...a more thorough one is appreciated
so well at least we're going the right way 😊 then to now i put it as WIP

@CastagnaIT CastagnaIT added the WIP PR that is still being worked on label Sep 14, 2019
@dagwieers
Copy link
Contributor

dagwieers commented Sep 14, 2019

@CastagnaIT I wasn't talking about MySQL specifically, there is a lot more code-paths we don't cover (see coverage results). And we don't have proper tests for most of the input/output functionality in Kodi/python to know for sure that we handle everything correctly wrt. unicode.

I am struggling with this for other add-ons as well, but it shouldn't be worse than before we added tests ;-)

Update: We don't have coverage reports at the moment because we do not run any of these tests yet. (See .travis) https://codecov.io/gh/dagwieers/plugin.video.netflix/branch/preparation

@@ -37,7 +40,7 @@ def json_rpc(method, params=None):
'params': params or {}}
request = json.dumps(request_data)
debug('Executing JSON-RPC: {}'.format(request))
raw_response = unicode(xbmc.executeJSONRPC(request), 'utf-8')
raw_response = text(xbmc.executeJSONRPC(request)).encode('utf-8')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the series "3%" exported, I can't start an episode. I always get a UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1013: ordinal not in range(128). This is not related to any accentuated chars, it does the same with series with no accent or anything special in the name of the series or the episode.

I don't know how to fix it, and I fear all text() functions are suffering the issue :/

See here for the first error in json_rpc() https://paste.kodi.tv/vitenogebu.kodi
And here for the same kind of error in _decrypt_chunks() https://paste.kodi.tv/olinafikon.kodi

Till this error exists, I can't go further. I'm sorry I can't help more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Smeulf You have an actual Kodi with Python 3 support that works?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's Python 2 (Kodi 18.2, "prod" Raspberry Pi)

Copy link

@Smeulf Smeulf Sep 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's not the exact same code you proposed in your PR, yours was raw_response = text(xbmc.executeJSONRPC(request), 'utf-8')

Copy link
Owner Author

@CastagnaIT CastagnaIT Sep 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes is not same becouse the text(xbmc.executeJSONRPC(request), 'utf-8') do not work with py2, str do not have parameters...

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it worked, i hate UnicodeDecodeError is a ugly beast

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not work with py2, str do not have parameters...

'str' or 'text' ? @dagwieers was using 'text'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works fine on Python 2:

from builtins import str as text
print("%r" % text(u"wieërs", "utf-8"))

Returns 'wie\xc3\xabrs'

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

text is only a reference to str (in py2) look to the imports

@dagwieers
Copy link
Contributor

Using text() was just a hack, I think we need to move to dedicated functions. Elsewhere we use this:

def to_unicode(text, encoding='utf-8'):
    ''' Force text to unicode '''
    return text.decode(encoding) if isinstance(text, bytes) else text


def from_unicode(text, encoding='utf-8'):
    ''' Force unicode to text '''
    import sys
    if sys.version_info.major == 2 and isinstance(text, unicode):  # noqa: F821; pylint: disable=undefined-variable
        return text.encode(encoding)
    return text

I was planning to implement this, before my branch was hijacked ;-)

@CastagnaIT
Copy link
Owner Author

I want to try again but tonight i can't

@CastagnaIT CastagnaIT force-pushed the python3 branch 2 times, most recently from ceb5848 to 9d063d1 Compare September 17, 2019 19:23
@CastagnaIT
Copy link
Owner Author

now it should work,
"unicode" is used by py2
"str" in py3 is same unicode

@CastagnaIT
Copy link
Owner Author

I have installed WSL Ubuntu with python and moudule requirements
with make unit/test i have only this output, it seems strange...
image

@CastagnaIT
Copy link
Owner Author

I plan the merge to master in one/two days
if anyone has to communicate something do it now
any improvements on the code if necessary will be made on other PRs

@CastagnaIT CastagnaIT removed the WIP PR that is still being worked on label Nov 10, 2019
@ccope ccope mentioned this pull request Nov 11, 2019
@CastagnaIT CastagnaIT merged commit 3e6ca65 into master Nov 11, 2019
@CastagnaIT CastagnaIT deleted the python3 branch November 11, 2019 17:37
@notoco
Copy link
Contributor

notoco commented Nov 12, 2019

Something does not work this version - at first a problem with Polish characters (ś), then addonsignals timeout
https://hastebin.com/abanamoyig.sql

The stable version obviously works.
Checked both on the old netflix profile in kodi, as well as on a completely new one

@CastagnaIT
Copy link
Owner Author

Can you try this?
plugin.video.netflix_0.15.8_20191112.zip

@notoco
Copy link
Contributor

notoco commented Nov 12, 2019

This version works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testers needed To resolve this issue other testers are required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants