pybughunt


Namepybughunt JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/Preksha-7/pybughunt
SummaryA Python library for detecting logical and syntactical errors in Python code
upload_time2025-08-09 14:37:20
maintainerNone
docs_urlNone
authorPreksha Upadhyay
requires_python>=3.8
licenseMIT
keywords code python error detection static analysis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyBugHunt

## Advanced Python Code Error Detection and Analysis

PyBugHunt is a sophisticated Python library designed to detect, analyze, and suggest fixes for both syntactical and logical errors in Python code. Leveraging a combination of static code analysis techniques and advanced transformer-based machine learning models, PyBugHunt offers developers a powerful tool to improve code quality and reduce debugging time.

![Python Version](https://img.shields.io/badge/python-3.8%2B-blue)
![License](https://img.shields.io/badge/license-MIT-green)
![Version](https://img.shields.io/badge/version-0.2.0-blue)

---

## Table of Contents

- [Features](#features)
- [Technology Stack](#technology-stack)
- [Project Structure](#project-structure)
- [Installation](#installation)
- [Usage](#usage)
  - [Command Line Interface](#command-line-interface)
  - [Python API](#python-api)
- [Error Detection Capabilities](#error-detection-capabilities)
- [Machine Learning Approach](#machine-learning-approach)
- [Development](#development)
- [License](#license)
- [Contributing](#contributing)

---

## Features

PyBugHunt offers comprehensive error detection capabilities:

- **Robust Syntax Error Detection and Analysis**
- **Intelligent Logical Error Detection** using both static analysis and machine learning.
- **Transformer-Based Models**:
  - **CodeBERT**: For classifying code as correct or containing a logical error.
  - **T5 (Text-to-Text Transfer Transformer)**: For generating natural language descriptions of the detected errors.
- **Fix Suggestion System**
- **Flexible Integration Options** (CLI and Python API)
- **Customization and Training** of models.

---

## Technology Stack

PyBugHunt utilizes a wide range of technologies and libraries:

### Core Technologies

- **Python 3.8+**
- **Abstract Syntax Tree (AST)**
- **Python Standard Library**

### Machine Learning

- **PyTorch**
- **Hugging Face Transformers** (for CodeBERT and T5)
- **scikit-learn**
- **NumPy**

### Static Analysis

- **Astroid**
- **PyLint**

---

## Project Structure

```
pybughunt/
├── src/
│   └── pybughunt/
│       ├── __init__.py
│       ├── cli.py
│       ├── detector.py
│       ├── logic_analyzer.py
│       ├── syntax_analyzer.py
│       └── models/
│           ├── __init__.py
│           ├── model_loader.py
│           ├── model_trainer.py
│           └── models.py  # New file for transformer model definitions
├── tests/
├── .gitignore
├── README.md
├── pyproject.toml
└── setup.py
```

---

## Installation

### From Source

```bash
# Clone the repository
git clone https://github.com/Preksha-7/pybughunt.git
cd pybughunt

# Install in development mode
pip install -e .
```

### Dependencies

All dependencies will be automatically installed. The main dependencies are listed in `pyproject.toml` and `setup.py`.

---

## Usage

### Command Line Interface

Analyze a file with the default static analysis:

```bash
python -m pybughunt.cli analyze src/pybughunt/sample_buggy.py --model_type static
```

Analyze a file using a specific machine learning model:

```bash
python -m pybughunt.cli analyze src/pybughunt/sample_buggy.py --model_type codebert --model_path path/to/saved_codebert_model
```

Train a new model:

```bash
python -m pybughunt.cli train --dataset /path/to/python/files --output my_model --model_type codebert
```

### Python API

```python
from pybughunt import CodeErrorDetector

# Initialize the detector with a specific model
detector = CodeErrorDetector(model_type='codebert', model_path='path/to/saved_codebert_model')

code = '''
def incorrect_factorial(n):
    if n == 0:
        return 1
    else:
        return incorrect_factorial(n-1) # Missing multiplication with n
'''

results = detector.analyze(code)
print(results)
```

---

## Error Detection Capabilities

**Syntax Errors:** Missing delimiters, indentation issues, invalid syntax, etc.

**Logical Errors:**

- **Static Analysis:** Infinite loops, unused variables, off-by-one errors, division by zero, unreachable code.
- **Machine Learning:** More subtle logical errors detected by the trained transformer models.

---

## Machine Learning Approach

PyBugHunt now includes transformer-based models for more advanced logical error detection:

**CodeBERT (microsoft/codebert-base):** A model pre-trained on a large corpus of code, used for classifying code snippets as either correct or containing a logical error.

**T5 (t5-small):** A sequence-to-sequence model that can be trained to generate a natural language description of the error in a piece of code.

These models can be trained on your own dataset using the `train` command in the CLI.

---

## Development

The project is structured to be modular and extensible. You can add new error detection patterns to the `logic_analyzer.py` or experiment with different models in the `models/` directory.

---

## License

This project is licensed under the MIT License. See the LICENSE file for details.

---

## Contributing

Contributions are welcome! Please feel free to submit a pull request.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Preksha-7/pybughunt",
    "name": "pybughunt",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "code, python, error, detection, static analysis",
    "author": "Preksha Upadhyay",
    "author_email": "Preksha Upadhyay <prekshaupadhyay03@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/0f/3b/2dc4356e4f415e2c6d48bc70a33abc7880cdbde36da55d650f3ae7313386/pybughunt-0.2.0.tar.gz",
    "platform": null,
    "description": "# PyBugHunt\r\n\r\n## Advanced Python Code Error Detection and Analysis\r\n\r\nPyBugHunt is a sophisticated Python library designed to detect, analyze, and suggest fixes for both syntactical and logical errors in Python code. Leveraging a combination of static code analysis techniques and advanced transformer-based machine learning models, PyBugHunt offers developers a powerful tool to improve code quality and reduce debugging time.\r\n\r\n![Python Version](https://img.shields.io/badge/python-3.8%2B-blue)\r\n![License](https://img.shields.io/badge/license-MIT-green)\r\n![Version](https://img.shields.io/badge/version-0.2.0-blue)\r\n\r\n---\r\n\r\n## Table of Contents\r\n\r\n- [Features](#features)\r\n- [Technology Stack](#technology-stack)\r\n- [Project Structure](#project-structure)\r\n- [Installation](#installation)\r\n- [Usage](#usage)\r\n  - [Command Line Interface](#command-line-interface)\r\n  - [Python API](#python-api)\r\n- [Error Detection Capabilities](#error-detection-capabilities)\r\n- [Machine Learning Approach](#machine-learning-approach)\r\n- [Development](#development)\r\n- [License](#license)\r\n- [Contributing](#contributing)\r\n\r\n---\r\n\r\n## Features\r\n\r\nPyBugHunt offers comprehensive error detection capabilities:\r\n\r\n- **Robust Syntax Error Detection and Analysis**\r\n- **Intelligent Logical Error Detection** using both static analysis and machine learning.\r\n- **Transformer-Based Models**:\r\n  - **CodeBERT**: For classifying code as correct or containing a logical error.\r\n  - **T5 (Text-to-Text Transfer Transformer)**: For generating natural language descriptions of the detected errors.\r\n- **Fix Suggestion System**\r\n- **Flexible Integration Options** (CLI and Python API)\r\n- **Customization and Training** of models.\r\n\r\n---\r\n\r\n## Technology Stack\r\n\r\nPyBugHunt utilizes a wide range of technologies and libraries:\r\n\r\n### Core Technologies\r\n\r\n- **Python 3.8+**\r\n- **Abstract Syntax Tree (AST)**\r\n- **Python Standard Library**\r\n\r\n### Machine Learning\r\n\r\n- **PyTorch**\r\n- **Hugging Face Transformers** (for CodeBERT and T5)\r\n- **scikit-learn**\r\n- **NumPy**\r\n\r\n### Static Analysis\r\n\r\n- **Astroid**\r\n- **PyLint**\r\n\r\n---\r\n\r\n## Project Structure\r\n\r\n```\r\npybughunt/\r\n\u251c\u2500\u2500 src/\r\n\u2502   \u2514\u2500\u2500 pybughunt/\r\n\u2502       \u251c\u2500\u2500 __init__.py\r\n\u2502       \u251c\u2500\u2500 cli.py\r\n\u2502       \u251c\u2500\u2500 detector.py\r\n\u2502       \u251c\u2500\u2500 logic_analyzer.py\r\n\u2502       \u251c\u2500\u2500 syntax_analyzer.py\r\n\u2502       \u2514\u2500\u2500 models/\r\n\u2502           \u251c\u2500\u2500 __init__.py\r\n\u2502           \u251c\u2500\u2500 model_loader.py\r\n\u2502           \u251c\u2500\u2500 model_trainer.py\r\n\u2502           \u2514\u2500\u2500 models.py  # New file for transformer model definitions\r\n\u251c\u2500\u2500 tests/\r\n\u251c\u2500\u2500 .gitignore\r\n\u251c\u2500\u2500 README.md\r\n\u251c\u2500\u2500 pyproject.toml\r\n\u2514\u2500\u2500 setup.py\r\n```\r\n\r\n---\r\n\r\n## Installation\r\n\r\n### From Source\r\n\r\n```bash\r\n# Clone the repository\r\ngit clone https://github.com/Preksha-7/pybughunt.git\r\ncd pybughunt\r\n\r\n# Install in development mode\r\npip install -e .\r\n```\r\n\r\n### Dependencies\r\n\r\nAll dependencies will be automatically installed. The main dependencies are listed in `pyproject.toml` and `setup.py`.\r\n\r\n---\r\n\r\n## Usage\r\n\r\n### Command Line Interface\r\n\r\nAnalyze a file with the default static analysis:\r\n\r\n```bash\r\npython -m pybughunt.cli analyze src/pybughunt/sample_buggy.py --model_type static\r\n```\r\n\r\nAnalyze a file using a specific machine learning model:\r\n\r\n```bash\r\npython -m pybughunt.cli analyze src/pybughunt/sample_buggy.py --model_type codebert --model_path path/to/saved_codebert_model\r\n```\r\n\r\nTrain a new model:\r\n\r\n```bash\r\npython -m pybughunt.cli train --dataset /path/to/python/files --output my_model --model_type codebert\r\n```\r\n\r\n### Python API\r\n\r\n```python\r\nfrom pybughunt import CodeErrorDetector\r\n\r\n# Initialize the detector with a specific model\r\ndetector = CodeErrorDetector(model_type='codebert', model_path='path/to/saved_codebert_model')\r\n\r\ncode = '''\r\ndef incorrect_factorial(n):\r\n    if n == 0:\r\n        return 1\r\n    else:\r\n        return incorrect_factorial(n-1) # Missing multiplication with n\r\n'''\r\n\r\nresults = detector.analyze(code)\r\nprint(results)\r\n```\r\n\r\n---\r\n\r\n## Error Detection Capabilities\r\n\r\n**Syntax Errors:** Missing delimiters, indentation issues, invalid syntax, etc.\r\n\r\n**Logical Errors:**\r\n\r\n- **Static Analysis:** Infinite loops, unused variables, off-by-one errors, division by zero, unreachable code.\r\n- **Machine Learning:** More subtle logical errors detected by the trained transformer models.\r\n\r\n---\r\n\r\n## Machine Learning Approach\r\n\r\nPyBugHunt now includes transformer-based models for more advanced logical error detection:\r\n\r\n**CodeBERT (microsoft/codebert-base):** A model pre-trained on a large corpus of code, used for classifying code snippets as either correct or containing a logical error.\r\n\r\n**T5 (t5-small):** A sequence-to-sequence model that can be trained to generate a natural language description of the error in a piece of code.\r\n\r\nThese models can be trained on your own dataset using the `train` command in the CLI.\r\n\r\n---\r\n\r\n## Development\r\n\r\nThe project is structured to be modular and extensible. You can add new error detection patterns to the `logic_analyzer.py` or experiment with different models in the `models/` directory.\r\n\r\n---\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License. See the LICENSE file for details.\r\n\r\n---\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to submit a pull request.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python library for detecting logical and syntactical errors in Python code",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/Preksha-7/pybughunt"
    },
    "split_keywords": [
        "code",
        " python",
        " error",
        " detection",
        " static analysis"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5bf188c4176175b578d4f15a66b5de471be08b8dd1126ddea24e6ec6b6015e87",
                "md5": "30d5c7f8126dab9caf94bf69ba12c350",
                "sha256": "fae32ce71876929160d46f96eb9884db25fe0dc794d4e52cc775f52197f49f57"
            },
            "downloads": -1,
            "filename": "pybughunt-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "30d5c7f8126dab9caf94bf69ba12c350",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 17574,
            "upload_time": "2025-08-09T14:37:18",
            "upload_time_iso_8601": "2025-08-09T14:37:18.256589Z",
            "url": "https://files.pythonhosted.org/packages/5b/f1/88c4176175b578d4f15a66b5de471be08b8dd1126ddea24e6ec6b6015e87/pybughunt-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0f3b2dc4356e4f415e2c6d48bc70a33abc7880cdbde36da55d650f3ae7313386",
                "md5": "628904603dc8dca7ebb3538de45cb0a6",
                "sha256": "849b9e2987ef615f079d07b3dc099330c1f8fcd9ad4f18423c6738eb6b2ea64b"
            },
            "downloads": -1,
            "filename": "pybughunt-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "628904603dc8dca7ebb3538de45cb0a6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 18627,
            "upload_time": "2025-08-09T14:37:20",
            "upload_time_iso_8601": "2025-08-09T14:37:20.902905Z",
            "url": "https://files.pythonhosted.org/packages/0f/3b/2dc4356e4f415e2c6d48bc70a33abc7880cdbde36da55d650f3ae7313386/pybughunt-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-09 14:37:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Preksha-7",
    "github_project": "pybughunt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pybughunt"
}
        
Elapsed time: 2.42121s