From 7b9666a4943606a904c4c18304e7a763dd0fbaca Mon Sep 17 00:00:00 2001 From: Khushiyant Date: Sun, 28 Apr 2024 17:24:43 +0530 Subject: [PATCH] chore: change package name --- pyproject.toml | 2 +- {quasarx => quasar}/cli/__init__.py | 14 +-- {quasarx => quasarpy}/__init__.py | 6 +- {quasarx => quasarpy}/__main__.py | 2 +- {quasarx => quasarpy}/_version.py | 0 quasarpy/algorithm/__init__.py | 3 + {quasarx => quasarpy}/algorithm/detector.py | 10 +- {quasarx => quasarpy}/algorithm/llm.py | 2 +- .../algorithm/model/class_model.json | 0 .../algorithm/model/method_model.json | 0 quasarpy/cli/__init__.py | 118 ++++++++++++++++++ quasarpy/handler/__init__.py | 1 + {quasarx => quasarpy}/handler/issue.py | 2 +- {quasarx => quasarpy}/tests/__init__.py | 0 {quasarx => quasarpy}/tests/conftest.py | 4 +- {quasarx => quasarpy}/tests/test_algorithm.py | 0 {quasarx => quasarpy}/tests/test_cli.py | 0 {quasarx => quasarpy}/tests/test_handler.py | 2 +- {quasarx => quasarpy}/tests/test_utils.py | 6 +- quasarpy/utils/__init__.py | 8 ++ {quasarx => quasarpy}/utils/analyser.py | 2 +- {quasarx => quasarpy}/utils/ascii.py | 0 {quasarx => quasarpy}/utils/errors.py | 0 {quasarx => quasarpy}/utils/logger.py | 0 .../utils/prompt_template.py | 0 {quasarx => quasarpy}/utils/redis_server.py | 2 +- .../utils/templates/report_template.html | 0 quasarx/algorithm/__init__.py | 3 - quasarx/handler/__init__.py | 1 - quasarx/utils/__init__.py | 8 -- 30 files changed, 157 insertions(+), 39 deletions(-) rename {quasarx => quasar}/cli/__init__.py (91%) rename {quasarx => quasarpy}/__init__.py (83%) rename {quasarx => quasarpy}/__main__.py (69%) rename {quasarx => quasarpy}/_version.py (100%) create mode 100644 quasarpy/algorithm/__init__.py rename {quasarx => quasarpy}/algorithm/detector.py (95%) rename {quasarx => quasarpy}/algorithm/llm.py (98%) rename {quasarx => quasarpy}/algorithm/model/class_model.json (100%) rename {quasarx => quasarpy}/algorithm/model/method_model.json (100%) create mode 100644 quasarpy/cli/__init__.py create mode 100644 quasarpy/handler/__init__.py rename {quasarx => quasarpy}/handler/issue.py (98%) rename {quasarx => quasarpy}/tests/__init__.py (100%) rename {quasarx => quasarpy}/tests/conftest.py (80%) rename {quasarx => quasarpy}/tests/test_algorithm.py (100%) rename {quasarx => quasarpy}/tests/test_cli.py (100%) rename {quasarx => quasarpy}/tests/test_handler.py (91%) rename {quasarx => quasarpy}/tests/test_utils.py (77%) create mode 100644 quasarpy/utils/__init__.py rename {quasarx => quasarpy}/utils/analyser.py (97%) rename {quasarx => quasarpy}/utils/ascii.py (100%) rename {quasarx => quasarpy}/utils/errors.py (100%) rename {quasarx => quasarpy}/utils/logger.py (100%) rename {quasarx => quasarpy}/utils/prompt_template.py (100%) rename {quasarx => quasarpy}/utils/redis_server.py (99%) rename {quasarx => quasarpy}/utils/templates/report_template.html (100%) delete mode 100644 quasarx/algorithm/__init__.py delete mode 100644 quasarx/handler/__init__.py delete mode 100644 quasarx/utils/__init__.py diff --git a/pyproject.toml b/pyproject.toml index 02ea64d..3752501 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.poetry] -name = "quasarx" +name = "quasarpy" version = "0.1.0" description = "Quasar is python package that can be used for smell detection along with detailed report in various formats such as html, pdf, etc." authors = ["Khushiyant "] diff --git a/quasarx/cli/__init__.py b/quasar/cli/__init__.py similarity index 91% rename from quasarx/cli/__init__.py rename to quasar/cli/__init__.py index 26c147c..6183460 100644 --- a/quasarx/cli/__init__.py +++ b/quasar/cli/__init__.py @@ -1,14 +1,14 @@ import click import os from datetime import datetime -from quasarx._version import __version__ as _version -from quasarx.utils import ASCII_ART -from quasarx.utils import analyse -from quasarx.algorithm.detector import MainDetector, detect_smell -from quasarx.handler.issue import IssueHandler, Repository -from quasarx.utils.redis_server import generate_report, RedisConfig +from quasarpy._version import __version__ as _version +from quasarpy.utils import ASCII_ART +from quasarpy.utils import analyse +from quasarpy.algorithm.detector import MainDetector, detect_smell +from quasarpy.handler.issue import IssueHandler, Repository +from quasarpy.utils.redis_server import generate_report, RedisConfig import asyncio -from quasarx.algorithm import LLM, LLMConfig +from quasarpy.algorithm import LLM, LLMConfig class ASCIICommandClass(click.Group): def get_help(self, ctx): diff --git a/quasarx/__init__.py b/quasarpy/__init__.py similarity index 83% rename from quasarx/__init__.py rename to quasarpy/__init__.py index 6b14d4d..bb48142 100644 --- a/quasarx/__init__.py +++ b/quasarpy/__init__.py @@ -1,9 +1,9 @@ '''This module contains the main() function, which is the entry point for the command line interface.''' from dotenv import load_dotenv -from quasarx.cli import cli -from quasarx.utils import logger -from quasarx._version import __version__ as _version +from quasarpy.cli import cli +from quasarpy.utils import logger +from quasarpy._version import __version__ as _version __version__ = _version diff --git a/quasarx/__main__.py b/quasarpy/__main__.py similarity index 69% rename from quasarx/__main__.py rename to quasarpy/__main__.py index 0b1c4aa..01d011d 100644 --- a/quasarx/__main__.py +++ b/quasarpy/__main__.py @@ -1,4 +1,4 @@ """Module allowing for ``python -m quasar ...``.""" -from quasarx import main +from quasarpy import main main() diff --git a/quasarx/_version.py b/quasarpy/_version.py similarity index 100% rename from quasarx/_version.py rename to quasarpy/_version.py diff --git a/quasarpy/algorithm/__init__.py b/quasarpy/algorithm/__init__.py new file mode 100644 index 0000000..ca20d23 --- /dev/null +++ b/quasarpy/algorithm/__init__.py @@ -0,0 +1,3 @@ +from quasarpy.algorithm.detector import MainDetector # noqa: F401 +from quasarpy.algorithm.llm import LLM # noqa: F401 +from quasarpy.algorithm.llm import LLMConfig # noqa: F401 \ No newline at end of file diff --git a/quasarx/algorithm/detector.py b/quasarpy/algorithm/detector.py similarity index 95% rename from quasarx/algorithm/detector.py rename to quasarpy/algorithm/detector.py index 79799b7..096b635 100644 --- a/quasarx/algorithm/detector.py +++ b/quasarpy/algorithm/detector.py @@ -1,13 +1,13 @@ from abc import ABC, abstractmethod import os from typing import Dict -from quasarx.utils.logger import logger +from quasarpy.utils.logger import logger import xgboost as xgb -from quasarx.handler.issue import Issue, IssueHandler -from quasarx.utils.redis_server import RedisConfig, RedisServer +from quasarpy.handler.issue import Issue, IssueHandler +from quasarpy.utils.redis_server import RedisConfig, RedisServer import asyncio -from quasarx.algorithm.llm import LLM -from quasarx.utils import PROMPT_TEMPLATE +from quasarpy.algorithm.llm import LLM +from quasarpy.utils import PROMPT_TEMPLATE diff --git a/quasarx/algorithm/llm.py b/quasarpy/algorithm/llm.py similarity index 98% rename from quasarx/algorithm/llm.py rename to quasarpy/algorithm/llm.py index e7d2bd0..4ef7803 100644 --- a/quasarx/algorithm/llm.py +++ b/quasarpy/algorithm/llm.py @@ -1,5 +1,5 @@ from transformers import AutoTokenizer, AutoModelForCausalLM -from quasarx.utils.logger import logger +from quasarpy.utils.logger import logger from dataclasses import dataclass import huggingface_hub import os diff --git a/quasarx/algorithm/model/class_model.json b/quasarpy/algorithm/model/class_model.json similarity index 100% rename from quasarx/algorithm/model/class_model.json rename to quasarpy/algorithm/model/class_model.json diff --git a/quasarx/algorithm/model/method_model.json b/quasarpy/algorithm/model/method_model.json similarity index 100% rename from quasarx/algorithm/model/method_model.json rename to quasarpy/algorithm/model/method_model.json diff --git a/quasarpy/cli/__init__.py b/quasarpy/cli/__init__.py new file mode 100644 index 0000000..6183460 --- /dev/null +++ b/quasarpy/cli/__init__.py @@ -0,0 +1,118 @@ +import click +import os +from datetime import datetime +from quasarpy._version import __version__ as _version +from quasarpy.utils import ASCII_ART +from quasarpy.utils import analyse +from quasarpy.algorithm.detector import MainDetector, detect_smell +from quasarpy.handler.issue import IssueHandler, Repository +from quasarpy.utils.redis_server import generate_report, RedisConfig +import asyncio +from quasarpy.algorithm import LLM, LLMConfig + +class ASCIICommandClass(click.Group): + def get_help(self, ctx): + return ASCII_ART + "\n" + super().get_help(ctx) + + +@click.group(name="cli", cls=ASCIICommandClass) +@click.version_option(_version, prog_name="Quasar") +@click.help_option("-h", "--help") +def cli() -> None: + pass + + +@cli.command(name="detect", help="Detect code smells") +@click.option( + "--path", + "-p", + type=click.Path(exists=True), + help="Path to the directory to analyse", +) +@click.option( + "--format", + "-f", + type=click.Choice(["json", "pdf", "html"]), + help="Format of the report", +) +@click.option( + "--solution", "-s", is_flag=True, help="Provide solutions for detected code smells" +) +@click.option( + "--create-issue", "-c", is_flag=True, help="Create an issue if a smell is detected" +) +@click.option( + "--output", "-o", type=click.Path(exists=False), help="Output file path for report" +) +@click.option( + "--offline", is_flag=False, help="Use the offline version of the model" +) +def detect(path, format, solution, create_issue, output, offline) -> None: + """ + Detects the specified type of object in the given path and formats the output. + + Args: + path (str): The path to the file or directory to be analyzed. + format (str): The desired output format ('json' or 'xml'). + solution (bool): Whether to provide solutions for the detected code smells. + create_issue (bool): Whether to create an issue for the detected code smells. + output (str): The path to save the output report. + + Raises: + ValueError: If the path is not provided or if format and output path are required but not provided. + NotImplementedError: If the solution flag is set to True (not implemented yet) or if other formats are not implemented yet. + + Returns: + None + """ + issue_handler = IssueHandler(repo=Repository()) if create_issue else None + redis_config = RedisConfig() + + if solution: + raise NotImplementedError("Solution flag not implemented yet") + else: + try: + if path: + data_json = analyse([path]) + if format in ["json", "pdf", "html"]: + try: + llm_config = LLMConfig() + llm = LLM(llm_config, is_online=True if not offline else False) + + detector = MainDetector(llm=llm, issue_handler=issue_handler) + data = asyncio.run(detect_smell(data_json, detector)) + + if not format or not output: + raise ValueError("Format and output path are required") + + report_path = os.path.join( + output, + f'report_{datetime.now().strftime("%H%M%S")}', + ) + + if format == "json": + with open(report_path, "w") as f: + f.write(data) + else: + if not data: + raise ValueError("No data to write") + + generate_report( + config=redis_config, + format=format, + data=data, + report_path=report_path, + ) + + except Exception as e: + raise e + else: + raise NotImplementedError("Other format not implemented yet") + else: + raise ValueError("Path is required") + except Exception as e: + raise e + + +if __name__ == "__main__": + cli() diff --git a/quasarpy/handler/__init__.py b/quasarpy/handler/__init__.py new file mode 100644 index 0000000..3dab16c --- /dev/null +++ b/quasarpy/handler/__init__.py @@ -0,0 +1 @@ +from quasarpy.handler.issue import Issue, IssueHandler, Repository # noqa: F401 \ No newline at end of file diff --git a/quasarx/handler/issue.py b/quasarpy/handler/issue.py similarity index 98% rename from quasarx/handler/issue.py rename to quasarpy/handler/issue.py index 0351a92..2822495 100644 --- a/quasarx/handler/issue.py +++ b/quasarpy/handler/issue.py @@ -2,7 +2,7 @@ from dataclasses import dataclass, field -from quasarx.utils.logger import logger +from quasarpy.utils.logger import logger from typing import AnyStr, List import pydantic diff --git a/quasarx/tests/__init__.py b/quasarpy/tests/__init__.py similarity index 100% rename from quasarx/tests/__init__.py rename to quasarpy/tests/__init__.py diff --git a/quasarx/tests/conftest.py b/quasarpy/tests/conftest.py similarity index 80% rename from quasarx/tests/conftest.py rename to quasarpy/tests/conftest.py index 222a70e..befc231 100644 --- a/quasarx/tests/conftest.py +++ b/quasarpy/tests/conftest.py @@ -1,6 +1,6 @@ import pytest -from quasarx.handler import Repository -from quasarx.handler import Issue +from quasarpy.handler import Repository +from quasarpy.handler import Issue @pytest.fixture diff --git a/quasarx/tests/test_algorithm.py b/quasarpy/tests/test_algorithm.py similarity index 100% rename from quasarx/tests/test_algorithm.py rename to quasarpy/tests/test_algorithm.py diff --git a/quasarx/tests/test_cli.py b/quasarpy/tests/test_cli.py similarity index 100% rename from quasarx/tests/test_cli.py rename to quasarpy/tests/test_cli.py diff --git a/quasarx/tests/test_handler.py b/quasarpy/tests/test_handler.py similarity index 91% rename from quasarx/tests/test_handler.py rename to quasarpy/tests/test_handler.py index af2cd32..cfce672 100644 --- a/quasarx/tests/test_handler.py +++ b/quasarpy/tests/test_handler.py @@ -1,6 +1,6 @@ import pytest -from quasarx.handler import Issue, Repository +from quasarpy.handler import Issue, Repository import pydantic diff --git a/quasarx/tests/test_utils.py b/quasarpy/tests/test_utils.py similarity index 77% rename from quasarx/tests/test_utils.py rename to quasarpy/tests/test_utils.py index 3e6b07b..a84eb01 100644 --- a/quasarx/tests/test_utils.py +++ b/quasarpy/tests/test_utils.py @@ -1,6 +1,6 @@ -from quasarx.utils.errors import LiteralEvalError -from quasarx.utils.logger import logger -from quasarx.utils.redis_server import RedisConfig +from quasarpy.utils.errors import LiteralEvalError +from quasarpy.utils.logger import logger +from quasarpy.utils.redis_server import RedisConfig # Test the logger diff --git a/quasarpy/utils/__init__.py b/quasarpy/utils/__init__.py new file mode 100644 index 0000000..347ba34 --- /dev/null +++ b/quasarpy/utils/__init__.py @@ -0,0 +1,8 @@ +from quasarpy.utils.ascii import ASCII_ART # noqa: F401 +from quasarpy.utils.analyser import analyse # noqa: F401 +from quasarpy.utils.logger import logger # noqa: F401 +from quasarpy.utils.errors import LiteralEvalError # noqa: F401 +from quasarpy.utils.redis_server import RedisServer # noqa: F401 +from quasarpy.utils.redis_server import RedisConfig # noqa: F401 +from quasarpy.utils.redis_server import generate_report # noqa: F401 +from quasarpy.utils.prompt_template import PROMPT_TEMPLATE # noqa: F401 \ No newline at end of file diff --git a/quasarx/utils/analyser.py b/quasarpy/utils/analyser.py similarity index 97% rename from quasarx/utils/analyser.py rename to quasarpy/utils/analyser.py index c2bbcda..bca7ca8 100644 --- a/quasarx/utils/analyser.py +++ b/quasarpy/utils/analyser.py @@ -1,7 +1,7 @@ from radon.cli.harvest import RawHarvester from radon.cli import Config from radon.metrics import h_visit -from quasarx.utils.errors import LiteralEvalError +from quasarpy.utils.errors import LiteralEvalError import json diff --git a/quasarx/utils/ascii.py b/quasarpy/utils/ascii.py similarity index 100% rename from quasarx/utils/ascii.py rename to quasarpy/utils/ascii.py diff --git a/quasarx/utils/errors.py b/quasarpy/utils/errors.py similarity index 100% rename from quasarx/utils/errors.py rename to quasarpy/utils/errors.py diff --git a/quasarx/utils/logger.py b/quasarpy/utils/logger.py similarity index 100% rename from quasarx/utils/logger.py rename to quasarpy/utils/logger.py diff --git a/quasarx/utils/prompt_template.py b/quasarpy/utils/prompt_template.py similarity index 100% rename from quasarx/utils/prompt_template.py rename to quasarpy/utils/prompt_template.py diff --git a/quasarx/utils/redis_server.py b/quasarpy/utils/redis_server.py similarity index 99% rename from quasarx/utils/redis_server.py rename to quasarpy/utils/redis_server.py index 3d6d042..b9cdb2e 100644 --- a/quasarx/utils/redis_server.py +++ b/quasarpy/utils/redis_server.py @@ -1,6 +1,6 @@ import redis import os -from quasarx.utils.logger import logger +from quasarpy.utils.logger import logger import pydantic import datetime from jinja2 import Environment, FileSystemLoader diff --git a/quasarx/utils/templates/report_template.html b/quasarpy/utils/templates/report_template.html similarity index 100% rename from quasarx/utils/templates/report_template.html rename to quasarpy/utils/templates/report_template.html diff --git a/quasarx/algorithm/__init__.py b/quasarx/algorithm/__init__.py deleted file mode 100644 index 37cbb7f..0000000 --- a/quasarx/algorithm/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from quasarx.algorithm.detector import MainDetector # noqa: F401 -from quasarx.algorithm.llm import LLM # noqa: F401 -from quasarx.algorithm.llm import LLMConfig # noqa: F401 \ No newline at end of file diff --git a/quasarx/handler/__init__.py b/quasarx/handler/__init__.py deleted file mode 100644 index e277da7..0000000 --- a/quasarx/handler/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from quasarx.handler.issue import Issue, IssueHandler, Repository # noqa: F401 \ No newline at end of file diff --git a/quasarx/utils/__init__.py b/quasarx/utils/__init__.py deleted file mode 100644 index 0ced5c5..0000000 --- a/quasarx/utils/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from quasarx.utils.ascii import ASCII_ART # noqa: F401 -from quasarx.utils.analyser import analyse # noqa: F401 -from quasarx.utils.logger import logger # noqa: F401 -from quasarx.utils.errors import LiteralEvalError # noqa: F401 -from quasarx.utils.redis_server import RedisServer # noqa: F401 -from quasarx.utils.redis_server import RedisConfig # noqa: F401 -from quasarx.utils.redis_server import generate_report # noqa: F401 -from quasarx.utils.prompt_template import PROMPT_TEMPLATE # noqa: F401 \ No newline at end of file