Skip to content

Commit

Permalink
Drop Python 2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Aug 9, 2024
1 parent b5498f3 commit edc59b3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
3 changes: 0 additions & 3 deletions tools/build/doxygen_spell_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ def check(self, text, node):
self.fname = fname
print(" %s:" % location, file=sys.stderr)
joined = ", ".join(misspelled)
# Need to convert from Unicode to plain string for Python 2
if sys.version_info[0] == 2:
joined = joined.encode('utf8')
print(" " + joined, file=sys.stderr)


Expand Down
6 changes: 4 additions & 2 deletions tools/build/setup_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def find_cmdline_links(mod, docdir, cmdline_tools):
for g in [os.path.join(docdir, "README.md")] \
+ glob.glob(os.path.join(docdir, "doc", "*.dox")) \
+ glob.glob(os.path.join(docdir, "doc", "*.md")):
for line in tools.open_utf8(g):
for line in open(g, encoding='UTF8'):
if todo and len(line.rstrip('\r\n ')) > 0 \
and line[0] not in " =-\\":
(k, v) = todo.popitem()
Expand Down Expand Up @@ -397,7 +397,9 @@ def make_overview(module, cmdline_tools):
pickle.dump(cmdline_links,
open(os.path.join("build_info",
"IMP_%s.pck" % module.name), 'wb'), -1)
rmd = tools.open_utf8(os.path.join(module.path, "README.md"), "r").read()
with open(os.path.join(module.path, "README.md"), "r",
encoding='UTF8') as fh:
rmd = fh.read()
# Since we wrap everything in a C++ comment, make sure nothing in the
# Markdown closes this comment (and thus truncates the page). This fixes
# truncation of the help page for IMP.sampcon.
Expand Down
13 changes: 4 additions & 9 deletions tools/build/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def rewrite(filename, contents, verbose=True):
if verbose:
print(" Was symlink - now new file: " + filename)
try:
old = open_utf8(filename, "r").read()
with open(filename, "r", encoding='UTF8') as fh:
old = fh.read()
if old == contents:
return
elif verbose:
Expand All @@ -95,7 +96,8 @@ def rewrite(filename, contents, verbose=True):
dirpath = os.path.split(filename)[0]
if dirpath != "":
mkdir(dirpath, False)
open_utf8(filename, "w").write(contents)
with open(filename, "w", encoding='UTF8') as fh:
fh.write(contents)


class FileGenerator(object):
Expand Down Expand Up @@ -729,13 +731,6 @@ def get_disabled_modules(extra_data_path, root="."):
)


# Treat an open file as UTF8-encoded, regardless of the locale
if sys.version_info[0] >= 3:
def open_utf8(fname, *args):
return open(fname, *args, encoding='UTF8')
else:
open_utf8 = open

_subprocesses = []


Expand Down

0 comments on commit edc59b3

Please sign in to comment.