Debian Codegraph @

test/lib/ansible_test/_internal/provider/source/unversioned.py

raw
1 """Fallback source provider when no other provider matches the content root."""
2
3 from __future__ import annotations
4
5 import os
6
7 from ...constants import (
8 TIMEOUT_PATH,
9 )
10
11 from ...encoding import (
12 to_bytes,
13 )
14
15 from . import (
16 SourceProvider,
17 )
18
19
20 class UnversionedSource(SourceProvider):
21 """Fallback source provider when no other provider matches the content root."""
22
23 sequence = 0 # disable automatic detection
24
25 @staticmethod
26 def is_content_root(path: str) -> bool:
27 """Return True if the given path is a content root for this provider."""
28 return False
29
30 def get_paths(self, path: str) -> list[str]:
31 """Return the list of available content paths under the given path."""
32 paths = []
33
34 kill_any_dir = (
35 '.idea',
36 '.pytest_cache',
37 '__pycache__',
38 'ansible.egg-info',
39 'ansible_base.egg-info',
40 'ansible_core.egg-info',
41 )
42
43 kill_sub_dir = {
44 'test': (
45 'results',
46 'cache',
47 'output',
48 ),
49 'tests': (
50 'output',
51 ),
52 }
53
54 kill_sub_file = {
55 '': (
56 TIMEOUT_PATH,
57 ),
58 }
59
60 kill_extensions = (
61 '.pyc',
62 '.pyo',
63 '.retry',
64 )
65
66 for root, dir_names, file_names in os.walk(path):
67 rel_root = os.path.relpath(root, path)
68
69 if rel_root == '.':
70 rel_root = ''
71
72 for kill in kill_any_dir + kill_sub_dir.get(rel_root, ()):
73 if kill in dir_names:
74 dir_names.remove(kill)
75
76 kill_files = kill_sub_file.get(rel_root, ())
77
78 paths.extend([os.path.join(rel_root, file_name) for file_name in file_names
79 if not os.path.splitext(file_name)[1] in kill_extensions and file_name not in kill_files])
80
81 # include directory symlinks since they will not be traversed and would otherwise go undetected
82 paths.extend([os.path.join(rel_root, dir_name) + os.path.sep for dir_name in dir_names if os.path.islink(to_bytes(dir_name))])
83
84 return paths