Skip to content

Commit

Permalink
In merge, ensure that an uncommented RTD badge isn't lost when resolv…
Browse files Browse the repository at this point in the history
…ing placeholders. Ref jaraco/skeleton#101.
  • Loading branch information
jaraco committed Dec 23, 2023
1 parent fbd7e14 commit dba2c6c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
31 changes: 30 additions & 1 deletion jaraco/develop/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import contextlib
from pathlib import Path

from jaraco.functools import identity
import autocommand


Expand Down Expand Up @@ -87,7 +88,35 @@ def resolve_placeholders(conflict):
assert 'PROJECT' in conflict.right
from . import repo

return repo.sub_placeholders(conflict.right)
return _retain_rtd(conflict.left)(repo.sub_placeholders(conflict.right))


def _retain_rtd(left):
"""
Retain the RTD enablement.
If RTD was enabled (uncommented) in left, return a function that
will enable it on the right. Otherwise, return a pass-through function.
>>> _retain_rtd('''.. image:: https://readthedocs.org/...''')
<function _enable_rtd at ...>
>>> _retain_rtd('''.. .. image:: https://readthedocs.org/...''')
<function identity at ...>
"""
enabled = re.search(r'^\.\. image.*readthedocs', left, flags=re.MULTILINE)
return _enable_rtd if enabled else identity


def _enable_rtd(text):
"""
Given text with a commented RTD badge, uncomment it.
>>> print(_enable_rtd('''.. .. image:: https://readthedocs.org/...
... .. :target: https://PROJECT_RTD.readthedocs.io/...'''))
.. image:: https://readthedocs.org/...
:target: https://PROJECT_RTD.readthedocs.io/...
"""
return re.sub(r'^\.\. ', '', text, flags=re.MULTILINE)


def resolve_shebang(conflict):
Expand Down
1 change: 1 addition & 0 deletions newsfragments/+6bb5135e.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In merge, ensure that an uncommented RTD badge isn't lost when resolving placeholders.

0 comments on commit dba2c6c

Please sign in to comment.