-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,9 +91,7 @@ def header_link(title): | |
for character in title: | ||
if character in string.whitespace: | ||
result += '-' | ||
elif character in string.punctuation: | ||
pass | ||
else: | ||
elif character not in string.punctuation: | ||
result += character.lower() | ||
return result | ||
|
||
|
@@ -104,13 +102,7 @@ def askyesno(question, default=True): | |
The default answer is yes if default is True and no if default is | ||
False. | ||
""" | ||
if default: | ||
# yes by default | ||
question += ' [Y/n] ' | ||
else: | ||
# no by default | ||
question += ' [y/N] ' | ||
|
||
question += ' [Y/n] ' if default else ' [y/N] ' | ||
Comment on lines
-107
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ):
|
||
while True: | ||
result = input(question).upper().strip() | ||
if result == 'Y': | ||
|
@@ -125,15 +117,15 @@ def askyesno(question, default=True): | |
@contextlib.contextmanager | ||
def backup(filename): | ||
"""A context manager that backs up a file.""" | ||
shutil.copy(filename, filename + '.backup') | ||
shutil.copy(filename, f'{filename}.backup') | ||
try: | ||
yield | ||
except Exception: | ||
# It failed, we need to restore from the backup. | ||
shutil.copy(filename + '.backup', filename) | ||
shutil.copy(f'{filename}.backup', filename) | ||
else: | ||
# Everything's fine, we can safely get rid of the backup. | ||
os.remove(filename + '.backup') | ||
os.remove(f'{filename}.backup') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
def header_link(title): | ||
|
@@ -149,8 +141,6 @@ def header_link(title): | |
for character in title: | ||
if character in string.whitespace: | ||
result += '-' | ||
elif character in string.punctuation: | ||
pass | ||
else: | ||
elif character not in string.punctuation: | ||
Comment on lines
-152
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
result += character.lower() | ||
return result |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,13 +67,11 @@ def check(this_file, target, title, titledict): | |
# A directory. | ||
if not os.path.isdir(path): | ||
return "not a directory" | ||
else: | ||
# A file. | ||
if not os.path.isfile(path): | ||
return "not a file" | ||
elif not os.path.isfile(path): | ||
return "not a file" | ||
|
||
if title is not None and title not in titledict[path]: | ||
return "no title named %s" % title | ||
return f"no title named {title}" | ||
Comment on lines
-70
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ):
|
||
return "ok" | ||
|
||
|
||
|
@@ -145,7 +143,7 @@ def main(): | |
status = check(filename, target, title, titledict) | ||
if status != "ok": | ||
print(" file %s, line %d: %s" % (filename, lineno, status)) | ||
print(" %s" % get_line(filename, lineno)) | ||
print(f" {get_line(filename, lineno)}") | ||
Comment on lines
-148
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
broken += 1 | ||
total += 1 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
|
||
"""Create HTML files of the tutorial.""" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
|
||
import argparse | ||
import os | ||
import platform | ||
|
@@ -37,19 +38,15 @@ | |
import textwrap | ||
import webbrowser | ||
|
||
if platform.system() == 'Windows': | ||
python = 'py' | ||
else: | ||
python = 'python3' | ||
|
||
python = 'py' if platform.system() == 'Windows' else 'python3' | ||
try: | ||
import mistune | ||
except ImportError: | ||
print("mistune isn't installed.", file=sys.stderr) | ||
print("You can install it by running this command on a terminal or ") | ||
print("command prompt:") | ||
print() | ||
print(" %s -m pip install mistune" % python) | ||
print(f" {python} -m pip install mistune") | ||
sys.exit(1) | ||
|
||
try: | ||
|
@@ -108,7 +105,7 @@ def fix_filename(filename): | |
# some/place/BEFORE -> some/place/AFTER | ||
return filename[:-len(before)] + after | ||
if filename.endswith('.md'): | ||
filename = filename[:-3] + '.html' | ||
filename = f'{filename[:-3]}.html' | ||
Comment on lines
-111
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return filename | ||
|
||
|
||
|
@@ -137,7 +134,7 @@ def link(self, link, title, text): | |
elif '#' in link: | ||
# it's like "some-file#title", we need to fix some-file | ||
before, after = link.split('#', 1) | ||
link = fix_filename(before) + '#' + after | ||
link = f'{fix_filename(before)}#{after}' | ||
Comment on lines
-140
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
else: | ||
# it's like "some-file" | ||
link = fix_filename(link) | ||
|
@@ -164,13 +161,11 @@ def block_code(self, code, lang=None): | |
continue | ||
|
||
if line.startswith('+'): | ||
result.append('<p><font color="green">%s</font></p>' | ||
% line.strip('+')) | ||
result.append(f"""<p><font color="green">{line.strip('+')}</font></p>""") | ||
elif line.startswith('-'): | ||
result.append('<p><font color="red">%s</font></p>' | ||
% line.strip('-')) | ||
result.append(f"""<p><font color="red">{line.strip('-')}</font></p>""") | ||
else: | ||
result.append('<p>%s</p>' % line) | ||
result.append(f'<p>{line}</p>') | ||
Comment on lines
-167
to
+168
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
return '\n'.join(result) | ||
|
||
|
@@ -191,9 +186,7 @@ def table(self, header, body): | |
|
||
def wrap_text(text): | ||
"""Like textwrap.fill, but respects newlines.""" | ||
result = [] | ||
for part in text.split('\n'): | ||
result.append(textwrap.fill(part)) | ||
result = [textwrap.fill(part) for part in text.split('\n')] | ||
Comment on lines
-194
to
+189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return '\n'.join(result) | ||
|
||
|
||
|
@@ -226,7 +219,7 @@ def main(): | |
if pygments is None: | ||
print("Pygments isn't installed. You can install it like this:") | ||
print() | ||
print(" %s -m pip install pygments" % python) | ||
print(f" {python} -m pip install pygments") | ||
Comment on lines
-229
to
+222
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
print() | ||
print("You can also continue without Pygments, but the code examples") | ||
print("will not be colored.") | ||
|
@@ -236,8 +229,9 @@ def main(): | |
args.pygments_style = None | ||
|
||
if os.path.exists(args.outdir): | ||
if not common.askyesno("%s exists. Do you want to remove it?" | ||
% args.outdir): | ||
if not common.askyesno( | ||
f"{args.outdir} exists. Do you want to remove it?" | ||
): | ||
print("Interrupt.") | ||
return | ||
if os.path.isdir(args.outdir): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,7 @@ def main(): | |
|
||
# the links that point to the subdir must now point to the | ||
# current directory, so we fix that | ||
content = BEGINNING + content.replace(directory + '/', '').rstrip() | ||
content = BEGINNING + content.replace(f'{directory}/', '').rstrip() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
path = os.path.join(directory, 'README.md') | ||
this_changed = update_file(path, content) | ||
something_changed = something_changed or this_changed | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
header_link
refactored with the following changes:remove-pass-elif
)