1+ #!/usr/bin/env python3
12# Copyright (c) Microsoft Corporation. All rights reserved.
23# Licensed under the Apache 2.0 License.
34
45import argparse
56import re
67import sys
78import subprocess
9+ import tomllib
810
911
1012def main ():
@@ -53,15 +55,11 @@ def main():
5355 release_notes = {}
5456 links_found = []
5557
56- # Check that pyproject.toml is up to date
57- # Once we have upgraded to Python 3.11, we can use tomllib to parse pyproject.toml
58- pyproject_version = None
59- with open ("python/pyproject.toml" ) as pyproject :
60- for line in pyproject :
61- if line .startswith ("version" ):
62- _ , version = line .split ("=" )
63- pyproject_version = version .strip ().strip ('"' )
64- assert pyproject_version is not None , "Could not find version in pyproject.toml"
58+ version_in_pyproject = None
59+ with open ("python/pyproject.toml" , "rb" ) as pyproject :
60+ config = tomllib .load (pyproject )
61+ version_in_pyproject = config .get ("project" , {}).get ("version" )
62+ assert version_in_pyproject is not None , "Could not find version in pyproject.toml"
6563
6664 # Parse file, bucketing lines into each version's release notes
6765 current_release_notes = None
@@ -72,8 +70,8 @@ def main():
7270 current_release_notes = []
7371 if not release_notes :
7472 assert (
75- log_version == pyproject_version
76- ), f"First version in CHANGELOG ({ log_version } ) must match version in pyproject.toml ({ pyproject_version } )"
73+ log_version == version_in_pyproject
74+ ), f"First version in CHANGELOG ({ log_version } ) must match version in pyproject.toml ({ version_in_pyproject } )"
7775 release_notes [log_version ] = current_release_notes
7876 elif match := link_definition .match (line ):
7977 link_version = match .group (1 )
0 commit comments