Skip to content

Commit b3f1ef4

Browse files
authored
Merge pull request #448 from necusjz/support-aaz-hooks
Support aaz hooks
2 parents 35794b1 + d5c0f5b commit b3f1ef4

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

src/aaz_dev/app/run.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import subprocess
23
import webbrowser
34

45
import click
@@ -129,7 +130,7 @@ def is_port_in_use(host, port):
129130
)
130131
@pass_script_info
131132
def run_command(
132-
info, host, port, reload, debugger, with_threads, extra_files, quiet
133+
info, host, port, aaz_path, reload, debugger, with_threads, extra_files, quiet
133134
):
134135
"""Run a local development server.
135136
@@ -139,6 +140,8 @@ def run_command(
139140
The reloader and debugger are enabled by default if
140141
FLASK_ENV=development or FLASK_DEBUG=1.
141142
"""
143+
_change_git_hooks_path(aaz_path)
144+
142145
debug = get_debug_flag()
143146

144147
if reload is None:
@@ -169,3 +172,11 @@ def run_command(
169172
threaded=with_threads,
170173
extra_files=extra_files,
171174
)
175+
176+
177+
def _change_git_hooks_path(repo_path):
178+
# if .githooks folder exists in the repo folder, change the git config to use the .githooks folder in the repo
179+
githooks_path = os.path.join(repo_path, '.githooks')
180+
if os.path.exists(githooks_path):
181+
subprocess.check_call(['git', 'config', 'core.hooksPath', githooks_path])
182+
display(f"Changed git hooks path to {githooks_path}")

src/aaz_dev/command/api/_cmds.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ def generate_command_models_from_swagger(swagger_tag, workspace_path=None):
166166
expose_value=False,
167167
help="Path of `aaz` repository."
168168
)
169-
def verify():
169+
@click.option(
170+
"--target", "-t",
171+
help="Target module to focus on."
172+
)
173+
def verify(target):
170174
def verify_resource(model, path):
171175
if "commandGroups" not in model:
172176
return
@@ -196,9 +200,6 @@ def verify_command(file_path):
196200
json_path = os.path.join(Config.AAZ_PATH, os.path.splitext(path)[0][1:] + ".json")
197201
json_path = os.path.normpath(json_path)
198202

199-
if json_path in model_set:
200-
continue
201-
202203
if not os.path.exists(json_path):
203204
raise Exception(f"{json_path} defined in {file_path} is missing.")
204205

@@ -232,7 +233,13 @@ def verify_command(file_path):
232233

233234
model_set = set()
234235
aaz = AAZSpecsManager()
235-
stack = [aaz.commands_folder]
236+
237+
parent = aaz.commands_folder
238+
stack = [os.path.join(parent, target)] if target else [
239+
os.path.join(parent, i)
240+
for i in os.listdir(parent)
241+
if os.path.isdir(os.path.join(parent, i))
242+
]
236243

237244
while stack:
238245
curr_path = stack.pop()
@@ -279,11 +286,12 @@ def verify_command(file_path):
279286
for folder in folders:
280287
stack.append(os.path.join(curr_path, folder))
281288

282-
for root, _, files in os.walk(aaz.resources_folder):
283-
for file in files:
284-
if not file.endswith(".json") or file.startswith("client"): # support data-plane
285-
continue
289+
if not target:
290+
for root, _, files in os.walk(aaz.resources_folder):
291+
for file in files:
292+
if not file.endswith(".json") or file.startswith("client"): # support data-plane
293+
continue
286294

287-
file_path = os.path.join(root, file)
288-
if file_path not in model_set:
289-
raise Exception(f"{file_path} is redundant.")
295+
file_path = os.path.join(root, file)
296+
if file_path not in model_set:
297+
raise Exception(f"{file_path} is redundant.")

0 commit comments

Comments
 (0)