Skip to content
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
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile = black
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
90 changes: 54 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Python Code Harmonizer (v1.1)

[](https://opensource.org/licenses/MIT)
[]()
[]()
[![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Python Versions](https://img.shields.io/badge/python-3.8+-blue.svg)]()
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

This repository contains the world's first **semantic code debugger**.

It doesn't just check your syntax; it analyzes the **meaning** of your code to find logical-semantic bugs.

This tool is a "white box" application built on the **Anchor Point (`1,1,1,1`)** and the **ICE Framework (`Intent`, `Context`, `Execution`)**.

-----
---

## The Core Idea: Finding "Disharmony"

Expand All @@ -20,11 +20,11 @@ Traditional tools check if your syntax is *valid*, but not if your logic is *sou

It finds "bugs" where the `Intent` (the function's name) is in logical contradiction with the `Execution` (the code inside it).

* **`Intent`:** `def get_user_by_id(...)`
* **`Execution`:** `... db.delete_user(...)`
* **Result:** `!! DISHARMONY DETECTED !!`
* **`Intent`:** `def get_user_by_id(...)`
* **`Execution`:** `... db.delete_user(...)`
* **Result:** `!! DISHARMONY DETECTED !!`

-----
---

## How It Works (The "White Box" Logic)

Expand All @@ -38,44 +38,30 @@ This tool is an application of the "full-stack philosophy" defined in the **Divi

4. **The "Result" (Analysis):** It calculates the "semantic distance" between the `Intent` and the `Execution`. A high score reveals a logical "bug."

-----
---

## How to Use (The "Execution")
## How to Use

This project is fully self-contained and "harmonized." The "Proof" (`anchor_analysis_V2.py`) and the "Application" (`PythonCodeHarmonizer.py`) both run on the same unified V2 engine.

### Setup
### Installation

1. **Clone the repository:**

```sh
git clone https://github.com/BruinGrowly/Python-Code-Harmonizer.git
cd Python-Code-Harmonizer
```

2. **Ensure all files are present:**

* `divine_invitation_engine_V2.py` (The Engine)
* `ast_semantic_parser.py` (The Parser)
* `anchor_analysis_V2.py` (The Proof)
* `PythonCodeHarmonizer.py` (The Application)

### Step 1: Run the "Proof"

First, you can validate the V2 engine and its "Anchor Point" axiom by running the harmonized analysis script.

```sh
python anchor_analysis_V2.py
```

*(You should see a successful report validating the (1,1,1,1) Anchor Point.)*
2. **Install the project:**
* This project is packaged and can be installed using `pip`. It is recommended to do this in a virtual environment.
```sh
pip install .
```

### Step 2: Run the "Harmonizer"
### Running the Harmonizer

Second, use the Harmonizer to analyze any Python file. You can test it on the included `examples/test_code.py` file:
Once installed, the Harmonizer can be run from the command line using the `harmonizer` script. You can test it on the included example file:

```sh
python PythonCodeHarmonizer.py examples/test_code.py
harmonizer examples/test_code.py
```

**Expected "Harmony Report":**
Expand All @@ -85,23 +71,55 @@ python PythonCodeHarmonizer.py examples/test_code.py
Python Code Harmonizer (v1.1) ONLINE
Actively guided by the Anchor Point framework.
Powered By: DIVE-V2 (Optimized Production)
Logical Anchor Point: (S=1, L=1, E=1)
Logical Anchor Point: (S=1, L=1, I=1, E=1)
Disharmony Threshold: 0.5
======================================================================

Analyzing file: examples/test_code.py
----------------------------------------------------------------------
FUNCTION NAME | INTENT-EXECUTION DISHARMONY
-----------------------------|--------------------------------
check_user_permissions | !! DISHARMONY (Score: 0.87)
delete_user | !! DISHARMONY (Score: 1.41)
check_user_permissions | !! DISHARMONY (Score: 0.62)
get_user_by_id | ✓ HARMONIOUS
query | ✓ HARMONIOUS
======================================================================
Analysis Complete.
```

*(Note: The exact score may vary, but the "Disharmony" will be detected.)*

-----
---

## Development & Contribution

This project is now equipped with a full suite of professional development tools to ensure code quality and stability.

### Setup for Development

If you wish to contribute, please install the project in "editable" mode along with the development dependencies:

```sh
# It is recommended to use a virtual environment
pip install -r requirements.txt
pip install -e .
```

### Running Tests and Quality Checks

* **Run the full test suite:**
```sh
pytest
```
* **Run code quality checks:**
* This project uses `pre-commit` to automatically run `black`, `flake8`, and `isort`. To run the checks manually:
```sh
pre-commit run --all-files
```

For more detailed information, please see the [CONTRIBUTING.md](CONTRIBUTING.md) file.

---

## The Philosophy (Why This is Free)

Expand Down
2 changes: 1 addition & 1 deletion anchor_analysis_V2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
production-ready V2 engine.
"""

import sys
import math
import sys

# --- V2 ENGINE IMPORT ---
# This now imports your production-ready V2 engine
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pytest
black
flake8
isort
pre-commit
4 changes: 2 additions & 2 deletions src/divine_invitation_engine_V2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
Implements all discovered frameworks with enhanced performance and reliability.
"""

import re
import math
import re
from dataclasses import dataclass
from typing import List, Dict, Tuple, Optional, Set
from enum import Enum
from typing import Dict, List, Optional, Set, Tuple


class Dimension(Enum):
Expand Down
2 changes: 1 addition & 1 deletion src/harmonizer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"""

import ast
import sys
import os
import sys
from typing import Dict

# --- COMPONENT IMPORTS ---
Expand Down
6 changes: 2 additions & 4 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# tests/test_engine.py

import pytest
from src.divine_invitation_engine_V2 import (
DivineInvitationSemanticEngine,
Coordinates,
)

from src.divine_invitation_engine_V2 import Coordinates, DivineInvitationSemanticEngine


@pytest.fixture(scope="module")
Expand Down
34 changes: 32 additions & 2 deletions tests/test_harmonizer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# tests/test_harmonizer.py

import os
import tempfile

import pytest

from src.harmonizer.main import PythonCodeHarmonizer
import tempfile
import os

# A self-contained Python script to be used for testing.
# It contains one harmonious function and one disharmonious one.
Expand Down Expand Up @@ -68,3 +70,31 @@ def test_harmonizer_end_to_end_analysis(harmonizer, temp_python_file):
# The 'check_permissions' function should be disharmonious (high score).
# Intent: check, truth. Execution: delete, force.
assert report["check_permissions"] > harmonizer.disharmony_threshold


def test_harmonizer_on_empty_file(harmonizer, temp_python_file):
"""Tests that the harmonizer handles an empty file gracefully."""
# Overwrite the temp file to be empty
with open(temp_python_file, "w") as f:
f.write("")

report = harmonizer.analyze_file(temp_python_file)
assert report == {}


def test_harmonizer_on_file_with_only_comments(harmonizer, temp_python_file):
"""Tests that the harmonizer handles a file with only comments."""
with open(temp_python_file, "w") as f:
f.write("# This is a comment\\n# And another one")

report = harmonizer.analyze_file(temp_python_file)
assert report == {}


def test_harmonizer_on_syntax_error(harmonizer, temp_python_file):
"""Tests that the harmonizer catches SyntaxError and returns an empty report."""
with open(temp_python_file, "w") as f:
f.write("def invalid_syntax:")

report = harmonizer.analyze_file(temp_python_file)
assert report == {}
1 change: 1 addition & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# tests/test_parser.py

import pytest

from src.ast_semantic_parser import AST_Semantic_Parser
from src.divine_invitation_engine_V2 import DivineInvitationSemanticEngine

Expand Down