Resolve custom component version dynamically

If the custom component is using setuptools_scm or some other dynamic
versioning scheme, use `build.util` to get the actual version being published.
This commit is contained in:
Masen Furer 2025-02-05 13:16:09 -08:00
parent 19f40745f8
commit f98f2b36f2
No known key found for this signature in database
GPG Key ID: B0008AD22B3B3A95

View File

@ -14,7 +14,7 @@ from typing import Optional, Tuple
import httpx import httpx
import tomlkit import tomlkit
import typer import typer
from tomlkit.exceptions import TOMLKitError from tomlkit.exceptions import NonExistentKey, TOMLKitError
from reflex import constants from reflex import constants
from reflex.config import environment, get_config from reflex.config import environment, get_config
@ -533,7 +533,13 @@ def _get_version_to_publish() -> str:
Returns: Returns:
The version to publish. The version to publish.
""" """
return _get_package_config()["project"]["version"] try:
return _get_package_config()["project"]["version"]
except NonExistentKey:
# Try to get the version from dynamic sources
import build.util
return build.util.project_wheel_metadata(".", isolated=True)["version"]
def _ensure_dist_dir(version_to_publish: str, build: bool): def _ensure_dist_dir(version_to_publish: str, build: bool):
@ -756,7 +762,7 @@ def _min_validate_project_info():
) )
raise typer.Exit(code=1) raise typer.Exit(code=1)
if not project.get("version"): if not project.get("version") and "version" not in project.get("dynamic", []):
console.error( console.error(
f"The project version is not found in {CustomComponents.PYPROJECT_TOML}" f"The project version is not found in {CustomComponents.PYPROJECT_TOML}"
) )
@ -772,7 +778,7 @@ def _validate_project_info():
pyproject_toml = _get_package_config() pyproject_toml = _get_package_config()
project = pyproject_toml["project"] project = pyproject_toml["project"]
console.print( console.print(
f"Double check the information before publishing: {project['name']} version {project['version']}" f"Double check the information before publishing: {project['name']} version {_get_version_to_publish()}"
) )
console.print("Update or enter to keep the current information.") console.print("Update or enter to keep the current information.")