Merge branch 'release'
This commit is contained in:
commit
8989e05af7
|
|
@ -5,9 +5,9 @@ name: Python Deployment
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main, test*]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ main ]
|
branches: [ main, test* ]
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ name: Python Tests and Lint
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main, release, releases/*]
|
branches: [ main, release, releases/*, test*]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ main, release, releases/* ]
|
branches: [ main, release, releases/*, test* ]
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
|
||||||
|
|
@ -156,4 +156,5 @@ cython_debug/
|
||||||
example_userfiles/output/
|
example_userfiles/output/
|
||||||
example_userfiles/output/*
|
example_userfiles/output/*
|
||||||
dev_outputs/*
|
dev_outputs/*
|
||||||
/example_output/*
|
example_output/*
|
||||||
|
docs/
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,11 @@ bootstraparse aims to be customisable in that regard, but its first iteration an
|
||||||
You can refer to the `example_userfiles` for an idea of what the parser expects you to feed it and find an example of our automated generation at https://idle-org.github.io/bootstraparse/ for this particular folder. Or you can run the program yourself for the same result!
|
You can refer to the `example_userfiles` for an idea of what the parser expects you to feed it and find an example of our automated generation at https://idle-org.github.io/bootstraparse/ for this particular folder. Or you can run the program yourself for the same result!
|
||||||
|
|
||||||
- Main
|
- Main
|
||||||
- [](https://github.com/idle-org/bootstraparse/actions/workflows/python-app.yml)
|
- [](https://github.com/idle-org/bootstraparse/actions/workflows/python-tests.yml)
|
||||||
- Releases
|
- Releases
|
||||||
- [](https://github.com/idle-org/bootstraparse/actions/workflows/python-app.yml)
|
- [](https://github.com/idle-org/bootstraparse/actions/workflows/python-tests.yml)
|
||||||
|
- Deploy
|
||||||
|
- [](https://github.com/idle-org/bootstraparse/actions/workflows/python-deploy.yml)
|
||||||
---
|
---
|
||||||
## Release Notes
|
## Release Notes
|
||||||
### V1.0.1
|
### V1.0.1
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# Main program, use this to start parsing
|
# Main program, use this to start parsing
|
||||||
|
|
||||||
from bootstraparse.modules import sitecreator
|
from bootstraparse.modules import sitecreator, error_mngr
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
@ -21,5 +21,6 @@ def parse(_args):
|
||||||
|
|
||||||
if __name__ == "__main__": # pragma: no cover
|
if __name__ == "__main__": # pragma: no cover
|
||||||
args = parse(sys.argv[1:])
|
args = parse(sys.argv[1:])
|
||||||
|
error_mngr.init_logging(filename=None, loglevel="DEBUG", filemode='w', handler=None)
|
||||||
if sitecreator.create_website(args.origin, args.destination) == 0:
|
if sitecreator.create_website(args.origin, args.destination) == 0:
|
||||||
print("Bootstraparse run successful!")
|
print("Bootstraparse run successful!")
|
||||||
|
|
|
||||||
|
|
@ -21,4 +21,4 @@ export:
|
||||||
intermediate_files: true
|
intermediate_files: true
|
||||||
type: "html"
|
type: "html"
|
||||||
force_rewrite: true
|
force_rewrite: true
|
||||||
copy_unparsable_files: "copy" # "copy" or "ignore"
|
copy_unparsable_files: copy
|
||||||
|
|
|
||||||
|
|
@ -74,11 +74,16 @@ class ConfigLoader:
|
||||||
if name not in self.loaded_conf:
|
if name not in self.loaded_conf:
|
||||||
self.loaded_conf[name] = yaml.safe_load(f)
|
self.loaded_conf[name] = yaml.safe_load(f)
|
||||||
else:
|
else:
|
||||||
self.loaded_conf[name].update(yaml.safe_load(f))
|
new_config = yaml.safe_load(f)
|
||||||
error_mngr.log_message(f"Warning: {name} is already in {self.loaded_conf}", level='INFO')
|
for key in new_config:
|
||||||
|
if key in self.loaded_conf[name]:
|
||||||
|
self.loaded_conf[name][key].update(new_config[key])
|
||||||
|
else:
|
||||||
|
self.loaded_conf[name][key] = new_config[key]
|
||||||
|
error_mngr.log_message(f"Warning: {name} is already in {self.loaded_conf}", level='CRITICAL')
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
error_mngr.log_message(f'Error parsing in file {basename} at {filepath}.', level='CRITICAL')
|
error_mngr.log_message(f'Error parsing in file {basename} at {filepath}.', level='CRITICAL')
|
||||||
error_mngr.log_exception(str(e), level='CRITICAL')
|
error_mngr.log_exception(e, level='CRITICAL')
|
||||||
|
|
||||||
def load_from_folder(self, folder):
|
def load_from_folder(self, folder):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -436,14 +436,12 @@ class ContextManager:
|
||||||
def __init__(self, parsed_list, name=None, ident=0):
|
def __init__(self, parsed_list, name=None, ident=0):
|
||||||
"""
|
"""
|
||||||
Takes a list of parsed tokens.
|
Takes a list of parsed tokens.
|
||||||
Parameters
|
:type parsed_list : list[syntax.SemanticType]
|
||||||
----------
|
:param parsed_list: List of parsed tokens output by our parser.
|
||||||
parsed_list : list[syntax.SemanticType]
|
:type name: str
|
||||||
List of parsed tokens output by our parser.
|
:param name: Name of the file being parsed.
|
||||||
name : str
|
:type ident: int
|
||||||
Name of the file being parsed.
|
:param ident: Number of spaces to indent the output.
|
||||||
ident : int
|
|
||||||
Number of spaces to indent the output.
|
|
||||||
"""
|
"""
|
||||||
self.output = []
|
self.output = []
|
||||||
self.parsed_list = parsed_list
|
self.parsed_list = parsed_list
|
||||||
|
|
@ -464,15 +462,12 @@ class ContextManager:
|
||||||
"""
|
"""
|
||||||
Method to encapsulate a number of tokens together as a final container object
|
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.
|
and replace all elements in the pile with None, except the first one which becomes the container.
|
||||||
Parameters
|
:type start : int
|
||||||
----------
|
:param start: Index of the pile where the encapsulation must begin.
|
||||||
start : int
|
:type end: int
|
||||||
Index of the pile where the encapsulation must begin.
|
:param end: Index of the pile where the encapsulation must end.
|
||||||
end : int
|
:rtype: list[(BaseContainer|None)]
|
||||||
Index of the pile where the encapsulation must end.
|
:return: List of containers and None objects.
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
list[(BaseContainer|None)]
|
|
||||||
"""
|
"""
|
||||||
# Enabling this will allow us to debug the pile
|
# Enabling this will allow us to debug the pile
|
||||||
# print(f"Step : [{end}] - encapsulation:")
|
# print(f"Step : [{end}] - encapsulation:")
|
||||||
|
|
@ -514,18 +509,16 @@ class ContextManager:
|
||||||
container.add(self.pile[end])
|
container.add(self.pile[end])
|
||||||
self.pile[end] = None
|
self.pile[end] = None
|
||||||
self.pile[start] = container
|
self.pile[start] = container
|
||||||
|
return self.pile # ? I think this is the right way to return the pile
|
||||||
# print(" <<< Pile:", self.pile)
|
# print(" <<< Pile:", self.pile)
|
||||||
|
|
||||||
def _add_matched(self, label, index):
|
def _add_matched(self, label, index):
|
||||||
"""
|
"""
|
||||||
Method to add a matched element to the dictionary of matched elements.
|
Method to add a matched element to the dictionary of matched elements.
|
||||||
Parameters
|
:type label : str
|
||||||
----------
|
:param label: Label of the matched element.
|
||||||
label : str
|
:type index: int
|
||||||
Label of the matched element.
|
:param index: Index of the matched element in the pile.
|
||||||
index : int
|
|
||||||
Index of the matched element in the pile.
|
|
||||||
"""
|
"""
|
||||||
if label not in self.matched_elements:
|
if label not in self.matched_elements:
|
||||||
self.matched_elements[label] = []
|
self.matched_elements[label] = []
|
||||||
|
|
@ -534,13 +527,10 @@ class ContextManager:
|
||||||
def _get_matched(self, label):
|
def _get_matched(self, label):
|
||||||
"""
|
"""
|
||||||
Method to get the index of the last matched element of a given label.
|
Method to get the index of the last matched element of a given label.
|
||||||
Parameters
|
:type label: str
|
||||||
----------
|
:param label: Label of the matched element.
|
||||||
label : str
|
:rtype: int
|
||||||
Label of the matched element.
|
:return: Index of the last matched element
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
int : Index of the last matched element of the given label.
|
|
||||||
"""
|
"""
|
||||||
return self.matched_elements[label].pop()
|
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
|
Interprets the list of tokens provided and deduces context, encapsulating them to their closest neighbour and
|
||||||
containing all tokens inbetween.
|
containing all tokens inbetween.
|
||||||
Returns
|
:rtype: list[BaseContainer]
|
||||||
-------
|
:return: Returns the pile entirely processed as a list of containers.
|
||||||
list[BaseContainer]
|
:raises: MismatchedContainerError if a container is not matched to its corresponding token.
|
||||||
Returns the pile entirely processed as a list of containers.
|
|
||||||
Raise
|
|
||||||
-----
|
|
||||||
MismatchedContainerError
|
|
||||||
Raised when a container is not matched to its corresponding token.
|
|
||||||
"""
|
"""
|
||||||
# self.pile = self.parsed_list.copy()
|
# self.pile = self.parsed_list.copy()
|
||||||
if self.contextualised:
|
if self.contextualised:
|
||||||
|
|
@ -655,15 +640,12 @@ class ContextManager:
|
||||||
def lookahead(self, token, index):
|
def lookahead(self, token, index):
|
||||||
"""
|
"""
|
||||||
Iterates the pile beginning from index and looks for all tokens matching labels with token.
|
Iterates the pile beginning from index and looks for all tokens matching labels with token.
|
||||||
Parameters
|
:type token : syntax.BaseContainer
|
||||||
----------
|
:param token: Token to look for.
|
||||||
token : syntax.BaseContainer
|
:type index : int
|
||||||
Token to look for.
|
:param index: Index of the token in the pile.
|
||||||
index : int
|
:return: (number of tokens matched, number of linebreaks)
|
||||||
Index of the token in the pile.
|
:rtype: (int, int)
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
(int, int) : (number of tokens matched, number of linebreaks)
|
|
||||||
"""
|
"""
|
||||||
range_to_encapsulate = 0
|
range_to_encapsulate = 0
|
||||||
line_skipped = 0
|
line_skipped = 0
|
||||||
|
|
@ -691,29 +673,21 @@ class ContextManager:
|
||||||
def recontext(self, token):
|
def recontext(self, token):
|
||||||
"""
|
"""
|
||||||
Function to recontextualise the content of a token.
|
Function to recontextualise the content of a token.
|
||||||
Parameters
|
:param token: Token to recontextualise.
|
||||||
----------
|
:type token: syntax.SemanticType
|
||||||
token : syntax.SemanticType
|
:return: Token to recontextualise.
|
||||||
Token to recontextualise.
|
:rtype: syntax.SemanticType
|
||||||
"""
|
"""
|
||||||
token.content = ContextManager(token.content, name=self.name)()
|
token.content = ContextManager(token.content, name=self.name)()
|
||||||
|
|
||||||
def get_last_container_in_pile(self, index):
|
def get_last_container_in_pile(self, index):
|
||||||
"""
|
"""
|
||||||
Returns the last element in the pile if it is a Container, raises an error otherwise.
|
Returns the last element in the pile if it is a Container, raises an error otherwise.
|
||||||
Parameters
|
:type index : int
|
||||||
----------
|
:param index: Index of the element to check.
|
||||||
index : int
|
:return: Last element in the pile if it is a Container, raises an error otherwise.
|
||||||
Index of the element to check.
|
:rtype: BaseContainer
|
||||||
|
:raise: error_mngr.LonelyOptionalError when an element is found in the pile that is not encapsulated in a container.
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
BaseContainer
|
|
||||||
|
|
||||||
Raises
|
|
||||||
------
|
|
||||||
error_mngr.LonelyOptionalError
|
|
||||||
Raised 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
|
i = index-1 # skip last token as it is self
|
||||||
while i >= 0:
|
while i >= 0:
|
||||||
|
|
|
||||||
|
|
@ -94,18 +94,10 @@ class ExportManager:
|
||||||
"""
|
"""
|
||||||
Function for initializing other transform functions.
|
Function for initializing other transform functions.
|
||||||
|
|
||||||
Parameters:
|
:param export_request: ExportRequest tuples
|
||||||
----------
|
:type export_request: ExportRequest
|
||||||
export_request: ExportRequest tuples
|
:return: start, end, optionals
|
||||||
|
:rtype: str, str, str
|
||||||
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
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
start, end = None, None
|
start, end = None, None
|
||||||
|
|
@ -206,14 +198,12 @@ class ContextConverter:
|
||||||
def __init__(self, pile, exporter, destination):
|
def __init__(self, pile, exporter, destination):
|
||||||
"""
|
"""
|
||||||
Takes a pile and the exporter object
|
Takes a pile and the exporter object
|
||||||
Parameters
|
:type pile : list[context_mngr.BaseContainer]
|
||||||
----------
|
:param pile: output from the context manager.
|
||||||
pile : list[context_mngr.BaseContainer]
|
:type exporter : ExportManager
|
||||||
pile output from the context manager.
|
:param exporter: Our ExportManager
|
||||||
exporter : ExportManager
|
:type destination : str
|
||||||
Our ExportManager
|
:param destination: Destination of the output file.
|
||||||
destination : str
|
|
||||||
Destination of the output file.
|
|
||||||
"""
|
"""
|
||||||
self.io_output = StringIO()
|
self.io_output = StringIO()
|
||||||
self.pile = pile
|
self.pile = pile
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,10 @@ import bootstraparse.modules.syntax as syntax
|
||||||
def parse_line(io):
|
def parse_line(io):
|
||||||
"""
|
"""
|
||||||
Takes an io string and returns the parsed output.
|
Takes an io string and returns the parsed output.
|
||||||
Parameters:
|
:param io: The io string to parse.
|
||||||
io (StringIO): The io string to parse.
|
:type io: StringIO
|
||||||
Returns:
|
:return: The parsed output.
|
||||||
list[syntax.SemanticType]: The parsed output.
|
:rtype: list[syntax.SemanticType]
|
||||||
"""
|
"""
|
||||||
output = []
|
output = []
|
||||||
for line in io.readlines():
|
for line in io.readlines():
|
||||||
|
|
|
||||||
|
|
@ -98,21 +98,13 @@ class SemanticType:
|
||||||
def to_container(self, filter_func=None):
|
def to_container(self, filter_func=None):
|
||||||
"""
|
"""
|
||||||
Function called by the context manager to know how to deal with the encapsulation of the token.
|
Function called by the context manager to know how to deal with the encapsulation of the token.
|
||||||
|
:param filter_func: A function that will be used to filter the content of the token.
|
||||||
Parameters
|
:type filter_func: (callable| None)
|
||||||
----------
|
:return: Self if containable, the expected replacement token if it can, raises an error otherwise.
|
||||||
filter_func: (function | None)
|
:rtype: SemanticType | context_mngr.BaseContainer
|
||||||
A function that takes a token and returns a boolean. If the token is not valid, it should return False.
|
:raises CannotBeContainedError: Raises error if the token we were trying to encapsulate cannot be (probably mismatched).
|
||||||
|
|
||||||
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).
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raise MismatchedContainerError(self)
|
raise MismatchedContainerError(self)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from yaml.scanner import ScannerError
|
||||||
|
|
||||||
import bootstraparse.modules.config as config
|
import bootstraparse.modules.config as config
|
||||||
import pytest
|
import pytest
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
@ -10,7 +12,8 @@ configs = {
|
||||||
"app/configs/parser_config.yaml": '{"parser": {"name": "test_parser", "type": "test_parser"}}',
|
"app/configs/parser_config.yaml": '{"parser": {"name": "test_parser", "type": "test_parser"}}',
|
||||||
"app/configs/aliases.yaml": '{"parser": {"name": "test_parser", "type": "test_parser"}}',
|
"app/configs/aliases.yaml": '{"parser": {"name": "test_parser", "type": "test_parser"}}',
|
||||||
"user/config/aliases.yaml": '{"aliases": {"test_alias": "test_parser"}}',
|
"user/config/aliases.yaml": '{"aliases": {"test_alias": "test_parser"}}',
|
||||||
"user/config/glossary.yaml": '{"glossary": {"test_glossary": "test_parser"}}',
|
"app/configs/glossary.yaml": '{"glossary": {"test_glossary": "test_parser"}}',
|
||||||
|
"user/config/glossary.yaml": '{"glossary": {"test_glossary": "second_parser"}}',
|
||||||
"user/config/custom_template.yaml": '{"custom_template": {"test_template": "test_parser"}}',
|
"user/config/custom_template.yaml": '{"custom_template": {"test_template": "test_parser"}}',
|
||||||
}
|
}
|
||||||
bad_configs = {
|
bad_configs = {
|
||||||
|
|
@ -36,7 +39,9 @@ def make_false_configs():
|
||||||
def test_config_load():
|
def test_config_load():
|
||||||
usr_c = config.ConfigLoader(user_conf)
|
usr_c = config.ConfigLoader(user_conf)
|
||||||
assert usr_c["aliases"] == {"aliases": {"test_alias": "test_parser"}}
|
assert usr_c["aliases"] == {"aliases": {"test_alias": "test_parser"}}
|
||||||
assert usr_c["glossary"] == {"glossary": {"test_glossary": "test_parser"}}
|
assert usr_c["glossary"] == {"glossary": {"test_glossary": "second_parser"}}
|
||||||
|
assert usr_c["glossary"]["glossary"] == {"test_glossary": "second_parser"}
|
||||||
|
assert usr_c["glossary"]["glossary"]["test_glossary"] == "second_parser"
|
||||||
assert usr_c["aliases"]["aliases"] == {"test_alias": "test_parser"}
|
assert usr_c["aliases"]["aliases"] == {"test_alias": "test_parser"}
|
||||||
assert usr_c["aliases"]["aliases"]["test_alias"] == "test_parser"
|
assert usr_c["aliases"]["aliases"]["test_alias"] == "test_parser"
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
|
|
@ -54,7 +59,6 @@ def test_add_to_config():
|
||||||
assert from_list["aliases"] == {"aliases": {"test_alias": "test_parser"},
|
assert from_list["aliases"] == {"aliases": {"test_alias": "test_parser"},
|
||||||
"parser": {"name": "test_parser", "type": "test_parser"}}
|
"parser": {"name": "test_parser", "type": "test_parser"}}
|
||||||
assert from_list["parser_config"] == {"parser": {"name": "test_parser", "type": "test_parser"}}
|
assert from_list["parser_config"] == {"parser": {"name": "test_parser", "type": "test_parser"}}
|
||||||
|
|
||||||
with pytest.raises(KeyError): # Not FileNotFoundError
|
with pytest.raises(KeyError): # Not FileNotFoundError
|
||||||
assert from_empty["aliases"]
|
assert from_empty["aliases"]
|
||||||
from_empty.add_folder(user_conf)
|
from_empty.add_folder(user_conf)
|
||||||
|
|
@ -64,7 +68,7 @@ def test_add_to_config():
|
||||||
assert from_empty["aliases"] == {"aliases": {"test_alias": "test_parser"},
|
assert from_empty["aliases"] == {"aliases": {"test_alias": "test_parser"},
|
||||||
"parser": {"name": "test_parser", "type": "test_parser"}}
|
"parser": {"name": "test_parser", "type": "test_parser"}}
|
||||||
|
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(ScannerError):
|
||||||
from_empty.load_from_file(os.path.join(bad_conf, "bad_config.yaml"))
|
from_empty.load_from_file(os.path.join(bad_conf, "bad_config.yaml"))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue