update_changelog.py 972 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env python3
  2. # Allow direct execution
  3. import os
  4. import sys
  5. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  6. from pathlib import Path
  7. from devscripts.make_changelog import create_changelog, create_parser
  8. from devscripts.utils import read_file, read_version, write_file
  9. # Always run after devscripts/update-version.py, and run before `make doc|pypi-files|tar|all`
  10. if __name__ == '__main__':
  11. parser = create_parser()
  12. parser.description = 'Update an existing changelog file with an entry for a new release'
  13. parser.add_argument(
  14. '--changelog-path', type=Path, default=Path(__file__).parent.parent / 'Changelog.md',
  15. help='path to the Changelog file')
  16. args = parser.parse_args()
  17. new_entry = create_changelog(args)
  18. header, sep, changelog = read_file(args.changelog_path).partition('\n### ')
  19. write_file(args.changelog_path, f'{header}{sep}{read_version()}\n{new_entry}\n{sep}{changelog}')