Return absolute path without resolving symlinks #4341
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After the rewrite of
util.abs_path
to usepathlib
instead ofos.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
returnsScenario 'default' not found. Exiting.
ormolecule test -s some-scenario
executed in/roles/role1
returnsScenario 'some-scenario' not found. Exiting.
(seemolecule/src/molecule/scenarios.py
Line 127 in f58ac30
Unfortunately
pathlib
is not a drop-in replacement foros.path
(see https://docs.python.org/3/library/pathlib.html#comparison-to-the-os-and-os-path-modules).Path.absolute() does not resolve symlink but does not reduce
/../
segments in the path. 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(). Hence the code reverts back to usingos.path.abspath()
, but keeps acceptingPath
objects as input and returns the absolute path as such in these cases.