-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Moire compatible with Python 3.8
We downgrade the Python version, because Moire don't use that much of 3.9 features and it feels better to cover more Python versions.
- Loading branch information
Showing
7 changed files
with
24 additions
and
24 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
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 |
---|---|---|
|
@@ -5,9 +5,9 @@ | |
|
||
import logging | ||
import sys | ||
from argparse import ArgumentParser, BooleanOptionalAction, Namespace | ||
from argparse import ArgumentParser, Namespace | ||
from pathlib import Path | ||
from typing import Optional | ||
from typing import List, Optional | ||
|
||
from moire.default import Default | ||
from moire.moire import Moire | ||
|
@@ -16,8 +16,7 @@ | |
__email__ = "[email protected]" | ||
|
||
|
||
def main(arguments: list[str] = None, top_class=None): | ||
|
||
def main(arguments: List[str] = None, top_class=None): | ||
if not arguments: | ||
arguments = sys.argv[1:] | ||
if not top_class: | ||
|
@@ -30,7 +29,7 @@ def main(arguments: list[str] = None, top_class=None): | |
parser.add_argument("-i", "--input", help="Moire input file", required=True) | ||
parser.add_argument("-o", "--output", help="output file") | ||
parser.add_argument("-f", "--format", help="output format", required=True) | ||
parser.add_argument("--wrap", action=BooleanOptionalAction, default=True) | ||
parser.add_argument("--wrap", action="store_true", default=True) | ||
|
||
options: Namespace = parser.parse_args(arguments) | ||
|
||
|
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
from dataclasses import dataclass | ||
from io import StringIO | ||
|
||
from typing import Any, Callable, Optional | ||
from typing import Any, Callable, Dict, List, Optional, Tuple | ||
|
||
__author__: str = "Sergey Vartanov" | ||
__email__: str = "[email protected]" | ||
|
@@ -103,8 +103,8 @@ def find(self, text: str) -> Optional["Tree"]: | |
|
||
@dataclass | ||
class Argument: | ||
array: list | ||
spec: dict[str, Any] | ||
array: List | ||
spec: Dict[str, Any] | ||
|
||
def __getitem__(self, key: int): | ||
return self.array[key] | ||
|
@@ -152,13 +152,13 @@ def is_letter_or_digit(char: str) -> bool: | |
return "a" <= char <= "z" or "A" <= char <= "Z" or "0" <= char <= "9" | ||
|
||
|
||
def lexer(text) -> (list[Lexeme], list[int]): | ||
def lexer(text) -> (List[Lexeme], List[int]): | ||
"""Parse formatted preprocessed text to a list of lexemes.""" | ||
in_tag: bool = False # Lexer position in tag name | ||
# Lexer position in space between tag name and first "{" | ||
in_space: bool = True | ||
lexemes: list[Lexeme] = [] | ||
positions: list[int] = [] | ||
lexemes: List[Lexeme] = [] | ||
positions: List[int] = [] | ||
tag_name: str = "" | ||
word: str = "" | ||
|
||
|
@@ -270,12 +270,12 @@ def get_intermediate(lexemes, positions, level, index=0): | |
|
||
class Moire: | ||
name: str = "Empty format" | ||
block_tags: list[str] = [] | ||
escape_symbols: dict[str, str] = {} | ||
block_tags: List[str] = [] | ||
escape_symbols: Dict[str, str] = {} | ||
|
||
def __init__(self, file_name: Optional[str] = None): | ||
self.index: int = 0 | ||
self.status: dict[str, Any] = {"missing_tags": set()} | ||
self.status: Dict[str, Any] = {"missing_tags": set()} | ||
self.file_name: Optional[str] = file_name | ||
|
||
def init(self): | ||
|
@@ -298,13 +298,13 @@ def trim(self, text: str) -> str: | |
text = text[:-1] | ||
return text | ||
|
||
def get_ids(self, content: str) -> list[tuple[str, int]]: | ||
def get_ids(self, content: str) -> List[Tuple[str, int]]: | ||
"""Get all header identifiers. | ||
:param content: input content in the Moire format | ||
:return: list of tuples (id, level), level is 0 for labels | ||
""" | ||
ids: list[tuple[str, int]] = [] | ||
ids: List[Tuple[str, int]] = [] | ||
intermediate_representation = self.get_ir(content) | ||
for element in intermediate_representation: | ||
if isinstance(element, Tag): | ||
|
@@ -315,7 +315,7 @@ def get_ids(self, content: str) -> list[tuple[str, int]]: | |
return ids | ||
|
||
def convert( | ||
self, input_data: str, wrap: bool = True, in_block: bool = True | ||
self, input_data: str, wrap: bool = True, in_block: bool = False | ||
) -> str: | ||
"""Convert Moire text without includes but with comments artifacts to | ||
selected format. | ||
|
@@ -361,7 +361,7 @@ def parse( | |
in_block: bool = False, | ||
depth: int = 0, | ||
mode: str = "", | ||
spec: Optional[dict[str, Any]] = None, | ||
spec: Optional[Dict[str, Any]] = None, | ||
) -> str: | ||
"""Element parsing into formatted text. | ||
|
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
author="Sergey Vartanov", | ||
author_email="[email protected]", | ||
description="Simple extendable markup", | ||
python_requires=">=3.8", | ||
entry_points={ | ||
"console_scripts": ["moire=moire.main:main"], | ||
}, | ||
|