Skip to content
Merged
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: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 4.1.2 (unreleased)

- Fix #53: Per-package target setting now correctly overrides default-target when constructing checkout paths.
[jensens]

- Fix #55: UnicodeEncodeError on Windows when logging emoji. The emoji is now conditionally displayed only when the console encoding supports it (UTF-8), avoiding errors on Windows cp1252 encoding.
[jensens]

Expand Down
4 changes: 4 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ myext-package_setting = value
- **Formatting**: Black-compatible (max line length: 120)
- **Import sorting**: isort with `force_alphabetical_sort = true`, `force_single_line = true`
- **Type hints**: Use throughout (Python 3.8+ compatible)
- **Path handling**: Prefer `pathlib.Path` over `os.path` for path operations
- Use `pathlib.Path().as_posix()` for cross-platform path comparison
- Use `/` operator for path joining: `Path("dir") / "file.txt"`
- Only use `os.path.join()` in production code where needed for compatibility
- **Logging**: Use `logger = logging.getLogger("mxdev")` from [logging.py](src/mxdev/logging.py)
- **Docstrings**: Document public APIs and complex logic

Expand Down
3 changes: 2 additions & 1 deletion src/mxdev/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def is_ns_member(name) -> bool:
package.setdefault("install-mode", mode)
package.setdefault("vcs", "git")
# XXX: path should not be necessary in WorkingCopies
package.setdefault("path", os.path.join(target, name))
# Use package["target"] not 'target' variable to respect per-package target setting (#53)
package.setdefault("path", os.path.join(package["target"], name))
if not package.get("url"):
raise ValueError(f"Section {name} has no URL set!")
if package.get("install-mode") not in ["direct", "skip"]:
Expand Down
14 changes: 14 additions & 0 deletions tests/data/config_samples/config_with_custom_target.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[settings]
default-target = ./sources
docs-directory = documentation

[package.with.default.target]
url = https://github.com/example/package1.git

[package.with.custom.target]
url = https://github.com/example/package2.git
target = custom-dir

[package.with.interpolated.target]
url = https://github.com/example/docs.git
target = ${settings:docs-directory}
43 changes: 43 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,46 @@ def test_configuration_package_defaults():
assert pkg["install-mode"] == "direct" # default mode
assert pkg["vcs"] == "git"
assert "path" in pkg


def test_per_package_target_override():
"""Test that per-package target setting overrides default-target.

This test demonstrates issue #53: the target setting for individual
packages should override the default-target setting.
"""
from mxdev.config import Configuration

base = pathlib.Path(__file__).parent / "data" / "config_samples"
config = Configuration(str(base / "config_with_custom_target.ini"))

# Package without custom target should use default-target
pkg_default = config.packages["package.with.default.target"]
assert pkg_default["target"] == "./sources"
# Normalize paths for comparison (handles both Unix / and Windows \)
assert (
pathlib.Path(pkg_default["path"]).as_posix()
== pathlib.Path(pkg_default["target"])
.joinpath("package.with.default.target")
.as_posix()
)

# Package with custom target should use its own target
pkg_custom = config.packages["package.with.custom.target"]
assert pkg_custom["target"] == "custom-dir"
assert (
pathlib.Path(pkg_custom["path"]).as_posix()
== pathlib.Path(pkg_custom["target"])
.joinpath("package.with.custom.target")
.as_posix()
)

# Package with interpolated target should use the interpolated value
pkg_interpolated = config.packages["package.with.interpolated.target"]
assert pkg_interpolated["target"] == "documentation"
assert (
pathlib.Path(pkg_interpolated["path"]).as_posix()
== pathlib.Path(pkg_interpolated["target"])
.joinpath("package.with.interpolated.target")
.as_posix()
)