Skip to content

_re_proj in update_proj replaces **all** name attributes in pyproject.toml #1581

@JonasJakubassa

Description

@JonasJakubassa

Description

The attribute name can occur not only in the project section of a pyproject.toml. Using nbdev-export will result in the command replacing the other name attributes with the project name. In our case, this occurred because we specified an alternative package index for PyTorch, as shown in the example below.

Provide a minimally reproducible example

main.py with:

from nbdev.config import update_proj 
from pathlib import Path
import tempfile
from fastcore.utils import *

pyproj_tmpl = """[build-system]
requires = ["setuptools>=64.0"]
build-backend = "setuptools.build_meta"

[project]
name = "FILL_IN"
requires-python="FILL_IN"
dynamic = [ "keywords", "description", "version", "dependencies", "optional-dependencies", "readme",
    "license", "authors", "classifiers", "entry-points", "scripts", "urls"]

[tool.uv]
cache-keys = [{ file = "pyproject.toml" }, { file = "setup.py" }]

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

with tempfile.TemporaryDirectory() as d:
    d = Path(d)
    cfg_text = (pyproj_tmpl.replace('name = "FILL_IN"', 'name = "testpkg"').replace('requires-python="FILL_IN"', 'requires-python=">=3.10"'))
    cfg_text += '\n[tool.nbdev]\n'
    (d/'pyproject.toml').write_text(cfg_text)
    (d/'testpkg').mkdir()

    with working_directory(d):
        update_proj(d)

    result = (d/'pyproject.toml').read_text()
    assert 'name = "testpkg"' in result
    assert 'name = "pytorch-cpu"' in result, "update_proj incorrectly modified the uv index name!"

Run with uv run --with nbdev,fastcore main.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions