Skip to content

Commit

Permalink
fixing bug that we need to add modulepath after updated
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsochat@stanford.edu>
  • Loading branch information
vsoch committed Jan 15, 2021
1 parent 4c5101d commit 0e691df
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions caliper/metrics/collection/functiondb/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from caliper.metrics.base import MetricBase
from caliper.utils.file import recursive_find, read_file
from caliper.logger import logger

import ast
import os
Expand Down Expand Up @@ -39,6 +40,9 @@ def add_functions(filepath, modulepath):
if filename != "__init__":
modulepath = "%s.%s" % (modulepath, re.sub("[.]py$", "", filename))

# Add the modulepath to the lookup
lookup[modulepath] = {}

# Add each of functions and classes - ignore default values for now
for function in functions:
lookup[modulepath][function.name] = [
Expand All @@ -53,7 +57,9 @@ def add_functions(filepath, modulepath):
arg.arg for arg in method.args.args
]

# Look for folders with an init
# Keep track of counts
count = 0
issue_count = 0
for filename in recursive_find(self.git.folder, "*.py"):

# Skip files that aren't a module
Expand All @@ -62,20 +68,25 @@ def add_functions(filepath, modulepath):
continue

# The module path is needed for a script calling the function
count += 1
modulepath = ".".join(
os.path.dirname(filename)
.replace(self.git.folder, "")
.strip("/")
.split("/")
)
lookup[modulepath] = {}

# Ignore any scripts that ast cannot parse
try:
add_functions(filename, modulepath)
except:
logger.debug("Issue parsing %s, skipping" % filename)
issue_count += 1
pass

logger.debug(
"Successfully parsed %s files. %s were skipped." % (count, issue_count)
)
return lookup

def get_file_results(self):
Expand Down

0 comments on commit 0e691df

Please sign in to comment.