Sourcery refactored master branch by sourcery-ai[bot] · Pull Request #1 · edson-github/python-tutorial · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions common.py
10 changes: 4 additions & 6 deletions linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function check refactored with the following changes:

This removes the following comments ( why? ):

# A file.

return "ok"


Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

broken += 1
total += 1

Expand Down
32 changes: 13 additions & 19 deletions make-html.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

"""Create HTML files of the tutorial."""

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 40-52 refactored with the following changes:


import argparse
import os
import platform
Expand All @@ -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:
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fix_filename refactored with the following changes:

return filename


Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TutorialRenderer.link refactored with the following changes:

else:
# it's like "some-file"
link = fix_filename(link)
Expand All @@ -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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TutorialRenderer.block_code refactored with the following changes:


return '\n'.join(result)

Expand All @@ -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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function wrap_text refactored with the following changes:

return '\n'.join(result)


Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

print()
print("You can also continue without Pygments, but the code examples")
print("will not be colored.")
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion update-readmes.py