Skip to content

Commit beb3dfd

Browse files
committed
feat: expand import file
1 parent cdf1859 commit beb3dfd

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/aaz_dev/swagger/model/specs/_typespec_helper.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,35 @@ def find_data_plane_entry_files(cls, folder):
4545

4646
@classmethod
4747
def _parse_main_tsp(cls, path):
48-
with open(path, 'r', encoding='utf-8') as f:
49-
lines = f.readlines()
48+
def expand(import_path):
49+
with open(import_path, "r", encoding="utf-8") as f:
50+
lines = f.readlines()
51+
52+
base = os.path.dirname(import_path)
53+
54+
content = []
55+
for line in lines:
56+
if match := import_pattern.findall(line):
57+
rel_path = match[0]
58+
abs_path = os.path.abspath(os.path.join(base, rel_path))
59+
60+
if os.path.isfile(abs_path): # expand first level only; otherwise, will impact performance
61+
with open(abs_path, "r", encoding="utf-8") as f:
62+
content.append("".join(f.readlines()))
63+
64+
else:
65+
content.append(line)
66+
else:
67+
content.append(line)
68+
69+
return "".join(content).split("\n")
70+
71+
import_pattern = re.compile(r'^import "([^"]+)"')
72+
5073
is_mgmt_plane = False
5174
namespace = None
52-
for line in lines:
75+
76+
for line in expand(path):
5377
if line.startswith("@armProviderNamespace"):
5478
is_mgmt_plane = True
5579
if line.startswith("namespace "):

0 commit comments

Comments
 (0)