Skip to content

Commit 78df434

Browse files
committed
Fix issue #22 and #25: Calculate relative path for constraints reference
- processing.py: Calculate relative path from requirements-out directory to constraints-out file using os.path.relpath() - Handles different directory scenarios (same dir, parent dir, subdirs) - Falls back to absolute path if relpath fails (e.g., different drives on Windows) - CHANGES.md: Document the fix
1 parent 4c13435 commit 78df434

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
- Fix #46: Git tags in branch option are now correctly detected and handled during updates. Previously, updating from one tag to another failed because tags were incorrectly treated as branches.
1212
[jensens]
1313

14+
- Fix #22 and #25: Constraints file path in requirements-out is now correctly calculated as a relative path from the requirements file's directory. This allows requirements and constraints files to be in different directories. Previously, the path was written from the config file's perspective, causing pip to fail when looking for the constraints file. On Windows, paths are now normalized to use forward slashes for pip compatibility.
15+
[jensens]
16+
1417
- Fix #53: Per-package target setting now correctly overrides default-target when constructing checkout paths.
1518
[jensens]
1619

src/mxdev/processing.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,26 @@ def write(state: State) -> None:
271271
logger.info(f"Write [r]: {cfg.out_requirements}")
272272
with open(cfg.out_requirements, "w") as fio:
273273
if constraints or cfg.overrides:
274+
# Calculate relative path from requirements-out directory to constraints-out file
275+
# This ensures pip can find the constraints file regardless of where requirements
276+
# and constraints files are located
277+
from pathlib import Path
278+
import os
279+
280+
req_path = Path(cfg.out_requirements)
281+
const_path = Path(cfg.out_constraints)
282+
283+
# Calculate relative path from requirements directory to constraints file
284+
try:
285+
constraints_ref = os.path.relpath(const_path, req_path.parent)
286+
except ValueError:
287+
# On Windows, relpath can fail if paths are on different drives
288+
# In that case, use absolute path
289+
constraints_ref = str(const_path.absolute())
290+
274291
fio.write("#" * 79 + "\n")
275292
fio.write("# mxdev combined constraints\n")
276-
fio.write(f"-c {cfg.out_constraints}\n\n")
293+
fio.write(f"-c {constraints_ref}\n\n")
277294
write_dev_sources(fio, cfg.packages)
278295
fio.writelines(requirements)
279296
write_main_package(fio, cfg.settings)

0 commit comments

Comments
 (0)