AnswerDotAI / AnswerDotAI/nbdev

_re_proj in update_proj replaces **all** `name` attributes in pyproject.toml

Open
#1,581 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Jupyter Notebook
Stars
5.3k
Forks
513
Avg merge
2d 30m
Merged PRs (30d)
8

Description

# 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:
```python
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`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.