-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Myoldmopar/FixDocsAndApostropheHandling
More fixes
- Loading branch information
Showing
11 changed files
with
232 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Function Call Group | ||
=================== | ||
|
||
.. autoclass:: energyplus_refactor_helper.function_call_group.FunctionCallGroup | ||
:members: | ||
:class-doc-from: init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from itertools import groupby | ||
from typing import Optional | ||
|
||
from energyplus_refactor_helper.function_call import FunctionCall | ||
|
||
|
||
class FunctionCallGroup: | ||
def __init__(self, initial_call: Optional[FunctionCall] = None): | ||
""" | ||
This class represents a contiguous chunk of function calls within a source file. This is essentially just | ||
a list of function call instances, but some extra intelligence can apply specifically to a group of calls. | ||
so a class is here to provide that context. | ||
""" | ||
self.function_calls = [] | ||
self.started = False | ||
if initial_call: | ||
self.add_function_call(initial_call) | ||
|
||
def add_function_call(self, function_call_info: FunctionCall) -> None: | ||
""" | ||
Add a function call instance to this chunk. | ||
""" | ||
self.started = True | ||
self.function_calls.append(function_call_info) | ||
|
||
def summary_dict(self) -> dict: | ||
""" | ||
This function creates a dict summary of a chunk of contiguous function calls. It is expected this function will | ||
change to returning a nice structure instead of a loosely defined dictionary. | ||
:return: A single dictionary summary. | ||
""" | ||
num_calls_in_this_chunk = len(self.function_calls) | ||
call_types = [e['type'] for e in self.function_calls] | ||
cleaned_call_types = [i[0] for i in groupby(call_types)] # remove duplicates | ||
chunk_start_line = self.function_calls[0]['line_start'] | ||
chunk_end_line = self.function_calls[-1]['line_end'] | ||
try: | ||
concatenated_messages = ' *** '.join([e['args'][1] for e in self.function_calls]) | ||
except IndexError: # pragma: no cover | ||
# this is almost certainly indicative of a parser problem, so we can't cover it | ||
raise Exception(f"Something went wrong with the arg processing for this chunk! {self.function_calls}") | ||
return { | ||
'num_calls_in_this_chunk': num_calls_in_this_chunk, | ||
'call_types': call_types, | ||
'cleaned_call_types': cleaned_call_types, | ||
'chunk_start_line': chunk_start_line, | ||
'chunk_end_line': chunk_end_line, | ||
'concatenated_messages': concatenated_messages | ||
} | ||
|
||
def to_json(self) -> dict: | ||
return {'summary': self.summary_dict(), 'original': self.function_calls} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.