Skip to content

Conversation

@jensens
Copy link
Member

@jensens jensens commented Oct 22, 2025

Summary

Fixes #22 and #25: Constraints file path in requirements-out is now correctly calculated as a relative path from the requirements file's directory.

Problem

When and are in different directories, the generated requirements file referenced constraints with the wrong path, causing pip to fail.

Example from #22:

[settings]
requirements-out = requirements/plone.txt
constraints-out = requirements/constraints.txt

Before (broken):
requirements/plone.txt contained:

-c requirements/constraints.txt

Pip interprets -c paths relative to the requirements file's directory, so it looked for:

requirements/requirements/constraints.txt  ❌ Wrong!

After (fixed):
requirements/plone.txt now contains:

-c constraints.txt

Because both files are in requirements/, the relative path is just constraints.txt.

Solution

Added path calculation logic in src/mxdev/processing.py:

# Calculate relative path from requirements directory to constraints file
req_path = Path(cfg.out_requirements)
const_path = Path(cfg.out_constraints)
constraints_ref = os.path.relpath(const_path, req_path.parent)

This works for all scenarios:

  • Same directory: constraints.txt
  • Parent directory: ../constraints.txt
  • Subdirectory: subdir/constraints.txt
  • Different directories: ../other/constraints.txt
  • Different drives (Windows): Falls back to absolute path

Changes

  • processing.py: Calculate relative path using os.path.relpath()
  • test_processing.py: Added 2 tests for different directory scenarios
  • CHANGES.md: Documented the fix

Test Coverage

pytest tests/test_processing.py::test_relative_constraints_path_in_subdirectory -v
pytest tests/test_processing.py::test_relative_constraints_path_different_directories -v

Both tests demonstrate the bug and verify the fix.


cc @davisagli @gforcada

@jensens jensens marked this pull request as ready for review October 22, 2025 11:55
Tests demonstrate that constraints path in requirements-out should be relative
to the requirements file's directory, not from the config file location.
- 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
@jensens jensens force-pushed the fix/22-relative-constraints-path branch from c8bf5fe to 78df434 Compare October 22, 2025 14:08
During rebase, the Windows path fix (forward slash normalization) was lost.
This commit restores the .replace("\\", "/") calls that ensure pip can
correctly interpret constraint paths on all platforms.

Related to #22 and #25
Move 'import os' to top of processing.py file
for better code organization.
@jensens jensens merged commit 4c114f0 into main Oct 22, 2025
23 checks passed
@jensens jensens deleted the fix/22-relative-constraints-path branch October 22, 2025 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong path to constraints in requirements-out file

2 participants