-
Notifications
You must be signed in to change notification settings - Fork 361
Fix Python SDK package version #985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,50 @@ | ||
| __version__ = "0.1.0" | ||
| """Package version. | ||
|
|
||
| The version is single-sourced from ``pyproject.toml``'s ``[project] version``, | ||
| which the release pipeline stamps from ``version-info/pyVersion.txt``. Nothing | ||
| here needs updating on a version bump. | ||
|
|
||
| For an installed wheel we read the metadata recorded at build time. When running | ||
| straight from a source checkout (no dist-info, e.g. ``PYTHONPATH=src``) we fall | ||
| back to parsing ``pyproject.toml`` so the reported version still matches the | ||
| build inputs instead of a stale hardcoded literal. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from importlib.metadata import PackageNotFoundError, version as _dist_version | ||
| from pathlib import Path | ||
|
|
||
| _DISTRIBUTION_NAME = "foundry-local-sdk" | ||
| _UNKNOWN = "0.0.0.dev0" | ||
|
|
||
|
|
||
| def _version_from_pyproject() -> str | None: | ||
| # src/foundry_local_sdk/version.py -> sdk_v2/python/pyproject.toml | ||
| pyproject = Path(__file__).resolve().parents[2] / "pyproject.toml" | ||
| if not pyproject.is_file(): | ||
| return None | ||
|
|
||
| try: | ||
| import tomllib | ||
| except ModuleNotFoundError: # pragma: no cover - tomllib is stdlib on 3.11+ | ||
| return None | ||
|
|
||
| try: | ||
| with pyproject.open("rb") as fh: | ||
| data = tomllib.load(fh) | ||
| except (OSError, ValueError): | ||
| return None | ||
|
|
||
| found = data.get("project", {}).get("version") | ||
| return found if isinstance(found, str) and found else None | ||
|
|
||
|
|
||
| def _resolve_version() -> str: | ||
| try: | ||
| return _dist_version(_DISTRIBUTION_NAME) | ||
| except PackageNotFoundError: | ||
| return _version_from_pyproject() or _UNKNOWN | ||
|
bmehta001 marked this conversation as resolved.
|
||
|
|
||
|
|
||
| __version__ = _resolve_version() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.