Compare commits
No commits in common. "da2d8c8c6db6bd5d4c6870026088999b40cb6e2d" and "423d6f98420f01faf856329d7ab8e690c0aba2fa" have entirely different histories.
da2d8c8c6d
...
423d6f9842
3
.gitignore
vendored
3
.gitignore
vendored
@ -139,6 +139,3 @@ dmypy.json
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# Files for PyPI publishing
|
||||
README.md
|
||||
|
@ -17,12 +17,8 @@ from . import dom
|
||||
|
||||
DEBUG_DIFF_CONTEXT = 10
|
||||
|
||||
DEFAULT_TODO_KEYWORDS = ["TODO"]
|
||||
DEFAULT_DONE_KEYWORDS = ["DONE"]
|
||||
|
||||
BASE_ENVIRONMENT = {
|
||||
"org-footnote-section": "Footnotes",
|
||||
"org-todo-keywords": ' '.join(DEFAULT_TODO_KEYWORDS) + ' | ' + ' '.join(DEFAULT_DONE_KEYWORDS),
|
||||
"org-options-keywords": (
|
||||
"ARCHIVE:",
|
||||
"AUTHOR:",
|
||||
@ -56,6 +52,9 @@ BASE_ENVIRONMENT = {
|
||||
),
|
||||
}
|
||||
|
||||
DEFAULT_TODO_KEYWORDS = ["TODO"]
|
||||
DEFAULT_DONE_KEYWORDS = ["DONE"]
|
||||
|
||||
HEADLINE_TAGS_RE = re.compile(r"((:(\w|[0-9_@#%])+)+:)\s*$")
|
||||
HEADLINE_RE = re.compile(r"^(?P<stars>\*+)(?P<spacing>\s+)(?P<line>.*?)$")
|
||||
KEYWORDS_RE = re.compile(
|
||||
@ -1865,27 +1864,17 @@ def dump_delimiters(line: DelimiterLine):
|
||||
|
||||
class OrgDoc:
|
||||
def __init__(
|
||||
self, headlines, keywords, contents, list_items, structural, properties,
|
||||
environment=BASE_ENVIRONMENT,
|
||||
self, headlines, keywords, contents, list_items, structural, properties
|
||||
):
|
||||
self.todo_keywords = DEFAULT_TODO_KEYWORDS
|
||||
self.done_keywords = DEFAULT_DONE_KEYWORDS
|
||||
|
||||
keywords_set_in_file = False
|
||||
for keyword in keywords:
|
||||
if keyword.key in ("TODO", "SEQ_TODO"):
|
||||
todo_kws, done_kws = re.sub(r"\([^)]+\)", "", keyword.value).split("|", 1)
|
||||
|
||||
self.todo_keywords = re.sub(r"\s{2,}", " ", todo_kws.strip()).split()
|
||||
self.done_keywords = re.sub(r"\s{2,}", " ", done_kws.strip()).split()
|
||||
keywords_set_in_file = True
|
||||
|
||||
if not keywords_set_in_file and 'org-todo-keywords' in environment:
|
||||
# Read keywords from environment
|
||||
todo_kws, done_kws = re.sub(r"\([^)]+\)", "", environment['org-todo-keywords']).split("|", 1)
|
||||
|
||||
self.todo_keywords = re.sub(r"\s{2,}", " ", todo_kws.strip()).split()
|
||||
self.done_keywords = re.sub(r"\s{2,}", " ", done_kws.strip()).split()
|
||||
|
||||
self.keywords: List[Property] = keywords
|
||||
self.contents: List[RawLine] = contents
|
||||
@ -2061,7 +2050,7 @@ class OrgDoc:
|
||||
|
||||
|
||||
class OrgDocReader:
|
||||
def __init__(self, environment=BASE_ENVIRONMENT):
|
||||
def __init__(self):
|
||||
self.headlines: List[HeadlineDict] = []
|
||||
self.keywords: List[Keyword] = []
|
||||
self.headline_hierarchy: List[Optional[HeadlineDict]] = []
|
||||
@ -2072,7 +2061,6 @@ class OrgDocReader:
|
||||
self.structural: List = []
|
||||
self.properties: List = []
|
||||
self.current_drawer: Optional[List] = None
|
||||
self.environment = environment
|
||||
|
||||
def finalize(self):
|
||||
return OrgDoc(
|
||||
@ -2082,7 +2070,6 @@ class OrgDocReader:
|
||||
self.list_items,
|
||||
self.structural,
|
||||
self.properties,
|
||||
self.environment,
|
||||
)
|
||||
|
||||
## Construction
|
||||
@ -2271,7 +2258,7 @@ class OrgDocReader:
|
||||
|
||||
self.current_drawer.append(Property(linenum, match, key, value, None))
|
||||
|
||||
def read(self, s):
|
||||
def read(self, s, environment):
|
||||
lines = s.split("\n")
|
||||
line_count = len(lines)
|
||||
reader = enumerate(lines)
|
||||
@ -2362,8 +2349,8 @@ class OrgDocReader:
|
||||
|
||||
|
||||
def loads(s, environment=BASE_ENVIRONMENT, extra_cautious=True):
|
||||
reader = OrgDocReader(environment)
|
||||
reader.read(s)
|
||||
reader = OrgDocReader()
|
||||
reader.read(s, environment)
|
||||
doc = reader.finalize()
|
||||
if extra_cautious: # Check that all options can be properly re-serialized
|
||||
after_dump = dumps(doc)
|
||||
|
@ -5,8 +5,6 @@ set -eu
|
||||
cd "`dirname $0`"
|
||||
cd ..
|
||||
|
||||
pandoc README.org -o README.md # PyPI doesn't accept Org files
|
||||
|
||||
python setup.py sdist
|
||||
|
||||
twine upload --verbose dist/*
|
||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
||||
|
||||
setup(
|
||||
name="org-rw",
|
||||
version="0.0.2",
|
||||
version="0.0.1.dev1",
|
||||
description="Library to de/serialize org-files and manipulate them.",
|
||||
author="kenkeiras",
|
||||
author_email="kenkeiras@codigoparallevar.com",
|
||||
|
@ -794,38 +794,6 @@ class TestSerde(unittest.TestCase):
|
||||
|
||||
self.assertEqual(dumps(doc), orig)
|
||||
|
||||
def test_add_todo_keywords_programatically(self):
|
||||
orig = '''* NEW_TODO_STATE First entry
|
||||
|
||||
* 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)
|
||||
|
||||
self.assertEqual(doc.headlines[1].is_todo, False)
|
||||
self.assertEqual(doc.headlines[1].is_done, True)
|
||||
|
||||
self.assertEqual(dumps(doc), orig)
|
||||
|
||||
def test_add_todo_keywords_in_file(self):
|
||||
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"
|
||||
})
|
||||
self.assertEqual(doc.headlines[0].is_todo, True)
|
||||
self.assertEqual(doc.headlines[0].is_done, False)
|
||||
|
||||
self.assertEqual(doc.headlines[1].is_todo, False)
|
||||
self.assertEqual(doc.headlines[1].is_done, True)
|
||||
|
||||
self.assertEqual(dumps(doc), orig)
|
||||
|
||||
|
||||
def print_tree(tree, indentation=0, headline=None):
|
||||
for element in tree:
|
||||
|
Loading…
Reference in New Issue
Block a user