Files
pydantic/changes/make_history.py
T
Samuel Colvin 33b7d52d31 moving docs to mkdocs (#856)
* moving docs to mkdocs

* transfering readme to md and more

* fixing build

* splitting usage.md

* improving schema.md and index.md

* fix make_history.rst

* models intro

* working on data conversation and required fields

* more fixes to models.md

* list all standard types supported

* list of pydantic types

* tweaks

* update links in code

* Apply suggestions from code review

incorporate @dmontagu's suggestions.

Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com>

* Apply suggestions from code review

more missed suggestions.

Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com>

* Apply suggestions from code review

more corrects.

* cleanup

* Field order warning

* fix and regenerate benchmarks

* format examples better, cleanup

* improve schema mapping table

* correct highlighting file types in schema.md

* add redirects in javascript

* add logo
2019-10-07 17:19:01 +01:00

47 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3.7
import re
import sys
from datetime import date
from importlib.machinery import SourceFileLoader
from pathlib import Path
THIS_DIR = Path(__file__).parent
name_regex = re.compile(r'(\d+)-(.*?)\.md')
bullet_list = []
for p in THIS_DIR.glob('*.md'):
if p.name == 'README.md':
continue
m = name_regex.fullmatch(p.name)
if not m:
raise RuntimeError(f'{p.name!r}: invalid change file name')
gh_id, creator = m.groups()
content = p.read_text().replace('\r\n', '\n').strip('\n. ')
if '\n\n' in content:
raise RuntimeError(f'{p.name!r}: content includes multiple paragraphs')
content = content.replace('\n', '\n ')
priority = 0 if '**breaking change' in content.lower() else 1
bullet_list.append((priority, int(gh_id), f'* {content}, #{gh_id} by @{creator}'))
if not bullet_list:
print('no changes found')
sys.exit(0)
version = SourceFileLoader('version', 'pydantic/version.py').load_module()
chunk_title = f'v{version.VERSION} ({date.today():%Y-%m-%d})'
new_chunk = '## {}\n{}\n'.format(chunk_title, '\n'.join(c for *_, c in sorted(bullet_list)))
print(f'{chunk_title}...{len(bullet_list)} items')
history_path = THIS_DIR / '..' / 'HISTORY.md'
history = history_path.read_text()
history_path.write_text(history)
for p in THIS_DIR.glob('*.md'):
if p.name != 'README.md':
p.unlink()
print(
'changes deleted and HISTORY.md successfully updated, to reset use:\n\n'
' git checkout -- changes/*-*.md HISTORY.md\n'
)