Skip to content

Commit d6ffab8

Browse files
Invalidate cache based on CWD and uv integration
1 parent 1556649 commit d6ffab8

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/usethis/_integrations/pyproject/core.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def set_config_value(
7575
parent[id_keys[-1]] = value
7676

7777
write_pyproject_toml(pyproject)
78-
read_pyproject_toml.cache_clear()
7978

8079

8180
def remove_config_value(id_keys: list[str], *, missing_ok: bool = False) -> None:

src/usethis/_integrations/pyproject/io.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
)
1212

1313

14-
@cache
1514
def read_pyproject_toml() -> tomlkit.TOMLDocument:
15+
return read_pyproject_toml_from_path(Path.cwd() / "pyproject.toml")
16+
17+
18+
@cache
19+
def read_pyproject_toml_from_path(path: Path) -> tomlkit.TOMLDocument:
1620
try:
17-
return tomlkit.parse((Path.cwd() / "pyproject.toml").read_text())
21+
return tomlkit.parse(path.read_text())
1822
except FileNotFoundError:
1923
msg = "'pyproject.toml' not found in the current directory."
2024
raise PyProjectTOMLNotFoundError(msg)
@@ -35,5 +39,5 @@ def read_pyproject_dict() -> dict[str, Any]:
3539

3640

3741
def write_pyproject_toml(toml_document: tomlkit.TOMLDocument) -> None:
38-
read_pyproject_toml.cache_clear()
42+
read_pyproject_toml_from_path.cache_clear()
3943
(Path.cwd() / "pyproject.toml").write_text(tomlkit.dumps(toml_document))

src/usethis/_integrations/uv/call.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from usethis._integrations.pyproject.io import read_pyproject_toml_from_path
12
from usethis._integrations.uv.errors import UVSubprocessFailedError
23
from usethis._subprocess import SubprocessFailedError, call_subprocess
34

@@ -8,6 +9,7 @@ def call_uv_subprocess(args: list[str]) -> str:
89
Raises:
910
UVSubprocessFailedError: If the subprocess fails.
1011
"""
12+
read_pyproject_toml_from_path.cache_clear()
1113
try:
1214
return call_subprocess(["uv", *args])
1315
except SubprocessFailedError as err:

0 commit comments

Comments
 (0)