2
2
3
3
import os
4
4
import sys
5
+ import time
5
6
from pathlib import Path
6
7
from typing import Any , Dict , List , Tuple , Union
7
8
@@ -387,8 +388,14 @@ def configure( # noqa: PLR0913
387
388
388
389
389
390
@cli .command ()
390
- def analyze ( # noqa: PLR0913, PLR0915, PLR0912
391
+ def analyze ( # noqa: PLR0912, PLR0913, PLR0915
391
392
project : str = typer .Argument (help = "Name of the project." ),
393
+ xpath : Path = typer .Option (
394
+ str ,
395
+ "--xpath-version" ,
396
+ "-xp" ,
397
+ help = "Accepts different xpath version, runs xpath version two by default." ,
398
+ ),
392
399
check_include : Tuple [enumerations .FilterableAttribute , str , int ] = typer .Option (
393
400
(None , None , 0 ),
394
401
"--check-include" ,
@@ -460,6 +467,7 @@ def analyze( # noqa: PLR0913, PLR0915, PLR0912
460
467
force : bool = typer .Option (False , help = "Force creation of new markdown file" ),
461
468
) -> None :
462
469
"""💫 Analyze the AST of Python source code."""
470
+ start_time = time .time ()
463
471
# output the preamble, including extra parameters specific to this function
464
472
output_preamble (
465
473
verbose ,
@@ -584,12 +592,18 @@ def analyze( # noqa: PLR0913, PLR0915, PLR0912
584
592
# search for the XML contents of an AST that match the provided
585
593
# XPATH query using the search_python_file in search module of pyastgrep;
586
594
# this looks for matches across all path(s) in the specified source path
587
- match_generator = pyastgrepsearch .search_python_files (
588
- paths = valid_directories ,
589
- expression = current_xpath_pattern ,
590
- xpath2 = True ,
591
- )
592
- # materialize a list from the generator of (potential) matches;
595
+ # match_generator = pyastgrepsearch.search_python_files(
596
+ # paths=valid_directories, expression=current_xpath_pattern, xpath2=True
597
+ # )
598
+ if xpath == "1.0" :
599
+ match_generator = pyastgrepsearch .search_python_files (
600
+ paths = valid_directories , expression = current_xpath_pattern , xpath2 = False
601
+ )
602
+ else :
603
+ match_generator = pyastgrepsearch .search_python_files (
604
+ paths = valid_directories , expression = current_xpath_pattern , xpath2 = True
605
+ )
606
+ # materia>>> mastlize a list from the generator of (potential) matches;
593
607
# note that this list will also contain an object that will
594
608
# indicate that the analysis completed for each located file
595
609
match_generator_list = list (match_generator )
@@ -733,6 +747,9 @@ def analyze( # noqa: PLR0913, PLR0915, PLR0912
733
747
# confirm whether or not all of the checks passed
734
748
# and then display the appropriate diagnostic message
735
749
all_checks_passed = all (check_status_list )
750
+ end_time = time .time ()
751
+ elapsed_time = end_time - start_time
752
+
736
753
if not all_checks_passed :
737
754
output .console .print ("\n :sweat: At least one check did not pass." )
738
755
if store_result :
@@ -742,7 +759,9 @@ def analyze( # noqa: PLR0913, PLR0915, PLR0912
742
759
f"\n :sparkles: Results saved in: { os .path .abspath (analysis_file_dir )} \n "
743
760
)
744
761
sys .exit (constants .markers .Non_Zero_Exit )
745
- output .console .print ("\n :joy: All checks passed." )
762
+ output .console .print (
763
+ f"\n :joy: All checks passed. Elapsed Time: { elapsed_time } seconds"
764
+ )
746
765
if store_result :
747
766
# writes results of analyze into a markdown file
748
767
result_path = os .path .abspath (analysis_file_dir )
0 commit comments