Skip to content

Commit

Permalink
Make things consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
EricCousineau-TRI committed Oct 8, 2018
1 parent c87fa36 commit 962d5fa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
10 changes: 4 additions & 6 deletions common/test_utilities/drake_py_unittest_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@

import six

if six.PY3:
_open = open

def _open(filename, mode):
if six.PY2:
return open(filename, mode)
else:
return open(filename, mode, encoding="utf-8")
def open(filename, mode="r"): return _open(filename, mode, encoding="utf8")


if __name__ == '__main__':
Expand All @@ -43,7 +41,7 @@ def _open(filename, mode):
if not found_filename:
raise RuntimeError("No such file found {}!".format(
test_filename))
with _open(found_filename, "r") as infile:
with open(found_filename, "r") as infile:
for line in infile.readlines():
if any([line.startswith("if __name__ =="),
line.strip().startswith("unittest.main")]):
Expand Down
3 changes: 1 addition & 2 deletions tools/install/cpsutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
if sys.version_info.major >= 3:
_open = open

def open(file, mode='r'):
return _open(file, mode, encoding='utf8')
def open(filename, mode="r"): return _open(filename, mode, encoding="utf8")


def read_defs(pattern, groups=(1, 2)):
Expand Down
12 changes: 5 additions & 7 deletions tools/lint/drakelint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@

from drake.tools.lint.formatter import IncludeFormatter

if sys.version_info.major >= 3:
_open = open

def _open(filename, mode):
if six.PY2:
return open(filename, mode)
else:
return open(filename, mode, encoding="utf-8")
def open(filename, mode="r"): return _open(filename, mode, encoding="utf8")


def _check_invalid_line_endings(filename):
"""Return 0 if all of the newlines in @p filename are Unix, and 1
otherwise.
"""
# Ask Python to read the file and determine the newlines convention.
with _open(filename, 'rU') as file:
with open(filename, 'rU') as file:
if not file:
print("ERROR: unable to open " + filename)
return 1
Expand Down Expand Up @@ -57,7 +55,7 @@ def _check_shebang(filename):
acceptable shebang lines, and 1 otherwise.
"""
is_executable = os.access(filename, os.X_OK)
with _open(filename, 'r') as file:
with open(filename, 'r') as file:
shebang = file.readline().rstrip("\n")
has_shebang = shebang.startswith("#!")
if is_executable and not has_shebang:
Expand Down

0 comments on commit 962d5fa

Please sign in to comment.