diff --git a/.gitea/workflows/tests.yaml b/.gitea/workflows/tests.yaml index a3adf0a..f56a490 100644 --- a/.gitea/workflows/tests.yaml +++ b/.gitea/workflows/tests.yaml @@ -9,8 +9,8 @@ jobs: - name: Check out repository code uses: actions/checkout@v3 - run: apt-get update && apt-get install -y python3-pip - - run: pip install --break-system-package -e . - - run: pip install --break-system-package pytest + - run: pip install -e . + - run: pip install pytest - run: pytest mypy: @@ -19,8 +19,8 @@ jobs: - name: Check out repository code uses: actions/checkout@v3 - run: apt-get update && apt-get install -y python3-pip - - run: pip install --break-system-package -e . - - run: pip install --break-system-package mypy + - run: pip install -e . + - run: pip install mypy - run: mypy org_rw --check-untyped-defs style-formatting: @@ -29,8 +29,8 @@ jobs: - name: Check out repository code uses: actions/checkout@v3 - run: apt-get update && apt-get install -y python3-pip - - run: pip install --break-system-package -e . - - run: pip install --break-system-package black + - run: pip install -e . + - run: pip install black - run: black --check . style-sorted-imports: @@ -39,8 +39,8 @@ jobs: - name: Check out repository code uses: actions/checkout@v3 - run: apt-get update && apt-get install -y python3-pip - - run: pip install --break-system-package -e . - - run: pip install --break-system-package isort + - run: pip install -e . + - run: pip install isort - run: isort --profile black --check . stability-extra-test: @@ -49,5 +49,5 @@ jobs: - name: Check out repository code uses: actions/checkout@v3 - run: apt-get update && apt-get install -y git-core python3-pip - - run: pip install --break-system-package -e . + - run: pip install -e . - run: bash extra-tests/check_all.sh diff --git a/org_rw/dom.py b/org_rw/dom.py index baf0092..f9ed40f 100644 --- a/org_rw/dom.py +++ b/org_rw/dom.py @@ -24,14 +24,6 @@ class ResultsDrawerNode(DrawerNode): return "".format(len(self.children)) -class GenericDrawerNode(DrawerNode): - def __init__(self, drawer_name): - self.drawer_name = drawer_name - - def __repr__(self): - return "".format(self.drawer_name, len(self.children)) - - class PropertyNode: def __init__(self, key, value): self.key = key @@ -70,18 +62,12 @@ class TableSeparatorRow: def __init__(self, orig=None): self.orig = orig - def get_raw(self): - return get_raw_contents(self.orig) - class TableRow: def __init__(self, cells, orig=None): self.cells = cells self.orig = orig - def get_raw(self): - return get_raw_contents(self.orig) - class Text: def __init__(self, content): diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index bc9657a..4fc5da5 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -122,7 +122,6 @@ NON_FINISHED_GROUPS = ( dom.ListGroupNode, dom.ResultsDrawerNode, dom.PropertyDrawerNode, - dom.GenericDrawerNode, ) FREE_GROUPS = (dom.CodeBlock,) @@ -415,7 +414,6 @@ class Headline: if ( isinstance(line, DelimiterLine) and line.delimiter_type == DelimiterLineType.END_BLOCK - and line.type_data.subtype == current_node.header.type_data.subtype ): start = current_node.header.linenum end = line.linenum @@ -637,13 +635,6 @@ class Headline: assert current_node is None current_node = dom.ResultsDrawerNode() - # TODO: Allow indentation of these blocks inside others - indentation_tree = [current_node] - tree.append(current_node) - elif content.strip().startswith(":") and content.strip().endswith(":"): - assert current_node is None - current_node = dom.GenericDrawerNode(content.strip().strip(":")) - # TODO: Allow indentation of these blocks inside others indentation_tree = [current_node] tree.append(current_node) @@ -871,24 +862,9 @@ class Headline: yield from get_links_from_content(item.content) def get_lines_between(self, start, end): - # @TODO: Generalize for other line types too. - everything = ( - [] - # + self.keywords - + self.contents - # + self.list_items - # + self.table_rows - # + self.properties - # + self.structural - + self.delimiters - ) - - for line in everything: + for line in self.contents: if start <= line.linenum < end: - if "get_raw" in dir(line): - yield "".join(line.get_raw()) - else: - yield line.line + yield "".join(line.get_raw()) def get_contents(self, format): if format == "raw": @@ -1816,7 +1792,7 @@ def token_list_to_plaintext(tok_list) -> str: else: assert isinstance(chunk, MarkerToken) - return "".join(contents) + return "".join(contents).strip() def token_list_to_raw(tok_list): @@ -2327,7 +2303,6 @@ class OrgDoc: list_items, structural, properties, - delimiters, environment=BASE_ENVIRONMENT, ): self.todo_keywords = [HeadlineState(name=kw) for kw in DEFAULT_TODO_KEYWORDS] @@ -2357,7 +2332,6 @@ class OrgDoc: self.list_items: List[ListItem] = list_items self.structural: List = structural self.properties: List = properties - self.delimiters: List = delimiters self._path = None self.headlines: List[Headline] = list( map(lambda hl: parse_headline(hl, self, self), headlines) @@ -2528,9 +2502,6 @@ class OrgDoc: for struct in self.structural: lines.append(dump_structural(struct)) - for content in self.delimiters: - lines.append(dump_delimiters(content)) - for kw in self.keywords: lines.append(dump_kw(kw)) @@ -2568,7 +2539,6 @@ class OrgDocReader: self.list_items, self.structural, self.properties, - self.delimiters, self.environment, ) diff --git a/org_rw/utils.py b/org_rw/utils.py index 87f6712..5b8b4e5 100644 --- a/org_rw/utils.py +++ b/org_rw/utils.py @@ -9,7 +9,6 @@ from .org_rw import ( ListItem, RawLine, Strike, - TableRow, Text, Underlined, Verbatim, @@ -51,8 +50,6 @@ def get_raw_contents(doc) -> str: return doc.get_raw() if isinstance(doc, ListItem): return dump_contents(doc)[1] - if isinstance(doc, TableRow): - return dump_contents(doc)[1] print("Unhandled type: " + str(doc)) raise NotImplementedError("Unhandled type: " + str(doc)) diff --git a/tests/14-titles.org b/tests/14-titles.org deleted file mode 100644 index 75b88a7..0000000 --- a/tests/14-titles.org +++ /dev/null @@ -1,12 +0,0 @@ -#+TITLE: 14-Simple -#+DESCRIPTION: Org file to evaluate titles -#+TODO: TODO(t) PAUSED(p) | DONE(d) - - -* Simple title - -* Simple title with tags :tag: - -* Simple title with trailing space - -* Simple title with leading space diff --git a/tests/test_org.py b/tests/test_org.py index d6b4351..a1fdff1 100644 --- a/tests/test_org.py +++ b/tests/test_org.py @@ -955,24 +955,6 @@ class TestSerde(unittest.TestCase): h1_2_h2 = h1_2.children[0] self.assertEqual(sorted(h1_2_h2.tags), ["otherh2tag"]) - def test_titles_file(self): - with open(os.path.join(DIR, "14-titles.org")) as f: - doc = load(f) - - h1, h2, h3, h4 = doc.getTopHeadlines() - self.assertEqual(h1.title.get_text(), "Simple title") - self.assertEqual(h2.title.get_text(), "Simple title with tags") - self.assertEqual(h3.title.get_text(), "Simple title with trailing space") - self.assertEqual(h4.title.get_text(), "Simple title with leading space") - - def test_mimic_write_file_14(self): - """A goal of this library is to be able to update a file without changing parts not directly modified.""" - with open(os.path.join(DIR, "14-titles.org")) as f: - orig = f.read() - doc = loads(orig) - - self.assertEqual(dumps(doc), orig) - def test_update_headline_from_none_to_todo(self): orig = "* First entry" doc = loads(orig)