Skip to content

Commit

Permalink
Update setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cgohlke committed May 20, 2024
1 parent 9000e74 commit a54f90c
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,32 @@
buildnumber = ''


def search(pattern, code, flags=0):
# return first match for pattern in code
match = re.search(pattern, code, flags)
def search(pattern, string, flags=0):
"""Return first match of pattern in string."""
match = re.search(pattern, string, flags)
if match is None:
raise ValueError(f'{pattern!r} not found')
return match.groups()[0]


def fix_docstring_examples(docstring):
"""Return docstring with examples fixed for GitHub."""
start = True
indent = False
lines = ['..', ' This file is generated by setup.py', '']
for line in docstring.splitlines():
if not line.strip():
start = True
indent = False
if line.startswith('>>> '):
indent = True
if start:
lines.extend(['.. code-block:: python', ''])
start = False
lines.append((' ' if indent else '') + line)
return '\n'.join(lines)


with open('tifffile/tifffile.py', encoding='utf-8') as fh:
code = fh.read().replace('\r\n', '\n').replace('\r', '\n')

Expand All @@ -39,7 +57,7 @@ def search(pattern, code, flags=0):
# update README, LICENSE, and CHANGES files

with open('README.rst', 'w', encoding='utf-8') as fh:
fh.write(readme)
fh.write(fix_docstring_examples(readme))

license = search(
r'(# Copyright.*?(?:\r\n|\r|\n))(?:\r\n|\r|\n)+r""',
Expand Down

0 comments on commit a54f90c

Please sign in to comment.