Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/erocarrera/pefile
Browse files Browse the repository at this point in the history
  • Loading branch information
erocarrera committed Apr 17, 2017
2 parents 4d08107 + 157ca58 commit a88107f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import os
import re
import sys
from io import open

if sys.version_info.major == 3:
from io import open

try:
from setuptools import setup, Command
Expand All @@ -23,8 +25,12 @@ def _read_doc():
Parse docstring from file 'pefile.py' and avoid importing
this module directly.
"""
with open('pefile.py', 'r', encoding='utf-8') as f:
tree = ast.parse(f.read().encode('ascii', 'backslashreplace'))
if sys.version_info.major == 2:
with open('pefile.py', 'r') as f:
tree = ast.parse(f.read())
else:
with open('pefile.py', 'r', encoding='utf-8') as f:
tree = ast.parse(f.read())
return ast.get_docstring(tree)


Expand All @@ -36,8 +42,12 @@ def _read_attr(attr_name):
__version__, __author__, __contact__,
"""
regex = attr_name + r"\s+=\s+'(.+)'"
with open('pefile.py', 'r', encoding='utf-8') as f:
match = re.search(regex, f.read())
if sys.version_info.major == 2:
with open('pefile.py', 'r') as f:
match = re.search(regex, f.read())
else:
with open('pefile.py', 'r', encoding='utf-8') as f:
match = re.search(regex, f.read())
# Second item in the group is the value of attribute.
return match.group(1)

Expand Down

0 comments on commit a88107f

Please sign in to comment.