-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented first version of uv executor
- Loading branch information
Showing
7 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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,6 +1,13 @@ | ||
from .base import PoeExecutor | ||
from .poetry import PoetryExecutor | ||
from .simple import SimpleExecutor | ||
from .uv import UvExecutor | ||
from .virtualenv import VirtualenvExecutor | ||
|
||
__all__ = ["PoeExecutor", "PoetryExecutor", "SimpleExecutor", "VirtualenvExecutor"] | ||
__all__ = [ | ||
"PoeExecutor", | ||
"PoetryExecutor", | ||
"SimpleExecutor", | ||
"UvExecutor", | ||
"VirtualenvExecutor", | ||
] |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from collections.abc import Sequence | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING, Optional | ||
|
||
from .base import PoeExecutor | ||
|
||
if TYPE_CHECKING: | ||
from ..context import RunContext | ||
|
||
|
||
class UvExecutor(PoeExecutor): | ||
""" | ||
A poe task executor implementation that executes inside a uv managed dev | ||
environment | ||
""" | ||
|
||
__key__ = "uv" | ||
__options__: dict[str, type] = {} | ||
|
||
@classmethod | ||
def works_with_context(cls, context: "RunContext") -> bool: | ||
if not context.config.is_uv_project: | ||
return False | ||
return bool(cls._uv_cmd_from_path()) | ||
|
||
def execute( | ||
self, cmd: Sequence[str], input: Optional[bytes] = None, use_exec: bool = False | ||
) -> int: | ||
""" | ||
Execute the given cmd as a subprocess inside the uv managed dev environment. | ||
We simply use `uv run`, which handles the virtualenv and other setup for us. | ||
""" | ||
|
||
# Run this task with `uv run` | ||
return self._execute_cmd( | ||
(self._uv_cmd(), "run", *cmd), | ||
input=input, | ||
use_exec=use_exec, | ||
) | ||
|
||
@classmethod | ||
def _uv_cmd(cls): | ||
from_path = cls._uv_cmd_from_path() | ||
if from_path: | ||
return str(Path(from_path).resolve()) | ||
|
||
return "uv" | ||
|
||
@classmethod | ||
def _uv_cmd_from_path(cls): | ||
import shutil | ||
|
||
return shutil.which("uv") |
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[project] | ||
name = "uv-project" | ||
version = "0.1.0" | ||
description = "Add your description here" | ||
readme = "README.md" | ||
requires-python = ">=3.12" | ||
dependencies = [] | ||
|
||
[tool.uv] | ||
# We need to have an empty table here to ensure that the tool is recognized | ||
|
||
[tool.poe.tasks] | ||
show-version = "test_print_version" | ||
test-package-version.script = "scripts:test_package_version" | ||
test-package-exec-version.script = "scripts:test_package_exec_version" | ||
show-env = "poe_test_env" | ||
|
||
|
||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" |
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
def test_package_version(): | ||
import poe_test_package | ||
|
||
print(poe_test_package.__version__) | ||
|
||
|
||
def test_package_exec_version(): | ||
from subprocess import Popen | ||
|
||
Popen(["test_print_version"]) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def hello() -> str: | ||
return "Hello from uv-project!" |