Skip to content

Commit

Permalink
Merge branch 'master' into Analyze-report
Browse files Browse the repository at this point in the history
  • Loading branch information
Poiuy7312 authored Nov 4, 2023
2 parents 7a6150e + 1e73b89 commit 5a98846
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions chasten-test
Submodule chasten-test added at 2d8478
35 changes: 27 additions & 8 deletions chasten/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import sys
import time
from pathlib import Path
from typing import Any, Dict, List, Tuple, Union

Expand Down Expand Up @@ -387,8 +388,14 @@ def configure( # noqa: PLR0913


@cli.command()
def analyze( # noqa: PLR0913, PLR0915, PLR0912
def analyze( # noqa: PLR0912, PLR0913, PLR0915
project: str = typer.Argument(help="Name of the project."),
xpath: Path = typer.Option(
str,
"--xpath-version",
"-xp",
help="Accepts different xpath version, runs xpath version two by default.",
),
check_include: Tuple[enumerations.FilterableAttribute, str, int] = typer.Option(
(None, None, 0),
"--check-include",
Expand Down Expand Up @@ -460,6 +467,7 @@ def analyze( # noqa: PLR0913, PLR0915, PLR0912
force: bool = typer.Option(False, help="Force creation of new markdown file"),
) -> None:
"""💫 Analyze the AST of Python source code."""
start_time = time.time()
# output the preamble, including extra parameters specific to this function
output_preamble(
verbose,
Expand Down Expand Up @@ -584,12 +592,18 @@ def analyze( # noqa: PLR0913, PLR0915, PLR0912
# search for the XML contents of an AST that match the provided
# XPATH query using the search_python_file in search module of pyastgrep;
# this looks for matches across all path(s) in the specified source path
match_generator = pyastgrepsearch.search_python_files(
paths=valid_directories,
expression=current_xpath_pattern,
xpath2=True,
)
# materialize a list from the generator of (potential) matches;
# match_generator = pyastgrepsearch.search_python_files(
# paths=valid_directories, expression=current_xpath_pattern, xpath2=True
# )
if xpath == "1.0":
match_generator = pyastgrepsearch.search_python_files(
paths=valid_directories, expression=current_xpath_pattern, xpath2=False
)
else:
match_generator = pyastgrepsearch.search_python_files(
paths=valid_directories, expression=current_xpath_pattern, xpath2=True
)
# materia>>> mastlize a list from the generator of (potential) matches;
# note that this list will also contain an object that will
# indicate that the analysis completed for each located file
match_generator_list = list(match_generator)
Expand Down Expand Up @@ -733,6 +747,9 @@ def analyze( # noqa: PLR0913, PLR0915, PLR0912
# confirm whether or not all of the checks passed
# and then display the appropriate diagnostic message
all_checks_passed = all(check_status_list)
end_time = time.time()
elapsed_time = end_time - start_time

if not all_checks_passed:
output.console.print("\n:sweat: At least one check did not pass.")
if store_result:
Expand All @@ -742,7 +759,9 @@ def analyze( # noqa: PLR0913, PLR0915, PLR0912
f"\n:sparkles: Results saved in: {os.path.abspath(analysis_file_dir)}\n"
)
sys.exit(constants.markers.Non_Zero_Exit)
output.console.print("\n:joy: All checks passed.")
output.console.print(
f"\n:joy: All checks passed. Elapsed Time: {elapsed_time} seconds"
)
if store_result:
# writes results of analyze into a markdown file
result_path = os.path.abspath(analysis_file_dir)
Expand Down

0 comments on commit 5a98846

Please sign in to comment.