Skip to content
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

Fix access to relative import bump time #313

Merged
merged 12 commits into from
Jan 30, 2025
6 changes: 6 additions & 0 deletions .changelog/_unreleased.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ id = "a46ae7eb-bfd4-4a1c-b8b3-e6d2ebc5e3a9"
type = "fix"
description = "Maturin: set always the venv interpreter on all compilations - fixes Windows cross-compilations"
author = "[email protected]"

[[entries]]
id = "c1cdc569-9c2f-439a-b422-4690063c13d7"
type = "fix"
description = "Fix uv version bump"
author = "[email protected]"
10 changes: 10 additions & 0 deletions examples/uv-project-relative-import/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ dependencies = [
"uv-project",
]

[dependency-groups]
Ghelfi marked this conversation as resolved.
Show resolved Hide resolved
dev = [
"uv-project",
]

[project.optional-dependencies]
opt = [
"uv-project",
]

[tool.uv.sources]
uv-project = { path = "../uv-project", editable = true }

Expand Down
14 changes: 14 additions & 0 deletions examples/uv-project-relative-import/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions kraken-build/src/kraken/std/python/buildsystem/uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _get_dependencies(self) -> list[str]:
return self.raw.get("project", {}).get("dependencies", []) # type: ignore [no-any-return]

def _get_dependency_groups(self) -> dict[str, list[str]]:
return self.raw.get("project", {}).get("dependency-groups", {}) # type: ignore [no-any-return]
return self.raw.get("dependency-groups", {})

def _get_optional_dependencies(self) -> dict[str, list[str]]:
return self.raw.get("project", {}).get("optional-dependencies", {}) # type: ignore [no-any-return]
Expand All @@ -223,18 +223,21 @@ def set_path_dependencies_to_version(self, version: str) -> None:
dependencies = self._get_dependencies()
dependency_groups = self._get_dependency_groups()
optional_dependencies = self._get_optional_dependencies()
sources_to_rm: list[str] = []
sources_to_rm: set[str] = set()
for source, params in sources.items():
# TODO(Ghelfi): Check if entry with `path` is within the current project
if "workspace" in params or "path" in params:
sources_to_rm.append(source)
if (index := dependencies.index(source)) is not None:
sources_to_rm.add(source)
if source in dependencies:
index = dependencies.index(source)
dependencies[index] = f"{source}=={version}"
for key, deps in dependency_groups.items():
if (index := deps.index(source)) is not None:
if source in deps:
index = deps.index(source)
dependency_groups[key][index] = f"{source}=={version}"
for key, deps in optional_dependencies.items():
if (index := deps.index(source)) is not None:
if source in deps:
index = deps.index(source)
optional_dependencies[key][index] = f"{source}=={version}"

for elem in sources_to_rm:
Expand Down
39 changes: 39 additions & 0 deletions kraken-build/src/kraken/std/python/buildsystem/uv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@
"""


EXAMPLE_UV_PYPROJECT_RELATIVE_IMPORT = """
[project]
name = "uv-project"
version = "0.1.0"

dependencies = [
"tqdm>=4.66.5",
"uv-project-relative-import",
]

[dependency-groups]
dev = [
"uv-project-relative-import-dev",
]

[project.optional-dependencies]
opt = [
"uv-project-relative-import-opt",
]

[tool.uv.sources]
uv-project-relative-import = { path = "../uv-project-relative-import", editable = true }
uv-project-relative-import-dev = { path = "../uv-project-relative-import-dev", editable = true }
uv-project-relative-import-opt = { path = "../uv-project-relative-import-opt", editable = true }
"""


def test__UvIndexes__to_env() -> None:
indexes = UvIndexes.from_package_indexes(
[
Expand Down Expand Up @@ -151,3 +178,15 @@ def test__UvPyprojectHandler__update_packages() -> None:
{"url": "https://example.org/simple/"},
{"url": "https://example.com/bar/simple/", "name": "bar", "explicit": True},
]


def test__UvPyprojectHandler__set_path_dependencies_to_version() -> None:
handler = UvPyprojectHandler(TomlFile.read_string(EXAMPLE_UV_PYPROJECT_RELATIVE_IMPORT))
version_to_bump = "0.1.1"
handler.set_path_dependencies_to_version(version_to_bump)

assert f"uv-project-relative-import=={version_to_bump}" in handler.raw["project"]["dependencies"]
assert f"uv-project-relative-import-dev=={version_to_bump}" in handler.raw["dependency-groups"]["dev"]
assert (
f"uv-project-relative-import-opt=={version_to_bump}" in handler.raw["project"]["optional-dependencies"]["opt"]
)
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ def test__python_project__upgrade_relative_import_version(
# Check if generated files store proper version.
metadata_file = tar.extractfile(f"{formatted_project_name}-{build_as_version}/PKG-INFO")
assert metadata_file is not None, ".tar.gz file does not contain an 'PKG-INFO'"
assert f"Requires-Dist: uv-project=={build_as_version}" in metadata_file.read().decode("UTF-8")
metadata = metadata_file.read().decode("UTF-8")
assert f"Requires-Dist: uv-project=={build_as_version}" in metadata
assert f"Requires-Dist: uv-project=={build_as_version}; extra == 'opt'" in metadata


M = TypeVar("M", PdmPyprojectHandler, PoetryPyprojectHandler)
Expand Down
Loading