Skip to content

fix: relative path destination local mode#47

Merged
NicoleMGomes merged 2 commits intomainfrom
bugfix/local-destination-virtual-env
Apr 13, 2026
Merged

fix: relative path destination local mode#47
NicoleMGomes merged 2 commits intomainfrom
bugfix/local-destination-virtual-env

Conversation

@NicoleMGomes
Copy link
Copy Markdown
Contributor

@NicoleMGomes NicoleMGomes commented Apr 13, 2026

Description

LocalDevClientBase.__init__ and the _mock_file() helper in destination/__init__.py resolved the mocks/ directory by navigating three levels up from __file__:

repo_root = os.path.abspath(
    os.path.join(os.path.dirname(__file__), "..", "..", "..")
)

This works in a source checkout (src/sap_cloud_sdk/destination/ → three levels up → project root), but when the package is installed into a virtual environment it lands at .venv/lib/python3.x/site-packages/sap_cloud_sdk/destination/, making three levels up resolve to .venv/lib/python3.x/ instead of the project root. As a result get_instance_destination() silently returns None.

Both locations now use os.getcwd(), which always resolves to the directory the application is launched from, regardless of install location:

self._file_path = os.path.join(os.getcwd(), "mocks", self.file_name)

Unit test fixtures that previously patched os.path.abspath were updated to patch os.getcwd instead.

Related Issue

Closes #46

Type of Change

Please check the relevant option:

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Dependency update

How to Test

  1. Create a project that uses sap_cloud_sdk installed from a virtual environment (not a source checkout).
  2. Add mocks/destination.json at the project root with at least one destination entry.
  3. Run:
    from sap_cloud_sdk.destination import create_client
    client = create_client(instance="destination-service")
    print(client._file_path)   # should print <project-root>/mocks/destination.json
    dest = client.get_instance_destination("my-destination")
    print(dest)                # should print the destination object, not None
  4. Confirm _file_path points to the project root and get_instance_destination() returns the expected destination.

Alternatively, run the unit test suite:

uv run pytest tests/destination/unit/ -v

Checklist

Before submitting your PR, please review and check the following:

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have updated documentation (if applicable)
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

Breaking Changes

None. The fix only affects the path resolution for local development mock files. Any project that already placed mocks/destination.json at the project root and ran the application from that root will see identical behaviour.

Additional Notes

The same __file__-based pattern was present in two places — _local_client_base.py and the _mock_file() helper in destination/__init__.py — both are fixed.

@NicoleMGomes NicoleMGomes marked this pull request as ready for review April 13, 2026 18:36
@NicoleMGomes NicoleMGomes requested a review from a team as a code owner April 13, 2026 18:36
Copy link
Copy Markdown
Member

@ArthurTonial ArthurTonial left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

@NicoleMGomes NicoleMGomes merged commit 0cfb39b into main Apr 13, 2026
9 of 11 checks passed
@NicoleMGomes NicoleMGomes deleted the bugfix/local-destination-virtual-env branch April 13, 2026 18:51
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.

LocalDevDestinationClient resolves mocks/ path relative to venv package directory instead of project root

2 participants