Skip to content

Commit

Permalink
Make setup.py file reads Python3 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhitlock committed Feb 17, 2017
1 parent 550d53b commit f94775f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@
description = 'Make Django requests aware of the DNT header'


def read_file(path):
contents = open('README.rst').read()
if hasattr(contents, 'decode'):
return contents.decode('utf8') # Python2 bytes to unicode
else:
return contents # Python3 reads unicode


def long_description():
"""Create a PyPI long description from docs."""
readme = open('README.rst').read().decode('utf8')
readme = read_file('README.rst')
body_tag = ".. Omit badges from docs"
try:
readme_body_start = readme.index(body_tag)
Expand All @@ -30,7 +38,7 @@ def long_description():
}

try:
history = open('HISTORY.rst').read().decode('utf8')
history = read_file('HISTORY.rst')
except IOError:
history = ''

Expand All @@ -47,7 +55,7 @@ def long_description():

setup(
name='django-dnt',
version='0.1.0',
version='0.2.0',
description=description + '.',
long_description=long_description(),
author='James Socol',
Expand Down

0 comments on commit f94775f

Please sign in to comment.