Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change --Xpath Versions While Using Chasten Analyze #90

Merged
merged 25 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions chasten-test
Submodule chasten-test added at 2d8478
32 changes: 27 additions & 5 deletions chasten/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""💫 Chasten checks the AST of a Python program."""

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

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


@cli.command()
def analyze( # noqa: PLR0913, PLR0915
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 @@ -441,6 +448,7 @@ def analyze( # noqa: PLR0913, PLR0915
save: bool = typer.Option(False, help="Enable saving of output file(s)."),
) -> 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 @@ -542,9 +550,18 @@ def analyze( # noqa: PLR0913, PLR0915
# 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
)
# 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
)

# materialize 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
Expand Down Expand Up @@ -668,10 +685,15 @@ def analyze( # noqa: PLR0913, PLR0915
# 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.")
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"
)


@cli.command()
Expand Down
Loading