Skip to content

Commit c9ba1ae

Browse files
authored
Merge pull request #57 from mxstack/fix/53-per-package-target-setting
Fix per-package target setting not being used
2 parents 50afd6a + 5800927 commit c9ba1ae

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 4.1.2 (unreleased)
44

5+
- Fix #53: Per-package target setting now correctly overrides default-target when constructing checkout paths.
6+
[jensens]
7+
58
- 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.
69
[jensens]
710

CLAUDE.md

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

src/mxdev/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def is_ns_member(name) -> bool:
100100
package.setdefault("install-mode", mode)
101101
package.setdefault("vcs", "git")
102102
# XXX: path should not be necessary in WorkingCopies
103-
package.setdefault("path", os.path.join(target, name))
103+
# Use package["target"] not 'target' variable to respect per-package target setting (#53)
104+
package.setdefault("path", os.path.join(package["target"], name))
104105
if not package.get("url"):
105106
raise ValueError(f"Section {name} has no URL set!")
106107
if package.get("install-mode") not in ["direct", "skip"]:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[settings]
2+
default-target = ./sources
3+
docs-directory = documentation
4+
5+
[package.with.default.target]
6+
url = https://github.com/example/package1.git
7+
8+
[package.with.custom.target]
9+
url = https://github.com/example/package2.git
10+
target = custom-dir
11+
12+
[package.with.interpolated.target]
13+
url = https://github.com/example/docs.git
14+
target = ${settings:docs-directory}

tests/test_config.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,46 @@ def test_configuration_package_defaults():
185185
assert pkg["install-mode"] == "direct" # default mode
186186
assert pkg["vcs"] == "git"
187187
assert "path" in pkg
188+
189+
190+
def test_per_package_target_override():
191+
"""Test that per-package target setting overrides default-target.
192+
193+
This test demonstrates issue #53: the target setting for individual
194+
packages should override the default-target setting.
195+
"""
196+
from mxdev.config import Configuration
197+
198+
base = pathlib.Path(__file__).parent / "data" / "config_samples"
199+
config = Configuration(str(base / "config_with_custom_target.ini"))
200+
201+
# Package without custom target should use default-target
202+
pkg_default = config.packages["package.with.default.target"]
203+
assert pkg_default["target"] == "./sources"
204+
# Normalize paths for comparison (handles both Unix / and Windows \)
205+
assert (
206+
pathlib.Path(pkg_default["path"]).as_posix()
207+
== pathlib.Path(pkg_default["target"])
208+
.joinpath("package.with.default.target")
209+
.as_posix()
210+
)
211+
212+
# Package with custom target should use its own target
213+
pkg_custom = config.packages["package.with.custom.target"]
214+
assert pkg_custom["target"] == "custom-dir"
215+
assert (
216+
pathlib.Path(pkg_custom["path"]).as_posix()
217+
== pathlib.Path(pkg_custom["target"])
218+
.joinpath("package.with.custom.target")
219+
.as_posix()
220+
)
221+
222+
# Package with interpolated target should use the interpolated value
223+
pkg_interpolated = config.packages["package.with.interpolated.target"]
224+
assert pkg_interpolated["target"] == "documentation"
225+
assert (
226+
pathlib.Path(pkg_interpolated["path"]).as_posix()
227+
== pathlib.Path(pkg_interpolated["target"])
228+
.joinpath("package.with.interpolated.target")
229+
.as_posix()
230+
)

0 commit comments

Comments
 (0)