Skip to content

Commit

Permalink
Fix pylint errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesstaats committed Dec 29, 2024
1 parent 7e52fa7 commit e74e82b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 59 deletions.
6 changes: 3 additions & 3 deletions asy-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import textwrap

# Open the file 'asy-keywords.el' for writing.
with open("asy-keywords.el", "w") as keywords:
with open("asy-keywords.el", "w", encoding="ascii") as keywords:

# Write header information to 'asy-keywords.el'.
# This includes comments and the definition of 'asy-keywords-version' using a
Expand All @@ -39,7 +39,7 @@ def add(keyword):
keywords.write("(defvar asy-keyword-name '(\n")

# Open the file 'camp.l' for reading.
with open("camp.l", "r") as camp:
with open("camp.l", "r", encoding="ascii") as camp:

# Read lines from 'camp.l' until reaching a line that contains only '%%'.
for line in camp:
Expand All @@ -60,7 +60,7 @@ def add(keyword):
keywords.write(match.group(1) + " ")

# Open an input file specified in the command-line arguments.
with open(sys.argv[1], "r") as asylist:
with open(sys.argv[1], "r", encoding="ascii") as asylist:

# Lists to store types, functions, and variables found in the file.
types = [] # List to hold data types.
Expand Down
88 changes: 39 additions & 49 deletions findsym.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,59 +26,49 @@
_, outname, *innames = sys.argv

# Attempt to open the output file in write mode.
header = open(outname, "w")
with open(outname, "w", encoding="ascii") as header:

# Write a predefined header comment block to the output file.
header.write(
textwrap.dedent(
"""\
/*****
* This file is automatically generated by findsym.py
* Changes will be overwritten.
*****/
# Write a predefined header comment block to the output file.
header.write(
textwrap.dedent(
"""\
/*****
* This file is automatically generated by findsym.py
* Changes will be overwritten.
*****/
// If the ADDSYMBOL macro is not already defined, define it with the default
// purpose of referring to an external pre-translated symbol, such that
// SYM(name) also refers to that symbol.
#ifndef ADDSYMBOL
#define ADDSYMBOL(name) extern sym::symbol PRETRANSLATED_SYMBOL_##name
#define SYM(name) PRETRANSLATED_SYMBOL_##name
#endif
// If the ADDSYMBOL macro is not already defined, define it with the default
// purpose of referring to an external pre-translated symbol, such that
// SYM(name) also refers to that symbol.
#ifndef ADDSYMBOL
#define ADDSYMBOL(name) extern sym::symbol PRETRANSLATED_SYMBOL_##name
#define SYM(name) PRETRANSLATED_SYMBOL_##name
#endif
"""
"""
)
)
)

# Initialize an empty set to store unique symbols.
symbols = set()

# Define a function named 'add' that takes a symbol name as an argument.
def add(symbol):
# Concatenate the ADDSYMBOL macro with the provided symbol name and a
# newline character, then write it to the header file.
header.write(f"ADDSYMBOL({symbol});\n")
# Iterate over each remaining command-line argument, which should be the names
# of C++ source files to process.
for inname in innames:
# Attempt to open the current input file in read mode.
with open(inname, "r", encoding="ascii") as infile:
# Read the input file line by line.
for line in infile:
# Use a regular expression to find all occurrences of the SYM macro
# with a valid symbol name inside parentheses.
matches = re.findall(r"SYM\(([_A-Za-z][_A-Za-z0-9]*)\)", line)
for match in matches:
# Add each matched symbol name to the symbols set.
symbols.add(match)


# Initialize an empty set to store unique symbols.
symbols = set()

# Iterate over each remaining command-line argument, which should be the names
# of C++ source files to process.
for inname in innames:
# Attempt to open the current input file in read mode.
with open(inname, "r") as infile:
# Read the input file line by line.
for line in infile:
# Use a regular expression to find all occurrences of the SYM macro
# with a valid symbol name inside parentheses.
matches = re.findall(r"SYM\(([_A-Za-z][_A-Za-z0-9]*)\)", line)
for match in matches:
# Add each matched symbol name to the symbols set.
symbols.add(match)

# After collecting all unique symbols, iterate over the sorted list of symbol
# names.
for symbol in sorted(symbols):
# Call the 'add' function to write its declaration to the header file.
add(symbol)

# Close the output file to finalize and save the output.
header.close()
# After collecting all unique symbols, iterate over the sorted list of symbol
# names.
for symbol in sorted(symbols):
# Concatenate the ADDSYMBOL macro with the provided symbol name and a
# newline character, then write it to the header file.
header.write(f"ADDSYMBOL({symbol});\n")
9 changes: 4 additions & 5 deletions keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import argparse
import re
import sys
import textwrap
from typing import List

Expand All @@ -26,7 +25,7 @@
# Extra keywords to add that aren't automatically extracted, currently none.
extrawords: List[str] = []

with open(output_keywords_file, "w") as keywords:
with open(output_keywords_file, "w", encoding="ascii") as keywords:

keywords.write(
textwrap.dedent(
Expand All @@ -40,13 +39,13 @@
)
)

def add(word):
def add(word): # pylint: disable=redefined-outer-name
keywords.write(f"ADD({word});\n")

for word in extrawords:
add(word)

with open(camplfile) as camp:
with open(camplfile, encoding="ascii") as camp:
# Search for the %% separator, after which the definitions start.
for line in camp:
if re.search(r"^%%\s*$", line):
Expand All @@ -61,7 +60,7 @@ def add(word):
add(match.group(1))

# Grab the special commands from the interactive prompt.
with open(process_file) as process:
with open(process_file, encoding="ascii") as process:
for line in process:
match = re.search(
r"^\s*ADDCOMMAND\(\s*([A-Za-z_][A-Za-z0-9_]*),",
Expand Down
5 changes: 3 additions & 2 deletions opsymbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
args = parser.parse_args()

# Open output file and write header
with open(args.output, "w") as header:
with open(args.output, "w", encoding="ascii") as header:
header.write(
# pylint: disable=line-too-long
textwrap.dedent(
"""\
/*****
Expand All @@ -43,7 +44,7 @@ def add(symbol, name):
header.write(f'OPSYMBOL("{symbol}", {name});\n')

# Open and process campfile
with open(args.campfile, "r") as lexer:
with open(args.campfile, "r", encoding="ascii") as lexer:
for line in lexer:
match = re.search(r'^"(\S+)"\s*{\s*DEFSYMBOL\((\w+)\);', line)
if match:
Expand Down

0 comments on commit e74e82b

Please sign in to comment.