Skip to content

Commit

Permalink
Merge pull request #131 from betaboon/fix-uv-pep735
Browse files Browse the repository at this point in the history
fix(uv): lockfile translation of pep735 dependency groups with uv 0.4.27
  • Loading branch information
betaboon authored Dec 10, 2024
2 parents 5e968ab + 5954e15 commit 06bacc3
Show file tree
Hide file tree
Showing 9 changed files with 1,440 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pycross/private/tools/uv_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ def get_optional_dependencies(lock: Dict[str, Any]) -> Dict[str, List[Requiremen


def get_development_dependencies(lock: Dict[str, Any]) -> Dict[str, List[Requirement]]:
dep_groups = lock.get("tool", {}).get("uv", {}).get("dev-dependencies", {})
dep_groups = lock.get("dependency-groups", {})
# backwards-compatiblity for https://github.com/astral-sh/uv/pull/8272
# see: https://docs.astral.sh/uv/concepts/projects/dependencies/#legacy-dev-dependencies
legacy_dev_deps = lock.get("tool", {}).get("uv", {}).get("dev-dependencies", [])
if legacy_dev_deps:
dev_deps = dep_groups.get("dev", []) + legacy_dev_deps
dep_groups["dev"] = list(set(dev_deps))

return {group: [Requirement(EDITABLE_PATTERN.sub("", dep)) for dep in deps] for group, deps in dep_groups.items()}


Expand Down
33 changes: 33 additions & 0 deletions pycross/tests/uv/lock_0_4_27_legacy_dev_dependencies/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
uv has introduced backwards compatible support for pep735.
This change was introduced in the following PR:
https://github.com/astral-sh/uv/pull/8272
This PR was contained in the following release:
https://github.com/astral-sh/uv/releases/tag/0.4.27
"""

load("@aspect_bazel_lib//lib:testing.bzl", "assert_json_matches")
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_file")
load("//pycross:defs.bzl", "pycross_uv_lock_model")

pycross_uv_lock_model(
name = "lock",
all_development_groups = True,
lock_file = "uv.lock",
project_file = "pyproject.toml",
)

write_source_file(
name = "update_expected",
diff_test = False,
in_file = ":lock",
out_file = "expected.json",
)

assert_json_matches(
name = "test",
file1 = ":lock",
file2 = "expected.json",
)
581 changes: 581 additions & 0 deletions pycross/tests/uv/lock_0_4_27_legacy_dev_dependencies/expected.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[project]
name = "rules-pycross-test"
version = "0.1.0"
description = ""
requires-python = ">=3.9, <3.13"
dependencies = []

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
dev-dependencies = [
"regex>=2024.11.6",
]
87 changes: 87 additions & 0 deletions pycross/tests/uv/lock_0_4_27_legacy_dev_dependencies/uv.lock

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions pycross/tests/uv/lock_0_4_27_pep735/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
uv has introduced backwards compatible support for pep735.
This change was introduced in the following PR:
https://github.com/astral-sh/uv/pull/8272
This PR was contained in the following release:
https://github.com/astral-sh/uv/releases/tag/0.4.27
"""

load("@aspect_bazel_lib//lib:testing.bzl", "assert_json_matches")
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_file")
load("//pycross:defs.bzl", "pycross_uv_lock_model")

pycross_uv_lock_model(
name = "lock",
all_development_groups = True,
lock_file = "uv.lock",
project_file = "pyproject.toml",
)

write_source_file(
name = "update_expected",
diff_test = False,
in_file = ":lock",
out_file = "expected.json",
)

assert_json_matches(
name = "test",
file1 = ":lock",
file2 = "expected.json",
)
581 changes: 581 additions & 0 deletions pycross/tests/uv/lock_0_4_27_pep735/expected.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions pycross/tests/uv/lock_0_4_27_pep735/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[project]
name = "rules-pycross-test"
version = "0.1.0"
description = ""
requires-python = ">=3.9, <3.13"
dependencies = []

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[dependency-groups]
dev = [
"regex>=2024.11.6",
]
87 changes: 87 additions & 0 deletions pycross/tests/uv/lock_0_4_27_pep735/uv.lock

Large diffs are not rendered by default.

0 comments on commit 06bacc3

Please sign in to comment.