Skip to content

Commit ead2796

Browse files
committed
Resolve custom component version dynamically (#4759)
If the custom component is using setuptools_scm or some other dynamic versioning scheme, use `build.util` to get the actual version being published.
1 parent 6c4597a commit ead2796

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

reflex/custom_components/custom_components.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import httpx
1515
import tomlkit
1616
import typer
17-
from tomlkit.exceptions import TOMLKitError
17+
from tomlkit.exceptions import NonExistentKey, TOMLKitError
1818

1919
from reflex import constants
2020
from reflex.config import environment, get_config
@@ -533,7 +533,13 @@ def _get_version_to_publish() -> str:
533533
Returns:
534534
The version to publish.
535535
"""
536-
return _get_package_config()["project"]["version"]
536+
try:
537+
return _get_package_config()["project"]["version"]
538+
except NonExistentKey:
539+
# Try to get the version from dynamic sources
540+
import build.util
541+
542+
return build.util.project_wheel_metadata(".", isolated=True)["version"]
537543

538544

539545
def _ensure_dist_dir(version_to_publish: str, build: bool):
@@ -756,7 +762,7 @@ def _min_validate_project_info():
756762
)
757763
raise typer.Exit(code=1)
758764

759-
if not project.get("version"):
765+
if not project.get("version") and "version" not in project.get("dynamic", []):
760766
console.error(
761767
f"The project version is not found in {CustomComponents.PYPROJECT_TOML}"
762768
)
@@ -772,7 +778,7 @@ def _validate_project_info():
772778
pyproject_toml = _get_package_config()
773779
project = pyproject_toml["project"]
774780
console.print(
775-
f"Double check the information before publishing: {project['name']} version {project['version']}"
781+
f"Double check the information before publishing: {project['name']} version {_get_version_to_publish()}"
776782
)
777783

778784
console.print("Update or enter to keep the current information.")

0 commit comments

Comments
 (0)