ziggy-pydust icon indicating copy to clipboard operation
ziggy-pydust copied to clipboard

Support for uv projects

Open antisaling opened this issue 1 year ago • 9 comments

uv is a Rust-based project and package manager for Python. It is considerably simpler than poetry, which is why I personally prefer it, so I hope it would be easy to integrate with. I have done some experiments with both the default build system (hatchling) and using setuptools but haven't had any success accessing the library that should be exported by pydust.

I wonder if this has to do with the include statement, although I have noticed that the build script compiles to a .so, and I'm on an ARM64 Mac, so there might be an issue there too.

antisaling avatar Nov 27 '24 22:11 antisaling

I would think that this would "just work" now with Poetry 2.0 and its new support for standard configuration. If you update to PEP 621 style configuration and poetry-core 2.0 I think you can use uv.

henryiii avatar Jan 17 '25 23:01 henryiii

This seems to work, as applied to the template repo:

-[tool.poetry]
+[project]
 name = "ziggy-pydust-template"
 version = "0.1.0"
 description = ""
-authors = ["Fulcrum Inc. <[email protected]>"]
+authors = [{name = "Fulcrum Inc", email = "[email protected]"}]
 readme = "README.md"
+dependencies = []
+requires-python = ">=3.11"
+
+[tool.poetry]
 packages = [{ include = "fibonacci" }]
 include = [
     { path = "src/", format = "sdist" },
@@ -18,21 +22,26 @@ include = [
 [tool.poetry.build]
 script = "build.py"

-[tool.poetry.dependencies]
-python = "^3.11"
-
 [tool.poetry.group.dev.dependencies]
 ziggy-pydust = "0.23.2"
-pytest = "^8.0.0"
-ruff = "^0.4.0"
+pytest = ">=8.0.0"
+ruff = ">=0.4.0"
 black = "^23.7.0"

+[dependency-groups]
+dev = [
+    "ziggy-pydust==0.23.2",
+    "pytest>=8",
+    "ruff>=0.4.0",
+    "black~=23.7.0",
+]
+
 [tool.black]
 line-length = 120

 [tool.ruff]
 line-length = 120
-select = ["F", "E", "W", "UP", "I001", "I002"]
+lint.select = ["F", "E", "W", "UP", "I001", "I002"]

henryiii avatar Jan 21 '25 21:01 henryiii

(I'm assuming this warning is unrelated:

/Users/henryschreiner/.cache/uv/builds-v0/.tmpZsKYCP/lib/python3.12/site-packages/pydust/config.py:92: UserWarning: A custom validator is returning a value other than `self`.
Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.
See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.
  return ToolPydust(**pyproject["tool"].get("pydust", {}))

)

henryiii avatar Jan 21 '25 21:01 henryiii

I would like to use UV as well.

taylorh140 avatar May 21 '25 19:05 taylorh140

@henryiii is correct, it does "just work", though did take some extra fiddling because it seems the original template is on an old zig version.

Here's a fork I made of the template, updating it to more recent versions:

  • Zig 0.14
  • python 3.13.1
  • ziggy-pydust==0.25.1

It adds

  • UV and Hatch for build, instead of Poetry
  • Pytest for testing
  • Ruff for formatting, instead of Black

https://github.com/erik-dunteman/ziggy-pydust-template

Enjoy, hope this helps

erik-dunteman avatar Jun 04 '25 03:06 erik-dunteman

@erik-dunteman I took a look it seems to not work on windows but that's probably a high bar. I was looking at the comment about using pyenv vs brew. I usually just use uv to manage my python installs.

taylorh140 avatar Jun 10 '25 20:06 taylorh140

@taylorh140 oops, sorry for not making compatible. There's a long tail of stuff to make it a clean repo, though hopefully it's a functional starting point at least

For python installs, my uv-managed python also had issues, but there's a chance it resolved to my brew-installed version.

erik-dunteman avatar Jun 10 '25 20:06 erik-dunteman

Thanks @erik-dunteman for investigating. Ultimately it's a bit suspect that "pydust.build.zig" calls poetry env info --executable to detect python. Why would poetry be in the path if python isn't ?

For me it works while letting uv manage the Python installation instead of adding another package manager in the mix.

gwenzek avatar Jul 15 '25 07:07 gwenzek

It ultimately goes down to how the virtualenv is managed. IIRC it was easier get the information from poetry. Would be happy to take prs here to replace poetry since at the time there wasn't anything else

robert3005 avatar Jul 15 '25 10:07 robert3005