Skip to content

Commit

Permalink
Make Moire compatible with Python 3.8
Browse files Browse the repository at this point in the history
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
enzet committed Jul 30, 2024
1 parent 5fd873a commit 5b0e4f1
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Rendering:
Installation
------------

Requirements: Python 3.9.
Requirements: Python 3.8.

```bash
pip install .
Expand Down
2 changes: 1 addition & 1 deletion doc/readme.moi
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Rendering\:

\2 {Installation} {installation}

Requirements: Python 3.9.
Requirements: Python 3.8.

\code {bash} {pip install .}

Expand Down
4 changes: 2 additions & 2 deletions moire/default.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from argparse import ArgumentParser, Namespace
from typing import Any, Dict, List, Set
from typing import Any, Dict, List, Set, Tuple
from textwrap import dedent

from moire.moire import Moire
Expand Down Expand Up @@ -71,7 +71,7 @@ def m(self, arg: Arguments) -> str:
def formal(self, arg: Arguments) -> str:
raise TagNotImplementedError("formal")

def _parse_code_arguments(self, arg: Arguments) -> tuple[str, str]:
def _parse_code_arguments(self, arg: Arguments) -> Tuple[str, str]:
"""Parse trimmed code and possible language identifier."""
if len(arg) == 1:
return self.trim(self.parse(arg[0], spec={"trim": False})), ""
Expand Down
9 changes: 4 additions & 5 deletions moire/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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)

Expand Down
26 changes: 13 additions & 13 deletions moire/moire.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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 = ""

Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
},
Expand Down

0 comments on commit 5b0e4f1

Please sign in to comment.