1111BUILD_DIR = ROOT_DIR / "FracturedJson" / "FracturedJsonCli"
1212SRC_DIR = ROOT_DIR / "src" / "fractured_json"
1313TEST_DIR = ROOT_DIR / "tests" / "bin"
14- VERSION_FILE = SRC_DIR / "_version.py "
14+ PYPROJECT_FILE = ROOT_DIR / "pyproject.toml "
1515
1616
1717def build_binaries () -> None :
@@ -45,11 +45,29 @@ def parse_assets_json() -> tuple[Path, str]:
4545 return (BUILD_DIR / "bin" / "Release" / framework / "publish" , library_version )
4646
4747
48- def create_version_file (version : str ) -> None :
49- """Create _version.pywith latest FracturedJson version."""
50- with open (VERSION_FILE , "w" ) as f : # noqa: PTH123
51- print ('__version__ = "5.0.0"' , file = f )
52- print (f"✅ Created _version.py with version { version } " )
48+ def update_version (version : str ) -> None :
49+ """Update pyproject.toml if FracturedJson version is newer."""
50+ new_project_toml = ""
51+ patch_version = True
52+ for line in PYPROJECT_FILE .read_text ().splitlines ():
53+ if line .startswith ("version" ):
54+ # Expect: version = "5.0.0post5" / version = "5.0.1"
55+ toml_version = line .split ("=" )[1 ].strip ().replace ('"' , "" )
56+ patch_version = False
57+ if "post" in toml_version :
58+ toml_base_version = toml_version .split ("post" )[0 ]
59+ if toml_base_version != version :
60+ patch_version = True
61+ elif toml_version != version :
62+ patch_version = True
63+ if patch_version :
64+ line = f'version = "{ version } '
65+ new_project_toml += line + "\n "
66+ if patch_version :
67+ PYPROJECT_FILE .write_text (new_project_toml )
68+ print (f"⚠️ Updated pyproject.toml with version { version } " )
69+ else :
70+ print (f"✅ pyproject.toml version { toml_version } matches version { version } " )
5371
5472
5573def copy_binary (bin_dir : Path , file : str , target_dir : Path ) -> None :
@@ -63,7 +81,7 @@ def main() -> None:
6381 build_binaries ()
6482
6583 bin_dir , version = parse_assets_json ()
66- create_version_file (version )
84+ update_version (version )
6785 copy_binary (bin_dir , "FracturedJson.dll" , SRC_DIR )
6886 copy_binary (bin_dir , "Mono.Options.dll" , TEST_DIR )
6987 copy_binary (bin_dir , "FracturedJson.dll" , TEST_DIR )
0 commit comments