Skip to content

Commit

Permalink
Merge pull request #51 from cs50/develop
Browse files Browse the repository at this point in the history
v2.3.1
  • Loading branch information
Kareem Zidane authored Oct 30, 2017
2 parents 264b20e + 749ad06 commit 41ea0a7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Topic :: Utilities"
],
description="This is style50, with which code can be checked against the CS50 style guide",
install_requires=["argparse", "autopep8", "icdiff", "jsbeautifier==1.6.14", "python-magic", "six", "termcolor"],
install_requires=["argparse", "autopep8>=1.3.3", "icdiff", "jsbeautifier==1.6.14", "python-magic", "six", "termcolor"],
dependency_links=["git+https://github.com/jeffkaufman/icdiff.git"],
keywords=["style", "style50"],
name="style50",
Expand All @@ -20,5 +20,5 @@
"console_scripts": ["style50=style50.__main__:main"],
},
url="https://github.com/cs50/style50",
version="2.3.0"
version="2.3.1"
)
3 changes: 2 additions & 1 deletion style50/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ def count_lines(self, code):

# TODO: Determine which options (if any) should be passed to autopep8
def style(self, code):
return autopep8.fix_code(code, options={"max_line_length": 100})
return autopep8.fix_code(code, options={"max_line_length": 100, "ignore_local_config": True})


class Js(C):
extensions = ["js"]
magic_names = []

# Taken from http://code.activestate.com/recipes/496882-javascript-code-compression/
match_literals = re.compile(
Expand Down
27 changes: 22 additions & 5 deletions style50/style50.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,29 @@ def _check(self, file):
check = self.extension_map[extension[1:]]
except KeyError:
magic_type = magic.from_file(file)
for names, cls in self.magic_map.items():
if any(name in magic_type for name in names):
for name, cls in self.magic_map.items():
if name in magic_type:
print(magic_type)
print(name)
check = cls
break
else:
raise Error("unknown file type \"{}\", skipping...".format(file))

with open(file) as f:
return check(f.read())
try:
with open(file) as f:
code = f.read()
except UnicodeDecodeError:
raise Error("file does not seem to contain text, skipping...")

# Ensure we don't warn about adding trailing newline
try:
if code[-1] != '\n':
code += '\n'
except IndexError:
pass

return check(code)

@staticmethod
def split_diff(old, new):
Expand Down Expand Up @@ -334,7 +348,10 @@ def __init__(self, code):
for d in difflib.ndiff(code.splitlines(True), self.styled.splitlines(True))) / 2

self.lines = self.count_lines(self.styled)
self.score = 1 - self.diffs / self.lines
try:
self.score = 1 - self.diffs / self.lines
except ZeroDivisionError:
raise Error("file is empty")

def count_lines(self, code):
"""
Expand Down

0 comments on commit 41ea0a7

Please sign in to comment.