Compare commits

...

6 Commits

Author SHA1 Message Date
05718e1001 Merge pull request 'feat: Apply and check autoformatting' (#8) from apply-and-check-autoformatting into develop
All checks were successful
Testing / pytest (push) Successful in 43s
Testing / mypy (push) Successful in 54s
Testing / style-formatting (push) Successful in 55s
Testing / style-sorted-imports (push) Successful in 28s
Testing / stability-extra-test (push) Successful in 53s
Reviewed-on: #8
2024-08-19 21:41:32 +00:00
Sergio Martínez Portela
e991074346 fix: Apply import sorting.
All checks were successful
Testing / pytest (push) Successful in 30s
Testing / mypy (push) Successful in 34s
Testing / style-formatting (push) Successful in 29s
Testing / style-sorted-imports (push) Successful in 26s
Testing / stability-extra-test (push) Successful in 32s
2024-08-18 22:49:33 +02:00
Sergio Martínez Portela
66b42e0b96 feat: Add script to apply formatting tools. 2024-08-18 22:49:06 +02:00
Sergio Martínez Portela
c6d8575ae5 test: Test sorted imports. 2024-08-18 22:47:42 +02:00
Sergio Martínez Portela
8ca480ad77 fix: Apply black formatter. 2024-08-18 22:47:24 +02:00
Sergio Martínez Portela
0a55c64551 test: Add formatting check to CI/CD. 2024-08-18 22:47:24 +02:00
8 changed files with 110 additions and 43 deletions

View File

@ -23,6 +23,26 @@ jobs:
- run: pip install mypy
- run: mypy org_rw --check-untyped-defs
style-formatting:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
- run: apt-get update && apt-get install -y python3-pip
- run: pip install -e .
- run: pip install black
- run: black --check .
style-sorted-imports:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
- run: apt-get update && apt-get install -y python3-pip
- run: pip install -e .
- run: pip install isort
- run: isort --profile black --check .
stability-extra-test:
runs-on: ubuntu-latest
steps:

View File

@ -41,11 +41,12 @@ class ListGroupNode:
self.children.append(child)
def get_raw(self):
return '\n'.join([c.get_raw() for c in self.children])
return "\n".join([c.get_raw() for c in self.children])
def __repr__(self):
return "<List: {}>".format(len(self.children))
class TableNode:
def __init__(self):
self.children = []
@ -56,21 +57,24 @@ class TableNode:
def __repr__(self):
return "<Table: {}>".format(len(self.children))
class TableSeparatorRow:
def __init__(self, orig=None):
self.orig = orig
class TableRow:
def __init__(self, cells, orig=None):
self.cells = cells
self.orig = orig
class Text:
def __init__(self, content):
self.content = content
def get_raw(self):
return ''.join(self.content.get_raw())
return "".join(self.content.get_raw())
class ListItem:
@ -105,7 +109,9 @@ class CodeBlock(BlockNode):
def __repr__(self):
return "<Code: {}>".format(len(self.lines or []))
DomNode = Union[DrawerNode,
DomNode = Union[
DrawerNode,
PropertyNode,
ListGroupNode,
TableNode,
@ -116,7 +122,8 @@ DomNode = Union[DrawerNode,
BlockNode,
]
ContainerDomNode = Union[DrawerNode,
ContainerDomNode = Union[
DrawerNode,
ListGroupNode,
TableNode,
BlockNode,

View File

@ -1,6 +1,5 @@
from __future__ import annotations
from typing import Dict, Optional, TextIO
from datetime import timedelta
import collections
import difflib
import logging
@ -9,12 +8,21 @@ import re
import sys
from datetime import date, datetime, timedelta
from enum import Enum
from typing import cast, Iterator, List, Literal, Optional, Tuple, TypedDict, Union
from .types import HeadlineDict
from typing import (
Dict,
Iterator,
List,
Literal,
Optional,
TextIO,
Tuple,
TypedDict,
Union,
cast,
)
from . import dom
from .types import HeadlineDict
DEBUG_DIFF_CONTEXT = 10

View File

@ -1,9 +1,19 @@
import uuid
from .org_rw import (Bold, Code, Headline, Italic, Line, RawLine, ListItem, Strike, Text,
Underlined, Verbatim)
from .org_rw import dump_contents
from .org_rw import (
Bold,
Code,
Headline,
Italic,
Line,
ListItem,
RawLine,
Strike,
Text,
Underlined,
Verbatim,
dump_contents,
)
def get_hl_raw_contents(doc: Headline) -> str:

11
scripts/apply-formatting.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
set -eu
cd "`dirname $0`"
cd ..
set -x
isort --profile black .
black .

View File

@ -2,9 +2,6 @@ import os
import unittest
from datetime import datetime as DT
from org_rw import MarkerToken, MarkerType, Timestamp, dumps, load, loads, dom
import org_rw
from utils.assertions import (
BOLD,
CODE,
@ -19,6 +16,9 @@ from utils.assertions import (
Tokens,
)
import org_rw
from org_rw import MarkerToken, MarkerType, Timestamp, dom, dumps, load, loads
DIR = os.path.dirname(os.path.abspath(__file__))
@ -834,12 +834,12 @@ class TestSerde(unittest.TestCase):
self.assertEqual(dumps(doc), orig)
def test_add_todo_keywords_programatically(self):
orig = '''* NEW_TODO_STATE First entry
orig = """* NEW_TODO_STATE First entry
* NEW_DONE_STATE Second entry'''
doc = loads(orig, environment={
'org-todo-keywords': "NEW_TODO_STATE | NEW_DONE_STATE"
})
* NEW_DONE_STATE Second entry"""
doc = loads(
orig, environment={"org-todo-keywords": "NEW_TODO_STATE | NEW_DONE_STATE"}
)
self.assertEqual(doc.headlines[0].is_todo, True)
self.assertEqual(doc.headlines[0].is_done, False)
@ -849,14 +849,14 @@ class TestSerde(unittest.TestCase):
self.assertEqual(dumps(doc), orig)
def test_add_todo_keywords_in_file(self):
orig = '''#+TODO: NEW_TODO_STATE | NEW_DONE_STATE
orig = """#+TODO: NEW_TODO_STATE | NEW_DONE_STATE
* NEW_TODO_STATE First entry
* NEW_DONE_STATE Second entry'''
doc = loads(orig, environment={
'org-todo-keywords': "NEW_TODO_STATE | NEW_DONE_STATE"
})
* NEW_DONE_STATE Second entry"""
doc = loads(
orig, environment={"org-todo-keywords": "NEW_TODO_STATE | NEW_DONE_STATE"}
)
self.assertEqual(doc.headlines[0].is_todo, True)
self.assertEqual(doc.headlines[0].is_done, False)

View File

@ -1,7 +1,9 @@
"""Test the Timestamp object."""
import pytest
from datetime import date, datetime
import pytest
from org_rw import Timestamp

View File

@ -2,8 +2,17 @@ import collections
import unittest
from datetime import datetime
from org_rw import (Bold, Code, Italic, Line, Strike, Text, Underlined,
Verbatim, get_raw_contents)
from org_rw import (
Bold,
Code,
Italic,
Line,
Strike,
Text,
Underlined,
Verbatim,
get_raw_contents,
)
def timestamp_to_datetime(ts):