utilize pathlib.Path instead of os.path.join()

pull/82967/head
ds 2 months ago
parent 4bddbe69d5
commit 7163456591

@ -9,6 +9,7 @@ import hashlib
import json
import ntpath
import os.path
from pathlib import Path
import re
import shlex
import sys
@ -576,9 +577,9 @@ def path_join(paths):
''' takes a sequence or a string, and return a concatenation
of the different members '''
if isinstance(paths, string_types):
return os.path.join(paths)
return Path(paths).as_posix()
if is_sequence(paths):
return os.path.join(*paths)
return Path(*paths).as_posix()
raise AnsibleFilterTypeError("|path_join expects string or sequence, got %s instead." % type(paths))

@ -55,6 +55,7 @@ files to exist and are passthrus to the python os.path functions
path_join_simple = /etc/subdir/test
path_join_with_slash = /test
path_join_relative = etc/subdir/test
path_join_merged = /etc/subdir/test
TODO: realpath follows symlinks. There isn't a test for this just now.

@ -49,6 +49,7 @@ files to exist and are passthrus to the python os.path functions
path_join_simple = {{ ('/etc', 'subdir', 'test') | path_join }}
path_join_with_slash = {{ ('/etc', 'subdir', '/test') | path_join }}
path_join_relative = {{ ('etc', 'subdir', 'test') | path_join }}
path_join_merged = {{ ('/etc', 'subdir//test') | path_join }}
TODO: realpath follows symlinks. There isn't a test for this just now.

Loading…
Cancel
Save