karlicoss / orgparse

Python module for reading Emacs org-mode files
https://orgparse.readthedocs.org
BSD 2-Clause "Simplified" License
371 stars 43 forks source link

Support more Effort format in Properties #35

Closed j3soon closed 3 years ago

j3soon commented 3 years ago

The following code produces error in orgparse 0.2.3:

from orgparse import loads
root = loads('''
* Node
  :PROPERTIES:
  :Effort: 1:23:45
  :END:
''')
root.children[0].properties['Effort']

Error message:

./venv/lib/python3.6/site-packages/orgparse/node.py in parse_property(line)
    136     match = RE_PROP.search(line)
    137     if match:
--> 138         prop_key = match.group(1)
    139         prop_val = match.group(2)
    140         if prop_key == 'Effort':

ValueError: too many values to unpack (expected 2)

Other formats listed below results in similar errors:

The available effort formats are mentioned in org-duration.el. I can parse these formats by adding some tests and modifying orgparse/node.py line140-143. If supporting such format is preferable, I can work on this during my free time and open a PR.

karlicoss commented 3 years ago

Thanks for reporting! Yeah, it would be welcome! I never used efforts in org-mode so I guess that's why I haven't noticed. If you could add some tests here https://github.com/karlicoss/orgparse/blob/ce8f6ccf60d6dca60c5f03890d730676a5d1ac21/orgparse/node.py#L130-L131 would be great as well

You can use tox to run all tests, or more specifically this command https://github.com/karlicoss/orgparse/blob/45b366eb5c23e4149d8bc7a319f10dc74888fe51/tox.ini#L9

P.S. I guess another thing to think about is that it's probably not great to crash on a relatively minor parsing issue, but not sure what would be a good way to do it. Maybe orgparse could work in 'strict' and 'defensive' modes, so people could adjust to their level of tolerance. (not for this change of course, just thinking out loud :) )

karlicoss commented 3 years ago

Now on pypi! thanks https://pypi.org/project/orgparse/