Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Fix encoding issue between Python 2 and 3 #133

Merged
merged 3 commits into from
Jan 8, 2018
Merged

Fix encoding issue between Python 2 and 3 #133

merged 3 commits into from
Jan 8, 2018

Conversation

JrGoodle
Copy link
Contributor

@JrGoodle JrGoodle commented Jan 6, 2018

Addresses #130

Fix for issue introduced in #121

I tested this on my own project and it worked: https://circleci.com/gh/JrGoodle/clowder/154

It probably still needs to be tested with Python 2

basestring
except NameError:
basestring = str
if isinstance(reports, basestring):
Copy link
Contributor

Choose a reason for hiding this comment

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

Almost good.

For Python 2 you want if isinstance(reports, unicode) (not (str, unicode)),
for python 3 you want if isinstance(reports, str).

So the correct fix would be:

try:
    unicode
except NameError:
    # Must be Python 3, make an alias for str.
    unicode = str
if isinstance(reports, unicode):
    reports = reports.encode('utf-8')

However, Python 2 has bytes being an alias for str. So you can do:

if not isinstance(reports, bytes):
    reports = reports.encode('utf-8')

@codecov
Copy link

codecov bot commented Jan 6, 2018

Codecov Report

Merging #133 into master will not change coverage.
The diff coverage is n/a.

@@          Coverage Diff          @@
##           master   #133   +/-   ##
=====================================
  Coverage       0%     0%           
=====================================
  Files           1      1           
  Lines           1      1           
=====================================
  Misses          1      1

@JrGoodle
Copy link
Contributor Author

JrGoodle commented Jan 6, 2018

@chfast I made the suggested change

@stevepeak I also configured the tests to skip invalid CI providers. I had to skip a number of extra tests for AppVeyor to pass (including the one specifically for AppVeyor). There was another string encoding bug exposed in the tests that I fixed. let me know if there are any changes you'd like for this part of the patch, but I think having fewer tests run that consistently pass is better than having more tests run that consistently fail

In addition, I updated the .gitignore from gitignore.io because it wanted to track my PyCharm project files

Copy link
Contributor

@chfast chfast left a comment

Choose a reason for hiding this comment

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

The encoding part looks good. The tests/CI part is not up to me.

@blueyed
Copy link
Contributor

blueyed commented Jan 7, 2018

Regarding .gitignore, I suggest configuring a global gitignore file.
Might be good to add PyCharm related files here, but there seem to be many unneeded additions now.

@JrGoodle
Copy link
Contributor Author

JrGoodle commented Jan 7, 2018

I generated the gitignore using the following options on gitignore.io: linux,macos,python,pycharm+all

It seem like a lot, but they're pretty well maintained and thorough. Would you rather I used a subset?

@blueyed
Copy link
Contributor

blueyed commented Jan 7, 2018

@JrGoodle
I think it makes sense for a separate PR - it should not block this fix.
And then, yes - there is no need to ignore e.g. CMake related files in this project.
And like I said, you can have a global/user gitignore file, too.

@JrGoodle
Copy link
Contributor Author

JrGoodle commented Jan 7, 2018

@blueyed I removed the .gitignore commit from this PR

@stevepeak
Copy link
Contributor

Thank you @JrGoodle @chfast @blueyed for your help. 👍

@stevepeak stevepeak merged commit 87bbf40 into codecov:master Jan 8, 2018
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.

4 participants