Debian Codegraph @

test/lib/ansible_test/_internal/classification/common.py

raw
1 """Common classification code used by multiple languages."""
2
3 from __future__ import annotations
4
5 import os
6
7 from ..data import (
8 data_context,
9 )
10
11
12 def resolve_csharp_ps_util(import_name: str, path: str) -> str:
13 """Return the fully qualified name of the given import if possible, otherwise return the original import name."""
14 if data_context().content.is_ansible or not import_name.startswith('.'):
15 # We don't support relative paths for builtin utils, there's no point.
16 return import_name
17
18 packages = import_name.split('.')
19 module_packages = path.split(os.path.sep)
20
21 for package in packages:
22 if not module_packages or package:
23 break
24 del module_packages[-1]
25
26 return 'ansible_collections.%s%s' % (data_context().content.prefix,
27 '.'.join(module_packages + [p for p in packages if p]))