Skip to content

Commit

Permalink
Dynamic author list works on python 3
Browse files Browse the repository at this point in the history
The dynamic author list introduced in MDAnalysis#787 did not work on python 3
because of the way encoding was handled. This commit fixes the handling
of file encodings by using the codecs library.
  • Loading branch information
jbarnoud committed Mar 21, 2016
1 parent 2cc1cc3 commit 0de57c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from __future__ import print_function
from setuptools import setup, Extension, find_packages
from distutils.ccompiler import new_compiler
import codecs
import os
import sys
import shutil
Expand Down Expand Up @@ -364,7 +365,7 @@ def dynamic_author_list():
"Chronological list of authors" title.
"""
authors = []
with open('AUTHORS') as infile:
with codecs.open('AUTHORS', encoding='utf-8') as infile:
# An author is a bullet point under the title "Chronological list of
# authors". We first want move the cursor down to the title of
# interest.
Expand All @@ -389,7 +390,7 @@ def dynamic_author_list():
break
elif line.strip()[:2] == '- ':
# This is a bullet point, so it should be an author name.
name = line.strip()[2:].strip().decode('utf-8')
name = line.strip()[2:].strip()
authors.append(name)

# So far, the list of authors is sorted chronologically. We want it
Expand All @@ -403,7 +404,8 @@ def dynamic_author_list():
+ authors + ['Oliver Beckstein'])

# Write the authors.py file.
with open('MDAnalysis/authors.py', 'w') as outfile:
out_path = 'MDAnalysis/authors.py'
with codecs.open(out_path, 'w', encoding='utf-8') as outfile:
# Write the header
header = '''\
#-*- coding:utf-8 -*-
Expand All @@ -417,7 +419,7 @@ def dynamic_author_list():
template = u'__authors__ = [\n{}\n]'
author_string = u',\n'.join(u' u"{}"'.format(name)
for name in authors)
print(template.format(author_string).encode('utf-8'), file=outfile)
print(template.format(author_string), file=outfile)


if __name__ == '__main__':
Expand Down
10 changes: 6 additions & 4 deletions testsuite/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from __future__ import print_function
from setuptools import setup, Extension, find_packages

import codecs
import sys
import os
import glob
Expand All @@ -55,7 +56,7 @@ def dynamic_author_list():
"Chronological list of authors" title.
"""
authors = []
with open('AUTHORS') as infile:
with codecs.open('AUTHORS', encoding='utf-8') as infile:
# An author is a bullet point under the title "Chronological list of
# authors". We first want move the cursor down to the title of
# interest.
Expand All @@ -80,7 +81,7 @@ def dynamic_author_list():
break
elif line.strip()[:2] == '- ':
# This is a bullet point, so it should be an author name.
name = line.strip()[2:].strip().decode('utf-8')
name = line.strip()[2:].strip()
authors.append(name)

# So far, the list of authors is sorted chronologically. We want it
Expand All @@ -94,7 +95,8 @@ def dynamic_author_list():
+ authors + ['Oliver Beckstein'])

# Write the authors.py file.
with open('MDAnalysisTests/authors.py', 'w') as outfile:
out_path = 'MDAnalysisTests/authors.py'
with codecs.open(out_path, 'w', encoding='utf-8') as outfile:
# Write the header
header = '''\
#-*- coding:utf-8 -*-
Expand All @@ -108,7 +110,7 @@ def dynamic_author_list():
template = u'__authors__ = [\n{}\n]'
author_string = u',\n'.join(u' u"{}"'.format(name)
for name in authors)
print(template.format(author_string).encode('utf-8'), file=outfile)
print(template.format(author_string), file=outfile)


# Make sure I have the right Python version.
Expand Down

0 comments on commit 0de57c8

Please sign in to comment.