Skip to content

Commit

Permalink
Merge pull request #872 from DimitriPapadopoulos/flake8
Browse files Browse the repository at this point in the history
[INFRA] Several style fixes (Flake8) for Python code in the repo
  • Loading branch information
sappelhoff authored Sep 28, 2021
2 parents 9dfe520 + 3bcda38 commit 98d7af6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
22 changes: 11 additions & 11 deletions pdf_build_src/process_markdowns.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def copy_src():
target_path = "src_copy"

# make new directory
mkdir_cmd = "mkdir "+target_path
mkdir_cmd = "mkdir " + target_path
run_shell_cmd(mkdir_cmd)

# copy contents of src directory
copy_cmd = "cp -R "+src_path+" "+target_path
copy_cmd = "cp -R " + src_path + " " + target_path
run_shell_cmd(copy_cmd)


Expand All @@ -66,7 +66,7 @@ def copy_images(root_path):

for each in subdir_list:
if each != root_path:
run_shell_cmd("cp -R "+each+"/images"+" "+root_path+"/images/")
run_shell_cmd("cp -R " + each + "/images" + " " + root_path + "/images/")


def extract_header_string():
Expand All @@ -91,13 +91,13 @@ def add_header():
header = " ".join([title, version_number, build_date])

# creating a header string with latest version number and date
header_string = (r"\fancyhead[L]{ " + header + " }")
header_string = r"\fancyhead[L]{ " + header + " }"

with open('header.tex', 'r') as file:
data = file.readlines()

# insert the header, note that you have to add a newline
data[4] = header_string+'\n'
data[4] = header_string + '\n'

# re-write header.tex file with new header string
with open('header.tex', 'w') as file:
Expand Down Expand Up @@ -321,12 +321,12 @@ def correct_tables(root_path, debug=False):
table_mode = True

# Keep track of the line number where the table starts
start_line = line_nb-1
start_line = line_nb - 1

print(' * Detected table starting line {}'.format(start_line))
# Extract for each row (header and the one containing dashes)
# the content of each column and strip to remove extra whitespace
header_row = [c.strip() for c in re.split(r'(?<!\\)\|', content[line_nb-1])]
header_row = [c.strip() for c in re.split(r'(?<!\\)\|', content[line_nb - 1])]
row = [c.strip() for c in re.split(r'(?<!\\)\|', line)]

# Add the two lines to the table row list
Expand Down Expand Up @@ -378,10 +378,10 @@ def correct_tables(root_path, debug=False):
if i == start_line:
new_content.pop()
if i >= start_line and i < end_line:
new_content.append('|'.join(table[count])+' \n')
new_content.append('|'.join(table[count]) + ' \n')
count += 1
elif i == end_line:
new_content.append('|'.join(table[count])+' \n\n')
new_content.append('|'.join(table[count]) + ' \n\n')
count += 1
print(' - Appended corrected table lines to the new markdown content')
else:
Expand All @@ -401,9 +401,9 @@ def edit_titlepage():
with open('cover.tex', 'r') as file:
data = file.readlines()

data[-1] = ("\\textsc{\large "+version_number+"}" +
data[-1] = ("\\textsc{\\large " + version_number + "}" +
"\\\\[0.5cm]" +
"{\large " +
"{\\large " +
build_date +
"}" +
"\\\\[2cm]" +
Expand Down
1 change: 1 addition & 0 deletions tools/examplecode/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import os


class DirectoryTree:
def __init__(self, filetree, use_pipe=True):
self._generator = _TreeGenerator(filetree, use_pipe)
Expand Down
73 changes: 36 additions & 37 deletions tools/no-bad-latin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,43 @@ def parse_args():

def remove_comments(text_string):
"""Function to omit html comment identifiers in a text string using
regular expression matches
regular expression matches
Arguments:
text_string {string} -- The text to be matched
Arguments:
text_string {string} -- The text to be matched
Returns:
{string} -- The input text string with html comments removed
"""
Returns:
{string} -- The input text string with html comments removed
"""
p = re.sub("(?s)<!--(.*?)-->", "", text_string)
return p


def get_lines(text_string, sub_string):
"""Get individual lines in a text file
Arguments:
text_string {string} -- The text string to test
sub_string {string} -- The conditional string to perform splitting on
Arguments:
text_string {string} -- The text string to test
sub_string {string} -- The conditional string to perform splitting on
Returns:
{list} -- A list of split strings
"""
Returns:
{list} -- A list of split strings
"""
lines = [line for line in text_string.split("\n") if sub_string in line]
return lines


def construct_error_message(files_dict):
"""Function to construct an error message pointing out where bad latin
phrases appear in lines of text
phrases appear in lines of text
Arguments:
files_dict {dictionary} -- Dictionary of failing files containing the
bad latin phrases and offending lines
Arguments:
files_dict {dictionary} -- Dictionary of failing files containing the
bad latin phrases and offending lines
Returns:
{string} -- The error message to be raised
"""
Returns:
{string} -- The error message to be raised
"""
error_message = ["Bad latin found in the following files:\n"]

for file in files_dict.keys():
Expand All @@ -82,32 +82,31 @@ def construct_error_message(files_dict):

def read_and_check_files(files):
"""Function to read in files, remove html comments and check for bad latin
phrases
phrases
Arguments:
files {list} -- List of filenames to be checked
Arguments:
files {list} -- List of filenames to be checked
Returns:
{dict} -- Dictionary: Top level keys are absolute filepaths to files
that failed the check. Each of these has two keys:
'latin_type' containing the unwanted latin phrase, and 'line'
containing the offending line.
"""
Returns:
{dict} -- Dictionary: Top level keys are absolute filepaths to files
that failed the check. Each of these has two keys:
'latin_type' containing the unwanted latin phrase, and 'line'
containing the offending line.
"""
failing_files = {}
bad_latin = [
"i.e.", "i.e ", " ie ",
"e.g.", "e.g ",
"e.t.c.", " etc", "et cetera"
]
]

for filename in files:
if os.path.basename(filename) in IGNORE_LIST:
pass
else:
try:
with open(
os.path.join(ABSOLUTE_HERE, filename), encoding="utf8",
errors="ignore") as f:
with open(os.path.join(ABSOLUTE_HERE, filename),
encoding="utf8", errors="ignore") as f:
text = f.read()
text = remove_comments(text)

Expand All @@ -128,12 +127,12 @@ def read_and_check_files(files):
def get_all_files(directory=os.path.join(ABSOLUTE_HERE, "src")):
"""Get a list of files to be checked. Ignores images, javascript, css files.
Keyword Arguments:
directory {string} -- The directory containing the files to check
Keyword Arguments:
directory {string} -- The directory containing the files to check
Returns:
{list} -- List of files to check
"""
Returns:
{list} -- List of files to check
"""
files = []
filetypes_to_ignore = (".png", ".jpg", ".js", ".css")

Expand Down

0 comments on commit 98d7af6

Please sign in to comment.