Merge branch 'develop' into release

This commit is contained in:
Maximilien Rigaut 2022-06-15 21:39:48 +02:00
commit 64a2763053
No known key found for this signature in database
GPG Key ID: 4F14B23709ADA5B1
7 changed files with 64 additions and 108 deletions

View File

@ -5,9 +5,9 @@ name: Python Deployment
on:
push:
branches: [ main ]
branches: [ main, test*]
pull_request:
branches: [ main ]
branches: [ main, test* ]
jobs:

View File

@ -5,9 +5,9 @@ name: Python Tests and Lint
on:
push:
branches: [ main, release, releases/*]
branches: [ main, release, releases/*, test*]
pull_request:
branches: [ main, release, releases/* ]
branches: [ main, release, releases/*, test* ]
jobs:

2
.gitignore vendored
View File

@ -157,4 +157,4 @@ example_userfiles/output/
example_userfiles/output/*
dev_outputs/*
example_output/*
dics/*
docs/

View File

@ -436,14 +436,12 @@ class ContextManager:
def __init__(self, parsed_list, name=None, ident=0):
"""
Takes a list of parsed tokens.
Parameters
----------
parsed_list : list[syntax.SemanticType]
List of parsed tokens output by our parser.
name : str
Name of the file being parsed.
ident : int
Number of spaces to indent the output.
:type parsed_list : list[syntax.SemanticType]
:param parsed_list: List of parsed tokens output by our parser.
:type name: str
:param name: Name of the file being parsed.
:type ident: int
:param ident: Number of spaces to indent the output.
"""
self.output = []
self.parsed_list = parsed_list
@ -464,15 +462,12 @@ class ContextManager:
"""
Method to encapsulate a number of tokens together as a final container object
and replace all elements in the pile with None, except the first one which becomes the container.
Parameters
----------
start : int
Index of the pile where the encapsulation must begin.
end : int
Index of the pile where the encapsulation must end.
Returns
-------
list[(BaseContainer|None)]
:type start : int
:param start: Index of the pile where the encapsulation must begin.
:type end: int
:param end: Index of the pile where the encapsulation must end.
:rtype: list[(BaseContainer|None)]
:return: List of containers and None objects.
"""
# Enabling this will allow us to debug the pile
# print(f"Step : [{end}] - encapsulation:")
@ -514,18 +509,16 @@ class ContextManager:
container.add(self.pile[end])
self.pile[end] = None
self.pile[start] = container
return self.pile # ? I think this is the right way to return the pile
# print(" <<< Pile:", self.pile)
def _add_matched(self, label, index):
"""
Method to add a matched element to the dictionary of matched elements.
Parameters
----------
label : str
Label of the matched element.
index : int
Index of the matched element in the pile.
:type label : str
:param label: Label of the matched element.
:type index: int
:param index: Index of the matched element in the pile.
"""
if label not in self.matched_elements:
self.matched_elements[label] = []
@ -534,13 +527,10 @@ class ContextManager:
def _get_matched(self, label):
"""
Method to get the index of the last matched element of a given label.
Parameters
----------
label : str
Label of the matched element.
Returns
-------
int : Index of the last matched element of the given label.
:type label: str
:param label: Label of the matched element.
:rtype: int
:return: Index of the last matched element
"""
return self.matched_elements[label].pop()
@ -548,14 +538,9 @@ class ContextManager:
"""
Interprets the list of tokens provided and deduces context, encapsulating them to their closest neighbour and
containing all tokens inbetween.
Returns
-------
list[BaseContainer]
Returns the pile entirely processed as a list of containers.
Raise
-----
MismatchedContainerError
Raised when a container is not matched to its corresponding token.
:rtype: list[BaseContainer]
:return: Returns the pile entirely processed as a list of containers.
:raises: MismatchedContainerError if a container is not matched to its corresponding token.
"""
# self.pile = self.parsed_list.copy()
if self.contextualised:
@ -655,15 +640,12 @@ class ContextManager:
def lookahead(self, token, index):
"""
Iterates the pile beginning from index and looks for all tokens matching labels with token.
Parameters
----------
token : syntax.BaseContainer
Token to look for.
index : int
Index of the token in the pile.
Returns
-------
(int, int) : (number of tokens matched, number of linebreaks)
:type token : syntax.BaseContainer
:param token: Token to look for.
:type index : int
:param index: Index of the token in the pile.
:return: (number of tokens matched, number of linebreaks)
:rtype: (int, int)
"""
range_to_encapsulate = 0
line_skipped = 0
@ -691,29 +673,21 @@ class ContextManager:
def recontext(self, token):
"""
Function to recontextualise the content of a token.
Parameters
----------
token : syntax.SemanticType
Token to recontextualise.
:param token: Token to recontextualise.
:type token: syntax.SemanticType
:return: Token to recontextualise.
:rtype: syntax.SemanticType
"""
token.content = ContextManager(token.content, name=self.name)()
def get_last_container_in_pile(self, index):
"""
Returns the last element in the pile if it is a Container, raises an error otherwise.
Parameters
----------
index : int
Index of the element to check.
Returns
-------
BaseContainer
Raises
------
error_mngr.LonelyOptionalError
Raised when an element is found in the pile that is not encapsulated in a container.
:type index : int
:param index: Index of the element to check.
:return: Last element in the pile if it is a Container, raises an error otherwise.
:rtype: BaseContainer
:raise: error_mngr.LonelyOptionalError when an element is found in the pile that is not encapsulated in a container.
"""
i = index-1 # skip last token as it is self
while i >= 0:

View File

@ -94,18 +94,10 @@ class ExportManager:
"""
Function for initializing other transform functions.
Parameters:
----------
export_request: ExportRequest tuples
Returns:
-------
start: str
Start string of the markup element
end: str
End string of the markup element
optionals: syntax.Optionals
Optionals object containing html_insert and class_insert
:param export_request: ExportRequest tuples
:type export_request: ExportRequest
:return: start, end, optionals
:rtype: str, str, str
"""
start, end = None, None
@ -206,14 +198,12 @@ class ContextConverter:
def __init__(self, pile, exporter, destination):
"""
Takes a pile and the exporter object
Parameters
----------
pile : list[context_mngr.BaseContainer]
pile output from the context manager.
exporter : ExportManager
Our ExportManager
destination : str
Destination of the output file.
:type pile : list[context_mngr.BaseContainer]
:param pile: output from the context manager.
:type exporter : ExportManager
:param exporter: Our ExportManager
:type destination : str
:param destination: Destination of the output file.
"""
self.io_output = StringIO()
self.pile = pile

View File

@ -12,10 +12,10 @@ import bootstraparse.modules.syntax as syntax
def parse_line(io):
"""
Takes an io string and returns the parsed output.
Parameters:
io (StringIO): The io string to parse.
Returns:
list[syntax.SemanticType]: The parsed output.
:param io: The io string to parse.
:type io: StringIO
:return: The parsed output.
:rtype: list[syntax.SemanticType]
"""
output = []
for line in io.readlines():

View File

@ -98,21 +98,13 @@ class SemanticType:
def to_container(self, filter_func=None):
"""
Function called by the context manager to know how to deal with the encapsulation of the token.
Parameters
----------
filter_func: (function | None)
A function that takes a token and returns a boolean. If the token is not valid, it should return False.
Returns
-------
SemanticType | context_mngr.BaseContainer
Self if containable, the expected replacement token if it can, raises an error otherwise.
Raises
------
CannotBeContainedError
Raises error if the token we were trying to encapsulate cannot be (probably mismatched).
:param filter_func: A function that will be used to filter the content of the token.
:type filter_func: (callable| None)
:return: Self if containable, the expected replacement token if it can, raises an error otherwise.
:rtype: SemanticType | context_mngr.BaseContainer
:raises CannotBeContainedError: Raises error if the token we were trying to encapsulate cannot be (probably mismatched).
"""
raise MismatchedContainerError(self)