Skip to content

Commit 593b45d

Browse files
committed
style: Format code with black and isort to fix CI
1 parent 7eb25c2 commit 593b45d

17 files changed

+487
-262
lines changed

check_harmony.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,59 @@
1111
from harmonizer.legacy_mapper import LegacyCodeMapper
1212
from harmonizer.config import ConfigLoader
1313

14-
def check_harmony(target_dir: str = ".", config_path: str = None, verbose: bool = False):
14+
15+
def check_harmony(
16+
target_dir: str = ".", config_path: str = None, verbose: bool = False
17+
):
1518
print(f"Running LJPW Harmony Check on: {os.path.abspath(target_dir)}")
1619
print("=" * 60)
17-
20+
1821
# Load config explicitly if provided, otherwise auto-load
19-
# Note: LegacyCodeMapper loads config automatically from target_dir,
22+
# Note: LegacyCodeMapper loads config automatically from target_dir,
2023
# but if we want to override with a specific file, we might need to adjust ConfigLoader.
2124
# For now, we'll rely on auto-loading from target_dir.
22-
25+
2326
mapper = LegacyCodeMapper(target_dir, quiet=not verbose)
2427
mapper.analyze_codebase(show_progress=True)
25-
28+
2629
failures = []
2730
warnings = []
28-
31+
2932
config = mapper.config
3033
print(f"\n--- CONFIGURATION ---")
3134
print(f"Max Disharmony: {config.max_disharmony}")
3235
print(f"Max Imbalance: {config.max_imbalance}")
3336
print(f"Min Density: {config.min_density}")
34-
37+
3538
print("\n--- QUALITY GATES ---")
36-
39+
3740
for file_path, analysis in mapper.file_analyses.items():
3841
rel_path = os.path.relpath(file_path, target_dir)
39-
42+
4043
# 1. Critical Disharmony Gate
4144
if analysis.avg_disharmony > config.max_disharmony:
42-
failures.append(f"[CRITICAL] {rel_path}: Disharmony {analysis.avg_disharmony:.2f} > {config.max_disharmony}")
43-
45+
failures.append(
46+
f"[CRITICAL] {rel_path}: Disharmony {analysis.avg_disharmony:.2f} > {config.max_disharmony}"
47+
)
48+
4449
# Check Architectural Smells
4550
for smell in mapper.architectural_smells:
4651
if smell.smell_type == "Unnatural Imbalance" and smell.severity == "HIGH":
4752
failures.append(f"[IMBALANCE] {smell.file_path}: {smell.description}")
48-
53+
4954
if smell.smell_type == "Anemic Component" and smell.severity == "HIGH":
5055
# Treat Anemic Components as warnings for now, unless critical
5156
warnings.append(f"[ANEMIC] {smell.file_path}: {smell.description}")
52-
57+
5358
if smell.smell_type == "God File" and smell.severity == "HIGH":
54-
failures.append(f"[GOD FILE] {smell.file_path}: {smell.description}")
59+
failures.append(f"[GOD FILE] {smell.file_path}: {smell.description}")
5560

5661
# Report Results
5762
if warnings:
5863
print("\nWARNINGS:")
5964
for w in warnings:
6065
print(w)
61-
66+
6267
if failures:
6368
print("\nFAILURES:")
6469
for f in failures:
@@ -69,15 +74,21 @@ def check_harmony(target_dir: str = ".", config_path: str = None, verbose: bool
6974
print("\nHarmony Check PASSED. The system is in balance.")
7075
sys.exit(0)
7176

77+
7278
def main():
7379
parser = argparse.ArgumentParser(description="LJPW Harmony Check")
74-
parser.add_argument("target", nargs="?", default=".", help="Target directory to analyze")
80+
parser.add_argument(
81+
"target", nargs="?", default=".", help="Target directory to analyze"
82+
)
7583
parser.add_argument("--config", help="Path to configuration file (optional)")
76-
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output")
77-
84+
parser.add_argument(
85+
"-v", "--verbose", action="store_true", help="Enable verbose output"
86+
)
87+
7888
args = parser.parse_args()
79-
89+
8090
check_harmony(args.target, args.config, args.verbose)
8191

92+
8293
if __name__ == "__main__":
8394
main()

examples/demo_ljpw_v4.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from harmonizer.ljpw_baselines import DynamicLJPWv3, ReferencePoints
1818

19+
1920
def run_demo():
2021
print("=" * 60)
2122
print("LJPW v4.0 Dynamic Model Demo")
@@ -30,7 +31,7 @@ def run_demo():
3031

3132
# Initial State: High Power (0.9), Low Wisdom (0.2), Low Love (0.2), Moderate Justice (0.5)
3233
initial_state = (0.2, 0.5, 0.9, 0.2)
33-
34+
3435
print(f"Initial State:")
3536
print(f" Love: {initial_state[0]:.2f}")
3637
print(f" Justice: {initial_state[1]:.2f}")
@@ -45,10 +46,10 @@ def run_demo():
4546
history = simulator.simulate(initial_state, duration=duration, dt=dt)
4647

4748
# Get final state
48-
final_L = history['L'][-1]
49-
final_J = history['J'][-1]
50-
final_P = history['P'][-1]
51-
final_W = history['W'][-1]
49+
final_L = history["L"][-1]
50+
final_J = history["J"][-1]
51+
final_P = history["P"][-1]
52+
final_W = history["W"][-1]
5253

5354
print("-" * 60)
5455
print(f"Final State:")
@@ -67,27 +68,33 @@ def run_demo():
6768

6869
print("\nDisplaying trajectory plot...")
6970
# simulator.plot_simulation(history) # This blocks, so we manually plot and save
70-
71-
plt.style.use('seaborn-v0_8-whitegrid')
71+
72+
plt.style.use("seaborn-v0_8-whitegrid")
7273
fig, ax = plt.subplots(figsize=(12, 7))
73-
ax.plot(history['t'], history['L'], label='Love (L)', color='crimson', lw=2)
74-
ax.plot(history['t'], history['J'], label='Justice (J)', color='royalblue', lw=2)
75-
ax.plot(history['t'], history['P'], label='Power (P)', color='darkgreen', lw=2)
76-
ax.plot(history['t'], history['W'], label='Wisdom (W)', color='purple', lw=2)
77-
74+
ax.plot(history["t"], history["L"], label="Love (L)", color="crimson", lw=2)
75+
ax.plot(history["t"], history["J"], label="Justice (J)", color="royalblue", lw=2)
76+
ax.plot(history["t"], history["P"], label="Power (P)", color="darkgreen", lw=2)
77+
ax.plot(history["t"], history["W"], label="Wisdom (W)", color="purple", lw=2)
78+
7879
NE = ReferencePoints.NATURAL_EQUILIBRIUM
7980
for i, val in enumerate(NE):
80-
ax.axhline(y=val, color=['crimson', 'royalblue', 'darkgreen', 'purple'][i], linestyle='--', alpha=0.3)
81-
81+
ax.axhline(
82+
y=val,
83+
color=["crimson", "royalblue", "darkgreen", "purple"][i],
84+
linestyle="--",
85+
alpha=0.3,
86+
)
87+
8288
ax.set_title("LJPW v3.0 System Evolution (Non-Linear, RK4)")
8389
ax.set_xlabel("Time")
8490
ax.set_ylabel("Dimension Value")
8591
ax.set_ylim(0, 1.2)
8692
ax.legend()
87-
88-
output_path = 'ljpw_v4_demo_plot.png'
93+
94+
output_path = "ljpw_v4_demo_plot.png"
8995
plt.savefig(output_path)
9096
print(f"Plot saved to {output_path}")
9197

98+
9299
if __name__ == "__main__":
93100
run_demo()

examples/realistic_code_samples.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
Demonstrates real-world functions with proper LJPW semantic mapping.
44
"""
55

6-
76
# ============================================================================
87
# HARMONIOUS FUNCTIONS (Intent matches Execution)
98
# ============================================================================
109

10+
1111
def get_user_by_id(user_id):
1212
"""
1313
Retrieve user information from database.
@@ -60,6 +60,7 @@ def send_welcome_email(user_email):
6060
# DISHARMONIOUS FUNCTIONS (Intent contradicts Execution)
6161
# ============================================================================
6262

63+
6364
def check_user_permissions(user_token):
6465
"""
6566
Check user permissions.
@@ -123,6 +124,7 @@ def calculate_and_notify(items):
123124
# COMPLEX MIXED FUNCTIONS (Multiple dimensions, properly named)
124125
# ============================================================================
125126

127+
126128
def fetch_validate_and_save_user(user_id, updates):
127129
"""
128130
Fetch user, validate updates, and save changes.
@@ -168,6 +170,7 @@ def process_order_with_notification(order_id):
168170
# DIMENSION-SPECIFIC EXAMPLES
169171
# ============================================================================
170172

173+
171174
# Pure WISDOM functions
172175
def calculate_total_price(items):
173176
"""Pure computation - returns information."""
@@ -220,17 +223,14 @@ def broadcast_system_message(message):
220223

221224
def merge_user_profiles(profile1, profile2):
222225
"""Pure integration - combines data."""
223-
return {
224-
**profile1,
225-
**profile2,
226-
"merged_at": datetime.now()
227-
}
226+
return {**profile1, **profile2, "merged_at": datetime.now()}
228227

229228

230229
# ============================================================================
231230
# Mock objects for testing
232231
# ============================================================================
233232

233+
234234
class Database:
235235
def query(self, sql):
236236
return {"id": 1, "name": "Test User"}

harmonizer/config.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,33 @@
2424
except ImportError:
2525
yaml = None
2626

27+
2728
@dataclass
2829
class HarmonizerConfig:
2930
# Thresholds
3031
max_disharmony: float = 1.0
3132
max_imbalance: float = 0.8
3233
min_density: float = 0.1
33-
34+
3435
# Paths
35-
exclude_patterns: List[str] = field(default_factory=lambda: [
36-
"venv", ".venv", "__pycache__", ".git", "build", "dist", ".pytest_cache", "tests"
37-
])
36+
exclude_patterns: List[str] = field(
37+
default_factory=lambda: [
38+
"venv",
39+
".venv",
40+
"__pycache__",
41+
".git",
42+
"build",
43+
"dist",
44+
".pytest_cache",
45+
"tests",
46+
]
47+
)
3848
report_output: str = "harmonizer_report.html"
39-
49+
4050
# Analysis
4151
complexity_weight: float = 0.2 # For dynamic simulation
4252

53+
4354
class ConfigLoader:
4455
@staticmethod
4556
def load(target_dir: str = ".") -> HarmonizerConfig:
@@ -51,7 +62,7 @@ def load(target_dir: str = ".") -> HarmonizerConfig:
5162
3. Defaults
5263
"""
5364
config = HarmonizerConfig()
54-
65+
5566
# 1. Try harmonizer.yaml
5667
yaml_path = os.path.join(target_dir, "harmonizer.yaml")
5768
if os.path.exists(yaml_path) and yaml:
@@ -77,23 +88,29 @@ def load(target_dir: str = ".") -> HarmonizerConfig:
7788
print(f"Loaded config from {toml_path}")
7889
except Exception as e:
7990
print(f"Warning: Failed to load {toml_path}: {e}")
80-
91+
8192
return config
8293

8394
@staticmethod
8495
def _update_config(config: HarmonizerConfig, data: Dict[str, Any]):
8596
"""Update config object with dictionary data"""
8697
if "thresholds" in data:
8798
t = data["thresholds"]
88-
if "max_disharmony" in t: config.max_disharmony = float(t["max_disharmony"])
89-
if "max_imbalance" in t: config.max_imbalance = float(t["max_imbalance"])
90-
if "min_density" in t: config.min_density = float(t["min_density"])
91-
99+
if "max_disharmony" in t:
100+
config.max_disharmony = float(t["max_disharmony"])
101+
if "max_imbalance" in t:
102+
config.max_imbalance = float(t["max_imbalance"])
103+
if "min_density" in t:
104+
config.min_density = float(t["min_density"])
105+
92106
if "paths" in data:
93107
p = data["paths"]
94-
if "exclude" in p: config.exclude_patterns = p["exclude"]
95-
if "report" in p: config.report_output = p["report"]
96-
108+
if "exclude" in p:
109+
config.exclude_patterns = p["exclude"]
110+
if "report" in p:
111+
config.report_output = p["report"]
112+
97113
if "analysis" in data:
98114
a = data["analysis"]
99-
if "complexity_weight" in a: config.complexity_weight = float(a["complexity_weight"])
115+
if "complexity_weight" in a:
116+
config.complexity_weight = float(a["complexity_weight"])

0 commit comments

Comments
 (0)