nbdev icon indicating copy to clipboard operation
nbdev copied to clipboard

nbdev_export modifies irrelevant items in pyproject.toml

Open ifsheldon opened this issue 10 months ago • 1 comments

Provide a minimally reproducible example

You can clone my repo and initialize the environment with uv sync. The code in the repo is not relevant, but I'm sure that you can reproduce this issue in 5mins.

From line 43 - line 51 in my pyproject.toml, I setup sources of torch for uv to resolve.

[[tool.uv.index]]
name="torch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true

[[tool.uv.index]]
name="torch-gpu"
url = "https://download.pytorch.org/whl/cu128"
explicit = true

https://github.com/ifsheldon/tensor-network-notes/blob/b675c068899e29c0c5324e7e7557ed41a1e9216a/pyproject.toml#L43

When I run uv run nbdev_export, nbdev_export keeps overwriting the name fields to the project name, which is really annoying, like below

[[tool.uv.index]]
name="tensor-network-code" # my project name
url = "https://download.pytorch.org/whl/cpu"
explicit = true

[[tool.uv.index]]
name="tensor-network-code" # my project name
url = "https://download.pytorch.org/whl/cu128"
explicit = true

Did you just do the plain string replacement when processing pyproject.toml instead of parsing it correctly?

ifsheldon avatar May 10 '25 14:05 ifsheldon

I think this is the cause

https://github.com/AnswerDotAI/nbdev/blob/ea0800cb1f4a7c5a847e840cf18bfecba95fd707/nbdev/config.py#L262

ifsheldon avatar May 10 '25 14:05 ifsheldon

Disable update_pyproject in settings.ini to manage the file yourself.

jph00 avatar Jul 02 '25 18:07 jph00

(A better fix of course would be to handle the toml properly, rather than with a regex - PRs welcome if anyone wants to look at that.)

jph00 avatar Jul 02 '25 18:07 jph00