Skip to content

Commit f1555f8

Browse files
authored
Merge pull request #6 from BruinGrowly/fix-harmonizer-bug-and-add-gitignore
feat: Finalize project professionalization
2 parents f753b7d + 5e86424 commit f1555f8

File tree

10 files changed

+121
-46
lines changed

10 files changed

+121
-46
lines changed

.isort.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[settings]
2+
profile = black

.pre-commit-config.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# .pre-commit-config.yaml
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.6.0
5+
hooks:
6+
- id: trailing-whitespace
7+
- id: end-of-file-fixer
8+
- id: check-yaml
9+
- id: check-added-large-files
10+
11+
- repo: https://github.com/psf/black
12+
rev: 24.8.0
13+
hooks:
14+
- id: black
15+
16+
- repo: https://github.com/pycqa/flake8
17+
rev: 7.0.0
18+
hooks:
19+
- id: flake8
20+
21+
- repo: https://github.com/pycqa/isort
22+
rev: 5.13.2
23+
hooks:
24+
- id: isort

README.md

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Python Code Harmonizer (v1.1)
22

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

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

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

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

13-
-----
13+
---
1414

1515
## The Core Idea: Finding "Disharmony"
1616

@@ -20,11 +20,11 @@ Traditional tools check if your syntax is *valid*, but not if your logic is *sou
2020
2121
It finds "bugs" where the `Intent` (the function's name) is in logical contradiction with the `Execution` (the code inside it).
2222

23-
* **`Intent`:** `def get_user_by_id(...)`
24-
* **`Execution`:** `... db.delete_user(...)`
25-
* **Result:** `!! DISHARMONY DETECTED !!`
23+
* **`Intent`:** `def get_user_by_id(...)`
24+
* **`Execution`:** `... db.delete_user(...)`
25+
* **Result:** `!! DISHARMONY DETECTED !!`
2626

27-
-----
27+
---
2828

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

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

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

41-
-----
41+
---
4242

43-
## How to Use (The "Execution")
43+
## How to Use
4444

45-
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.
46-
47-
### Setup
45+
### Installation
4846

4947
1. **Clone the repository:**
50-
5148
```sh
5249
git clone https://github.com/BruinGrowly/Python-Code-Harmonizer.git
5350
cd Python-Code-Harmonizer
5451
```
5552

56-
2. **Ensure all files are present:**
57-
58-
* `divine_invitation_engine_V2.py` (The Engine)
59-
* `ast_semantic_parser.py` (The Parser)
60-
* `anchor_analysis_V2.py` (The Proof)
61-
* `PythonCodeHarmonizer.py` (The Application)
62-
63-
### Step 1: Run the "Proof"
64-
65-
First, you can validate the V2 engine and its "Anchor Point" axiom by running the harmonized analysis script.
66-
67-
```sh
68-
python anchor_analysis_V2.py
69-
```
70-
71-
*(You should see a successful report validating the (1,1,1,1) Anchor Point.)*
53+
2. **Install the project:**
54+
* This project is packaged and can be installed using `pip`. It is recommended to do this in a virtual environment.
55+
```sh
56+
pip install .
57+
```
7258

73-
### Step 2: Run the "Harmonizer"
59+
### Running the Harmonizer
7460

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

7763
```sh
78-
python PythonCodeHarmonizer.py examples/test_code.py
64+
harmonizer examples/test_code.py
7965
```
8066

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

9278
Analyzing file: examples/test_code.py
9379
----------------------------------------------------------------------
9480
FUNCTION NAME | INTENT-EXECUTION DISHARMONY
9581
-----------------------------|--------------------------------
96-
check_user_permissions | !! DISHARMONY (Score: 0.87)
82+
delete_user | !! DISHARMONY (Score: 1.41)
83+
check_user_permissions | !! DISHARMONY (Score: 0.62)
9784
get_user_by_id | ✓ HARMONIOUS
85+
query | ✓ HARMONIOUS
9886
======================================================================
9987
Analysis Complete.
10088
```
10189
10290
*(Note: The exact score may vary, but the "Disharmony" will be detected.)*
10391
104-
-----
92+
---
93+
94+
## Development & Contribution
95+
96+
This project is now equipped with a full suite of professional development tools to ensure code quality and stability.
97+
98+
### Setup for Development
99+
100+
If you wish to contribute, please install the project in "editable" mode along with the development dependencies:
101+
102+
```sh
103+
# It is recommended to use a virtual environment
104+
pip install -r requirements.txt
105+
pip install -e .
106+
```
107+
108+
### Running Tests and Quality Checks
109+
110+
* **Run the full test suite:**
111+
```sh
112+
pytest
113+
```
114+
* **Run code quality checks:**
115+
* This project uses `pre-commit` to automatically run `black`, `flake8`, and `isort`. To run the checks manually:
116+
```sh
117+
pre-commit run --all-files
118+
```
119+
120+
For more detailed information, please see the [CONTRIBUTING.md](CONTRIBUTING.md) file.
121+
122+
---
105123

106124
## The Philosophy (Why This is Free)
107125

anchor_analysis_V2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
production-ready V2 engine.
1111
"""
1212

13-
import sys
1413
import math
14+
import sys
1515

1616
# --- V2 ENGINE IMPORT ---
1717
# This now imports your production-ready V2 engine

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
pytest
22
black
33
flake8
4+
isort
5+
pre-commit

src/divine_invitation_engine_V2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
Implements all discovered frameworks with enhanced performance and reliability.
66
"""
77

8-
import re
98
import math
9+
import re
1010
from dataclasses import dataclass
11-
from typing import List, Dict, Tuple, Optional, Set
1211
from enum import Enum
12+
from typing import Dict, List, Optional, Set, Tuple
1313

1414

1515
class Dimension(Enum):

src/harmonizer/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"""
1818

1919
import ast
20-
import sys
2120
import os
21+
import sys
2222
from typing import Dict
2323

2424
# --- COMPONENT IMPORTS ---

tests/test_engine.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# tests/test_engine.py
22

33
import pytest
4-
from src.divine_invitation_engine_V2 import (
5-
DivineInvitationSemanticEngine,
6-
Coordinates,
7-
)
4+
5+
from src.divine_invitation_engine_V2 import Coordinates, DivineInvitationSemanticEngine
86

97

108
@pytest.fixture(scope="module")

tests/test_harmonizer.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# tests/test_harmonizer.py
22

3+
import os
4+
import tempfile
5+
36
import pytest
7+
48
from src.harmonizer.main import PythonCodeHarmonizer
5-
import tempfile
6-
import os
79

810
# A self-contained Python script to be used for testing.
911
# It contains one harmonious function and one disharmonious one.
@@ -68,3 +70,31 @@ def test_harmonizer_end_to_end_analysis(harmonizer, temp_python_file):
6870
# The 'check_permissions' function should be disharmonious (high score).
6971
# Intent: check, truth. Execution: delete, force.
7072
assert report["check_permissions"] > harmonizer.disharmony_threshold
73+
74+
75+
def test_harmonizer_on_empty_file(harmonizer, temp_python_file):
76+
"""Tests that the harmonizer handles an empty file gracefully."""
77+
# Overwrite the temp file to be empty
78+
with open(temp_python_file, "w") as f:
79+
f.write("")
80+
81+
report = harmonizer.analyze_file(temp_python_file)
82+
assert report == {}
83+
84+
85+
def test_harmonizer_on_file_with_only_comments(harmonizer, temp_python_file):
86+
"""Tests that the harmonizer handles a file with only comments."""
87+
with open(temp_python_file, "w") as f:
88+
f.write("# This is a comment\\n# And another one")
89+
90+
report = harmonizer.analyze_file(temp_python_file)
91+
assert report == {}
92+
93+
94+
def test_harmonizer_on_syntax_error(harmonizer, temp_python_file):
95+
"""Tests that the harmonizer catches SyntaxError and returns an empty report."""
96+
with open(temp_python_file, "w") as f:
97+
f.write("def invalid_syntax:")
98+
99+
report = harmonizer.analyze_file(temp_python_file)
100+
assert report == {}

tests/test_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# tests/test_parser.py
22

33
import pytest
4+
45
from src.ast_semantic_parser import AST_Semantic_Parser
56
from src.divine_invitation_engine_V2 import DivineInvitationSemanticEngine
67

0 commit comments

Comments
 (0)