Skip to content

Commit

Permalink
Format python code using black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
asmaloney committed Oct 9, 2023
1 parent 1ed234b commit 54fafd9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
8 changes: 6 additions & 2 deletions framework/ccm_pyactr/ccm_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from python_actr import Buffer


class CCMPrint():
class CCMPrint:
def __init__(self):
self.chunk_map: Dict[str, List[str]] = {}

Expand All @@ -17,7 +17,11 @@ def register_chunk(self, chunk_name: str, slot_names: List[str]):
"""
self.chunk_map[chunk_name] = slot_names

def print_chunk(self, buffer: Buffer, buffer_name: str, ):
def print_chunk(
self,
buffer: Buffer,
buffer_name: str,
):
"""
Prints the contents of the buffer.
Expand Down
2 changes: 1 addition & 1 deletion framework/ccm_pyactr/gactar_ccm_activate_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ def __init__(self, memory: Memory):
# We don't have any real info at this point, but we can output
# the chunk which was activated.
def activation(self, chunk: Chunk):
print(f'trace: activated chunk ({chunk})')
print(f"trace: activated chunk ({chunk})")
return 0
49 changes: 29 additions & 20 deletions framework/pyactr/pyactr_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ def text(self, *args):
text "'a string'"
text "42"
"""
text = ''.join(args[1:]).strip('"')
output = '' # build up our output in this buffer
text = "".join(args[1:]).strip('"')
output = "" # build up our output in this buffer

for itemlist in csv.reader([text]):
for item in itemlist:
item = item.strip(' ')
item = item.strip(" ")

# Handle string
if item[0] == '\'' or item[0] == '"':
if item[0] == "'" or item[0] == '"':
output += item[1:-1]
else:
# Handle number
Expand All @@ -91,26 +91,27 @@ def buffer(self, *args):
buffer retrieval
buffer retrieval.word
"""
name = ''.join(args)
name = "".join(args)
contents = self.get_buffer_data(name)
print(f"{name}: {contents}")

def get_buffer_data(self, item: str) -> str:
"""
Given an "item" which is either a <buffer name> or a <buffer name>.<slot name>,
Given an "item" which is either a <buffer name> or a <buffer name>.<slot name>,
return the contents.
"""
ids = item.split('.')
ids = item.split(".")
match len(ids):
case 1:
contents = self.get_buffer_contents(item)
case 2:
contents = self.get_slot_contents(
ids[0], ids[1])
contents = self.get_slot_contents(ids[0], ids[1])
case _:
print(
'ERROR: expected <buffer> or <buffer>.<slot_name>, found \'' +
item + '\'')
"ERROR: expected <buffer> or <buffer>.<slot_name>, found '"
+ item
+ "'"
)
raise KeyError
return contents

Expand Down Expand Up @@ -140,8 +141,13 @@ def get_slot_contents(self, buffer_name: str, slot_name: str) -> str:
try:
return str(getattr(chunk, slot_name))
except AttributeError:
print('ERROR: no slot named \'' + slot_name +
'\' in buffer \'' + buffer_name + '\'')
print(
"ERROR: no slot named '"
+ slot_name
+ "' in buffer '"
+ buffer_name
+ "'"
)
raise

def get_buffer(self, buffer_name: str) -> Buffer:
Expand All @@ -151,25 +157,28 @@ def get_buffer(self, buffer_name: str) -> Buffer:
if buffer_name in self.ACTR_MODEL._ACTRModel__buffers:
return self.ACTR_MODEL._ACTRModel__buffers[buffer_name]

print('ERROR: Buffer \'' + buffer_name + '\' not found')
print("ERROR: Buffer '" + buffer_name + "' not found")
raise KeyError

def add(self, *args):
raise AttributeError(
"Attempt to add an element to the print buffer. This is not allowed.")
"Attempt to add an element to the print buffer. This is not allowed."
)

def clear(self, *args):
raise AttributeError(
"Attempt to clear the print buffer. This is not allowed.")
raise AttributeError("Attempt to clear the print buffer. This is not allowed.")

def create(self, *args):
raise AttributeError(
"Attempt to add an element to the print buffer. This is not allowed.")
"Attempt to add an element to the print buffer. This is not allowed."
)

def retrieve(self, *args):
raise AttributeError(
"Attempt to retrieve from the print buffer. This is not allowed.")
"Attempt to retrieve from the print buffer. This is not allowed."
)

def test(self, *args):
raise AttributeError(
"Attempt to test the print buffer state. This is not allowed.")
"Attempt to test the print buffer state. This is not allowed."
)

0 comments on commit 54fafd9

Please sign in to comment.