Skip to content

Commit 5a98846

Browse files
authored
Merge branch 'master' into Analyze-report
2 parents 7a6150e + 1e73b89 commit 5a98846

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

chasten-test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 2d8478da0234a1425f5e767e0d1a69d17ec26aa4

chasten/main.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import sys
5+
import time
56
from pathlib import Path
67
from typing import Any, Dict, List, Tuple, Union
78

@@ -387,8 +388,14 @@ def configure( # noqa: PLR0913
387388

388389

389390
@cli.command()
390-
def analyze( # noqa: PLR0913, PLR0915, PLR0912
391+
def analyze( # noqa: PLR0912, PLR0913, PLR0915
391392
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+
),
392399
check_include: Tuple[enumerations.FilterableAttribute, str, int] = typer.Option(
393400
(None, None, 0),
394401
"--check-include",
@@ -460,6 +467,7 @@ def analyze( # noqa: PLR0913, PLR0915, PLR0912
460467
force: bool = typer.Option(False, help="Force creation of new markdown file"),
461468
) -> None:
462469
"""💫 Analyze the AST of Python source code."""
470+
start_time = time.time()
463471
# output the preamble, including extra parameters specific to this function
464472
output_preamble(
465473
verbose,
@@ -584,12 +592,18 @@ def analyze( # noqa: PLR0913, PLR0915, PLR0912
584592
# search for the XML contents of an AST that match the provided
585593
# XPATH query using the search_python_file in search module of pyastgrep;
586594
# 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;
593607
# note that this list will also contain an object that will
594608
# indicate that the analysis completed for each located file
595609
match_generator_list = list(match_generator)
@@ -733,6 +747,9 @@ def analyze( # noqa: PLR0913, PLR0915, PLR0912
733747
# confirm whether or not all of the checks passed
734748
# and then display the appropriate diagnostic message
735749
all_checks_passed = all(check_status_list)
750+
end_time = time.time()
751+
elapsed_time = end_time - start_time
752+
736753
if not all_checks_passed:
737754
output.console.print("\n:sweat: At least one check did not pass.")
738755
if store_result:
@@ -742,7 +759,9 @@ def analyze( # noqa: PLR0913, PLR0915, PLR0912
742759
f"\n:sparkles: Results saved in: {os.path.abspath(analysis_file_dir)}\n"
743760
)
744761
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+
)
746765
if store_result:
747766
# writes results of analyze into a markdown file
748767
result_path = os.path.abspath(analysis_file_dir)

0 commit comments

Comments
 (0)