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

Support Uv as a Python build-system #285

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changelog/_unreleased.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,21 @@ id = "e3dd07f8-7520-45b9-9407-9f650e4d333c"
type = "feature"
description = "Extend pytest task to accept a sequence of paths that contain test files."
author = "@sebimarkgraf"

[[entries]]
id = "eca4a4bb-fef4-4692-8799-402d874a5807"
type = "feature"
description = "Add Python build-system support for Uv (https://docs.astral.sh/uv/guides/projects/)"
author = "@NiklasRosenstein"

[[entries]]
id = "2d36cc17-ab77-476d-9187-9f509e51735d"
type = "fix"
description = "Use `fsdecode()` on result from `find_uv_bin()` for enhanced compatbility"
author = "@NiklasRosenstein"

[[entries]]
id = "6262db32-1e87-471b-b4fb-b99ef55eea56"
type = "fix"
description = "Fix `inject_url_credentials()` to not drop port"
author = "@NiklasRosenstein"
16 changes: 16 additions & 0 deletions examples/uv-project-consumer/.kraken.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os

from kraken.std import python

python.python_settings(always_use_managed_env=True).add_package_index(
alias="local",
index_url=os.environ["LOCAL_PACKAGE_INDEX"],
credentials=(os.environ["LOCAL_USER"], os.environ["LOCAL_PASSWORD"]),
)
python.install()
python.mypy(version_spec="==1.10.0")
python.flake8(version_spec="==7.0.0")
python.black(version_spec="==24.4.2")
python.isort(version_spec="==5.13.2")
python.pytest()
python.publish(package_index="local", distributions=python.build(as_version="0.1.0").output_files)
13 changes: 13 additions & 0 deletions examples/uv-project-consumer/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[project]
name = "uv-project-consumer"
version = "0.1.0"
description = "Add your description here"
requires-python = ">=3.10"
dependencies = [
"tqdm>=4.66.5",
"uv-project==0.1.0",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from uv_project import hello


def main() -> None:
hello()
34 changes: 34 additions & 0 deletions examples/uv-project-consumer/uv.lock

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

16 changes: 16 additions & 0 deletions examples/uv-project/.kraken.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os

from kraken.std import python

python.python_settings(always_use_managed_env=True).add_package_index(
alias="local",
index_url=os.environ["LOCAL_PACKAGE_INDEX"],
credentials=(os.environ["LOCAL_USER"], os.environ["LOCAL_PASSWORD"]),
)
python.install()
python.mypy(version_spec="==1.10.0")
python.flake8(version_spec="==7.0.0")
python.black(version_spec="==24.4.2")
python.isort(version_spec="==5.13.2")
python.pytest()
python.publish(package_index="local", distributions=python.build(as_version="0.1.0").output_files)
17 changes: 17 additions & 0 deletions examples/uv-project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[project]
name = "uv-project"
version = "0.1.0"
description = "Add your description here"
requires-python = ">=3.10"
dependencies = [
"tqdm>=4.66.5",
]

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

[tool.uv]
dev-dependencies = [
"types-tqdm>=4.66.0.20240417",
]
9 changes: 9 additions & 0 deletions examples/uv-project/src/uv_project/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from time import sleep

from tqdm import tqdm


def hello() -> None:
for _ in tqdm(range(10)):
print("Hello from uv-project!")
sleep(1)
51 changes: 51 additions & 0 deletions examples/uv-project/uv.lock

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

10 changes: 9 additions & 1 deletion kraken-build/src/kraken/std/python/buildsystem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,12 @@ def detect_build_system(project_directory: Path) -> PythonBuildSystem | None:

return PDMPythonBuildSystem(project_directory)

return None
if "[tool.uv]" not in pyproject_content:
logger.info(
"Got no hint as to the Python build system used in the project '%s', falling back to UV (experimental)",
project_directory,
)

from kraken.std.python.buildsystem.uv import UVPythonBuildSystem

return UVPythonBuildSystem(project_directory)
3 changes: 0 additions & 3 deletions kraken-build/src/kraken/std/python/buildsystem/pdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class PdmPyprojectHandler(PyprojectHandler):
Implements the PyprojectHandler interface for PDM projects.
"""

def __init__(self, pyproj: TomlFile) -> None:
super().__init__(pyproj)

# PyprojectHandler

def get_package_indexes(self) -> list[PackageIndex]:
Expand Down
1 change: 1 addition & 0 deletions kraken-build/src/kraken/std/python/buildsystem/slap.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def bump_version(self, version: str) -> Iterator[None]:
def build(self, output_directory: Path) -> list[Path]:
with tempfile.TemporaryDirectory() as tempdir:
command = ["slap", "publish", "--dry", "-b", tempdir]
logger.info("Running %s in '%s'", command, self.project_directory)
sp.check_call(command, cwd=self.project_directory)
src_files = list(Path(tempdir).iterdir())
dst_files = [output_directory / path.name for path in src_files]
Expand Down
Loading
Loading