Skip to content

Commit c5071cd

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 d8c9203 commit c5071cd

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
@@ -2,6 +2,9 @@
22

33
## 4.1.2 (unreleased)
44

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

src/mxdev/processing.py

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

0 commit comments

Comments
 (0)