Skip to content

Commit 0a07ad3

Browse files
committed
refactor: Remove project.dependencies mutation and clean up dead code
1 parent 24c505b commit 0a07ad3

File tree

1 file changed

+2
-32
lines changed

1 file changed

+2
-32
lines changed

src/mxdev/uv.py

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
logger = logging.getLogger("mxdev")
1111

1212

13-
def normalize_name(name: str) -> str:
14-
"""PEP 503 normalization: lowercased, runs of -, _, . become single -"""
15-
return re.sub(r"[-_.]+", "-", name).lower()
16-
17-
1813
class UvPyprojectUpdater(Hook):
1914
"""An mxdev hook that updates pyproject.toml during the write phase for uv-managed projects."""
2015

@@ -66,7 +61,7 @@ def write(self, state: State) -> None:
6661
except OSError as e:
6762
logger.error("[%s] Failed to write pyproject.toml: %s", self.namespace, e)
6863

69-
def _update_pyproject(self, doc: Any, state: State) -> None:
64+
def _update_pyproject(self, doc: "tomlkit.TOMLDocument", state: State) -> None:
7065
"""Modify the pyproject.toml document based on mxdev state."""
7166
import tomlkit
7267

@@ -106,34 +101,9 @@ def _update_pyproject(self, doc: Any, state: State) -> None:
106101
source_table = tomlkit.inline_table()
107102
source_table.append("path", rel_path)
108103

109-
if install_mode in ("editable", "direct"):
104+
if install_mode == "editable":
110105
source_table.append("editable", True)
111106
elif install_mode == "fixed":
112107
source_table.append("editable", False)
113108

114109
uv_sources[pkg_name] = source_table
115-
116-
# 2. Add packages to project.dependencies if not present
117-
if "project" not in doc:
118-
doc.add("project", tomlkit.table())
119-
120-
if "dependencies" not in doc["project"]:
121-
doc["project"]["dependencies"] = tomlkit.array()
122-
123-
dependencies = doc["project"]["dependencies"]
124-
pkg_name_pattern = re.compile(r"^([a-zA-Z0-9_\-\.]+)")
125-
existing_pkg_names = set()
126-
127-
for dep in dependencies:
128-
match = pkg_name_pattern.match(str(dep).strip())
129-
if match:
130-
existing_pkg_names.add(normalize_name(match.group(1)))
131-
132-
for pkg_name, pkg_data in state.configuration.packages.items():
133-
install_mode = pkg_data.get("install-mode", "editable")
134-
if install_mode == "skip":
135-
continue
136-
137-
normalized_name = normalize_name(pkg_name)
138-
if normalized_name not in existing_pkg_names:
139-
dependencies.append(pkg_name)

0 commit comments

Comments
 (0)