Skip to content

Commit

Permalink
fix black flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
jessica-mitchell committed Jul 4, 2023
1 parent 93041be commit 10b70ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
29 changes: 15 additions & 14 deletions doc/htmldoc/_ext/extract_api_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ def find_all_variables(file_path):
"""
all_variables = None

if 'pynest/nest/__init__' in file_path:
if "pynest/nest/__init__" in file_path:
# Read the __init__.py file
with open(file_path, 'r') as init_file:
with open(file_path, "r") as init_file:
file_content = init_file.read()

# Find the class definition
match = re.search(r'class\s+NestModule\(.*?\):', file_content, re.DOTALL)
match = re.search(r"class\s+NestModule\(.*?\):", file_content, re.DOTALL)
if match:
# Find the variable assignments within the class
all_variables = re.findall(r'(\w+)\s*=\s*KernelAttribute', file_content)
all_variables = re.findall(r"(\w+)\s*=\s*KernelAttribute", file_content)

with open(file_path, 'r') as file:
with open(file_path, "r") as file:
try:
tree = ast.parse(file.read())
except SyntaxError:
Expand All @@ -55,7 +55,7 @@ def find_all_variables(file_path):
for node in ast.iter_child_nodes(tree):
if isinstance(node, ast.Assign) and len(node.targets) == 1:
target = node.targets[0]
if isinstance(target, ast.Name) and target.id == '__all__':
if isinstance(target, ast.Name) and target.id == "__all__":
value = node.value
if isinstance(value, ast.List):
all_variables = [elem.s for elem in value.elts if isinstance(elem, ast.Str)]
Expand All @@ -71,31 +71,32 @@ def process_directory(directory):
result = {}
for root, _, files in os.walk(directory):
for file in files:
if file.endswith('.py'):
if file.endswith(".py"):
file_path = os.path.join(root, file)
# There are two hl_api_spatial files (one in ``lib``, the other in
# ``spatial``) in PyNEST, so we need to distinguish them from each other
if 'lib/hl_api_spatial' in file_path:
file = 'lib.hl_api_spatial.py'
if "lib/hl_api_spatial" in file_path:
file = "lib.hl_api_spatial.py"
# We want the nestModule kernel attributes, which are in ``__init__``
# Rename the key to nestModule
if 'pynest/nest/__init__' in file_path:
file = 'nestModule.py'
if "pynest/nest/__init__" in file_path:
file = "nestModule.py"
filename = os.path.splitext(file)[0]
all_variables = find_all_variables(file_path)
if all_variables:
result[filename] = all_variables
return result


def ExtractPyNESTAPIS():

directory = '../../pynest/nest/'
directory = "../../pynest/nest/"
all_variables_dict = process_directory(directory)

with open('api_function_list.json', 'w') as outfile:
with open("api_function_list.json", "w") as outfile:
json.dump(all_variables_dict, outfile, indent=4)


if __name__ == '__main__':
if __name__ == "__main__":

ExtractPyNESTAPIS()
3 changes: 2 additions & 1 deletion doc/htmldoc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def setup(app):
app.add_css_file("css/custom.css")
app.add_css_file("css/pygments.css")
app.add_js_file("js/custom.js")
app.connect('env-before-read-docs', get_pynest_list)
app.connect("env-before-read-docs", get_pynest_list)
app.connect("env-before-read-docs", add_button_to_examples)
app.connect("config-inited", config_inited_handler)

Expand Down Expand Up @@ -375,6 +375,7 @@ def copy_example_file(src):
copy_example_file("examples/Potjans_2014/microcircuit.png")
copy_example_file("examples/hpc_benchmark_connectivity.svg")


def patch_documentation(patch_url):
"""Apply a hot-fix patch to the documentation before building it.
Expand Down

0 comments on commit 10b70ad

Please sign in to comment.