Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return absolute path without resolving symlinks (#4341)
After the rewrite of `util.abs_path` to use `pathlib` instead of `os.path` (000d200, c20dc08) the function now resolves symlinks in the given path whereas it did not do before. This breaks setups where the `molecule.yml` file in a scenario is a symlink. E.g. /common-files/molecule.yml /roles/role1/molecule/default/molecule.yml -> /common-files/molecule.yml /roles/role1/molecule/some-scenario/molecule.yml -> /common-files/molecule.yml /roles/role2/molecule/default/molecule.yml -> /common-files/molecule.yml Where a common `molecule.yml` can be used for multiple roles / scenarios and where changes to this file should reflect everywhere. In this case `molecule test` executed in `/roles/role1` returns `Scenario 'default' not found. Exiting.` or `molecule test -s some-scenario` executed in `/roles/role1` returns `Scenario 'some-scenario' not found. Exiting.` (see https://github.com/ansible/molecule/blob/f58ac30d5cee79a073ce0893701c8e82ec669078/src/molecule/scenarios.py#L127) Unfortunately `pathlib` is not a drop-in replacement for `os.path` (see https://docs.python.org/3/library/pathlib.html#comparison-to-the-os-and-os-path-modules). [Path.absolute()](https://docs.python.org/3/library/pathlib.html#pathlib.Path.absolute) does not resolve symlink but does not reduce `/../` segments in the path. [Path.resolve()](https://docs.python.org/3/library/pathlib.html#pathlib.Path.resolve) does reduce `/../` path elements, but also resolves symlinks. There is no method or combination of methods in the `Path` object that can deliver the same functionality as [os.path.abspath()](https://docs.python.org/3/library/os.path.html#os.path.abspath). Hence the code reverts back to using `os.path.abspath()`, but keeps accepting `Path` objects as input and returns the absolute path as such in these cases. --------- Signed-off-by: Ruediger Pluem <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Kate Case <[email protected]>
- Loading branch information