Skip to content

Commit d9efcfb

Browse files
committed
Cleanup
1 parent 5fc6ec5 commit d9efcfb

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

graphbuilder.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
import networkx as nx
99
import matplotlib.pyplot as plt
1010

11-
# Regular expression to detect cell references like A1, B2, or ranges like A1:B2
12-
13-
# ignore linting error for regex pattern
14-
CELL_REF_REGEX = r"('?[A-Za-z0-9_\-\[\] ]+'?![A-Z]{1,3}[0-9]+(:[A-Z]{1,3}[0-9]+)?)|([A-Z]{1,3}[0-9]+(:[A-Z]{1,3}[0-9]+)?)"
11+
# Regex to detect cell references like A1, B2, or ranges like A1:B2
12+
CELL_REF_REGEX = r"('?[A-Za-z0-9_\-\[\] ]+'?![A-Z]{1,3}[0-9]+(:[A-Z]{1,3}[0-9]+)?)|([A-Z]{1,3}[0-9]+(:[A-Z]{1,3}[0-9]+)?)" # noqa
1513

1614

1715
def extract_formulas_and_build_dependencies(file_path):
@@ -45,7 +43,7 @@ def extract_formulas_and_build_dependencies(file_path):
4543
# Add the cell and its dependencies to the graph
4644
for ref_cell in referenced_cells:
4745
if "!" not in ref_cell:
48-
# No sheet specified in the reference, assume current sheet
46+
# No sheet specified in the assume current sheet
4947
refc = f"{sheet_name}!{ref_cell}"
5048
else:
5149
refc = ref_cell
@@ -85,13 +83,12 @@ def extract_references(formula):
8583
"""
8684
formula = formula.replace("$", "")
8785
matches = re.findall(CELL_REF_REGEX, formula)
88-
# extracted_references = [match[0].replace("$", "") for match in matches if match[0]]
89-
extracted_references = [match[0] if match[0] else match[2] for match in matches]
86+
references = [match[0] if match[0] else match[2] for match in matches]
9087

9188
# trim the extracted references
92-
extracted_references = [ref.strip() for ref in extracted_references]
89+
references = [ref.strip() for ref in references]
9390

94-
return extracted_references
91+
return references
9592

9693

9794
def visualize_dependency_graph(graph, file_path):

test_cell_reference_extraction.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pylint: disable=missing-function-docstring missing-module-docstring
21
from graphbuilder import (
32
extract_references,
43
) # Ensure you replace this with the actual name of your module

0 commit comments

Comments
 (0)