Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## 5.4.0 (unreleased)

<!-- Add future changes here -->
- Test: Add test to ensure that sections starting with `__uv__` are ignored in `pyproject.toml`. [erral]
- Fix: Updated `uv` hook tests to match the current `__uv__` namespace. [erral]


## 5.3.0 (2026-05-29)
Expand Down
2 changes: 1 addition & 1 deletion src/mxdev/uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class UvPyprojectUpdater(Hook):
"""An mxdev hook that updates pyproject.toml during the write phase for uv-managed projects."""

namespace = "uv"
namespace = "__uv__"

def read(self, state: State) -> None:
pass
Expand Down
53 changes: 46 additions & 7 deletions tests/test_uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_hook_skips_when_pyproject_toml_missing(mocker, tmp_path, monkeypatch):
state = State(config)
mock_logger = mocker.patch("mxdev.uv.logger")
hook.write(state)
mock_logger.debug.assert_called_with("[%s] pyproject.toml not found, skipping.", "uv")
mock_logger.debug.assert_called_with("[%s] pyproject.toml not found, skipping.", "__uv__")


def test_hook_skips_when_uv_managed_is_false_or_missing(mocker, tmp_path, monkeypatch):
Expand All @@ -39,7 +39,7 @@ def test_hook_skips_when_uv_managed_is_false_or_missing(mocker, tmp_path, monkey
hook.write(state)
mock_logger.debug.assert_called_with(
"[%s] Project not explicitly managed by uv ([tool.uv] managed=true missing), skipping.",
"uv",
"__uv__",
)

# Verify the file was not modified
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_hook_skips_when_uv_managed_is_false(mocker, tmp_path, monkeypatch):
hook.write(state)
mock_logger.debug.assert_called_with(
"[%s] Project not explicitly managed by uv ([tool.uv] managed=true missing), skipping.",
"uv",
"__uv__",
)

# Verify the file was not modified
Expand Down Expand Up @@ -105,8 +105,8 @@ def test_hook_executes_when_uv_managed_is_true(mocker, tmp_path, monkeypatch):

mock_logger = mocker.patch("mxdev.uv.logger")
hook.write(state)
mock_logger.info.assert_any_call("[%s] Updating pyproject.toml...", "uv")
mock_logger.info.assert_any_call("[%s] Successfully updated pyproject.toml", "uv")
mock_logger.info.assert_any_call("[%s] Updating pyproject.toml...", "__uv__")
mock_logger.info.assert_any_call("[%s] Successfully updated pyproject.toml", "__uv__")

# Verify the file was actually written correctly
doc = tomlkit.parse((tmp_path / "pyproject.toml").read_text())
Expand Down Expand Up @@ -375,7 +375,7 @@ def test_hook_handles_oserror_on_read(mocker, tmp_path, monkeypatch):

hook.write(state)

mock_logger.error.assert_called_with("[%s] Failed to read pyproject.toml: %s", "uv", mocker.ANY)
mock_logger.error.assert_called_with("[%s] Failed to read pyproject.toml: %s", "__uv__", mocker.ANY)


def test_hook_handles_oserror_on_write(mocker, tmp_path, monkeypatch):
Expand All @@ -400,7 +400,7 @@ def test_hook_handles_oserror_on_write(mocker, tmp_path, monkeypatch):

hook.write(state)

mock_logger.error.assert_called_with("[%s] Failed to write pyproject.toml: %s", "uv", mocker.ANY)
mock_logger.error.assert_called_with("[%s] Failed to write pyproject.toml: %s", "__uv__", mocker.ANY)

# Ensure no .tmp files are left behind
assert len(list(tmp_path.glob("*.tmp"))) == 0
Expand Down Expand Up @@ -459,3 +459,42 @@ def fake_import(name, *args, **kw):

# Should not raise any error, even though tomlkit import is mocked to fail
hook.write(state)


def test_uv_namespace_sections_are_ignored_in_pyproject(tmp_path, monkeypatch):
# Test that sections starting with __uv__ are ignored in pyproject.toml
monkeypatch.chdir(tmp_path)
hook = UvPyprojectUpdater()

mx_ini = """
[settings]
[pkg1]
url = https://example.com/pkg1.git
target = sources
install-mode = editable

[__uv__.whatever]
some-hook-setting = value
"""
(tmp_path / "mx.ini").write_text(mx_ini.strip())
# We need to pass the hook to Configuration so it knows about the namespace
config = Configuration("mx.ini", hooks=[hook])
state = State(config)

initial_toml = """
[project]
name = "test"
dependencies = []

[tool.uv]
managed = true
"""
(tmp_path / "pyproject.toml").write_text(initial_toml.strip())

hook.write(state)

doc = tomlkit.parse((tmp_path / "pyproject.toml").read_text())
sources = doc["tool"]["uv"]["sources"]
assert "pkg1" in sources
assert "__uv__.whatever" not in sources
assert "whatever" not in sources
Loading