Update DataLoader.get_basedir to be an abspath (#85940)

pull/85953/head
sivel / Matt Martz 2 months ago committed by GitHub
parent 0c7dcb65cf
commit 6673a14a9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
minor_changes:
- DataLoader - Update ``DataLoader.get_basedir`` to be an abspath

@ -54,7 +54,7 @@ class DataLoader:
def __init__(self) -> None:
self._basedir: str = '.'
self._basedir: str = os.path.abspath('.')
# NOTE: not effective with forks as the main copy does not get updated.
# avoids rereading files
@ -227,7 +227,7 @@ class DataLoader:
def set_basedir(self, basedir: str) -> None:
""" sets the base directory, used to find files when a relative path is given """
self._basedir = basedir
self._basedir = os.path.abspath(basedir)
def path_dwim(self, given: str) -> str:
"""

@ -17,7 +17,6 @@
from __future__ import annotations
import os
import sys
import typing as t
@ -447,7 +446,7 @@ class VariableManager:
"""
variables = {}
variables['playbook_dir'] = os.path.abspath(self._loader.get_basedir())
variables['playbook_dir'] = self._loader.get_basedir()
variables['ansible_playbook_python'] = sys.executable
variables['ansible_config_file'] = C.CONFIG_FILE

@ -17,6 +17,7 @@
from __future__ import annotations
import collections
import os
import pathlib
import tempfile
@ -109,9 +110,9 @@ class TestDataLoader(unittest.TestCase):
self.assertIn('/tmp/roles/testrole/tasks/included2.yml', called_args)
self.assertIn('/tmp/roles/testrole/tasks/tasks/included2.yml', called_args)
# relative directories below are taken in account too:
self.assertIn('tasks/included2.yml', called_args)
self.assertIn('included2.yml', called_args)
c = collections.Counter(called_args)
assert c['/tmp/roles/testrole/tasks/included2.yml'] == 1
assert c['/tmp/roles/testrole/tasks/tasks/included2.yml'] == 2
def test_path_dwim_root(self):
self.assertEqual(self._loader.path_dwim('/'), '/')
@ -167,7 +168,7 @@ class TestPathDwimRelativeStackDataLoader(unittest.TestCase):
self.assertRaisesRegex(AnsibleFileNotFound, 'on the Ansible Controller', self._loader.path_dwim_relative_stack, None, None, None)
def test_empty_strings(self):
self.assertEqual(self._loader.path_dwim_relative_stack('', '', ''), './')
self.assertEqual(self._loader.path_dwim_relative_stack('', '', ''), os.path.abspath('./') + '/')
def test_empty_lists(self):
self.assertEqual(self._loader.path_dwim_relative_stack([], '', '~/'), os.path.expanduser('~'))

Loading…
Cancel
Save