44These scripts provide centralized development commands through Poetry.
55"""
66
7+ import glob
78import os
89import shutil
910import subprocess
1011import sys
1112from pathlib import Path
1213
14+ # Constants
15+ PYTHON_CLIENT_DIR = "terminusdb_client/"
16+ RUNNING_FLAKE8_MSG = "Running flake8..."
17+ RUNNING_RUFF_MSG = "Running ruff..."
18+ RUFF_WARNING_MSG = "⚠️ Ruff found some issues it couldn't fix automatically:\n Run 'poetry run dev ruff' to see all issues"
1319# Constants for pytest arguments
1420PYTEST_TB_SHORT = "--tb=short"
1521PYTEST_COV = "--cov=terminusdb_client"
@@ -56,75 +62,64 @@ def install():
5662
5763
5864def format ():
59- """Format code with shed ."""
65+ """Format code with black and ruff (no auto-commits) ."""
6066 print ("Formatting code..." )
61- run_command (["poetry" , "run" , "shed" ])
67+ # Find all Python files and format them
68+ python_files = glob .glob ("terminusdb_client/**/*.py" , recursive = True )
69+ if python_files :
70+ # Run black for formatting
71+ print ("Running black..." )
72+ run_command (["poetry" , "run" , "black" ] + python_files )
73+ # Run ruff for import sorting and other fixes (ignore unfixed errors)
74+ print (RUNNING_RUFF_MSG )
75+ try :
76+ run_command (["poetry" , "run" , "ruff" , "check" , "--fix" , PYTHON_CLIENT_DIR ])
77+ except subprocess .CalledProcessError :
78+ print (RUFF_WARNING_MSG )
79+ else :
80+ print ("No Python files found to format." )
6281
6382
6483def lint ():
6584 """Run linting checks (read-only)."""
6685 print ("Running linting checks..." )
6786
68- # Check code formatting with shed
69- print ("Checking code formatting with shed..." )
70- temp_dir = Path ("/tmp/terminusdb-lint-check" )
71- temp_dir .mkdir (exist_ok = True )
72-
73- try :
74- # Copy code to temp directory
75- src_dir = Path ("terminusdb_client" )
76- if src_dir .exists ():
77- shutil .copytree (src_dir , temp_dir / src_dir .name , dirs_exist_ok = True )
78-
79- # Initialize git repo in temp directory if not exists
80- subprocess .run (["git" , "init" ], cwd = temp_dir , capture_output = True )
81- subprocess .run (["git" , "config" , "user.email" , "test@example.com" ], cwd = temp_dir , capture_output = True )
82- subprocess .run (["git" , "config" , "user.name" , "Test User" ], cwd = temp_dir , capture_output = True )
83- subprocess .run (["git" , "add" , "." ], cwd = temp_dir , capture_output = True )
84- subprocess .run (["git" , "commit" , "-m" , "initial" ], cwd = temp_dir , capture_output = True )
85-
86- # Run shed in temp directory
87- subprocess .run (
88- ["poetry" , "run" , "shed" ],
89- cwd = temp_dir ,
90- capture_output = True
91- )
92-
93- # Check if any files were modified
94- git_result = subprocess .run (
95- ["git" , "status" , "--porcelain" ],
96- cwd = temp_dir ,
97- capture_output = True ,
98- text = True
99- )
100-
101- if git_result .returncode != 0 or git_result .stdout .strip ():
102- print ("❌ Code formatting issues found. Run 'poetry run dev lint-fix' to fix." )
103- sys .exit (1 )
104- else :
105- print ("✅ Code formatting is correct." )
106- finally :
107- # Clean up
108- shutil .rmtree (temp_dir , ignore_errors = True )
109-
11087 # Run flake8
111- print ("Running flake8..." )
88+ print (RUNNING_FLAKE8_MSG )
11289 run_command (["poetry" , "run" , "flake8" , "terminusdb_client" ])
11390
11491
11592def flake8 ():
11693 """Run flake8 linting only."""
117- print ("Running flake8..." )
94+ print (RUNNING_FLAKE8_MSG )
11895 run_command (["poetry" , "run" , "flake8" , "terminusdb_client" ])
11996
12097
98+ def ruff ():
99+ """Run ruff linting only."""
100+ print (RUNNING_RUFF_MSG )
101+ run_command (["poetry" , "run" , "ruff" , "check" , PYTHON_CLIENT_DIR ])
102+
103+
121104def lint_fix ():
122105 """Run linting and fix issues automatically."""
123106 print ("Running linting fixes..." )
124107
125- # Format code with shed
126- print ("Fixing code formatting with shed..." )
127- run_command (["poetry" , "run" , "shed" ])
108+ # Format code with black and ruff
109+ print ("Fixing code formatting..." )
110+ python_files = glob .glob ("terminusdb_client/**/*.py" , recursive = True )
111+ if python_files :
112+ # Run black for formatting
113+ print ("Running black..." )
114+ run_command (["poetry" , "run" , "black" ] + python_files )
115+ # Run ruff for import sorting and other fixes
116+ print (RUNNING_RUFF_MSG )
117+ try :
118+ run_command (["poetry" , "run" , "ruff" , "check" , "--fix" , PYTHON_CLIENT_DIR ])
119+ except subprocess .CalledProcessError :
120+ print (RUFF_WARNING_MSG )
121+ else :
122+ print ("No Python files found to format." )
128123
129124 print ("✅ Linting fixes completed!" )
130125 print ("Note: Some issues (like flake8 violations) may need manual fixes." )
@@ -253,19 +248,36 @@ def pr():
253248 # 1. Clean
254249 clean ()
255250
256- # 2. Format
257- format ()
251+ # 2. Check formatting (don't fix)
252+ print ("\n Checking code formatting..." )
253+ try :
254+ run_command (["poetry" , "run" , "black" , "--check" , "--diff" , "terminusdb_client/" ])
255+ print ("✅ Black formatting is correct." )
256+ except subprocess .CalledProcessError :
257+ print ("❌ Black formatting issues found." )
258+ print (" Run 'poetry run dev format' to fix formatting issues" )
259+ sys .exit (1 )
258260
259261 # 3. Lint
260262 lint ()
263+
264+ # 4. Check ruff for any remaining issues
265+ print ("\n Checking for ruff issues..." )
266+ try :
267+ run_command (["poetry" , "run" , "ruff" , "check" , PYTHON_CLIENT_DIR ])
268+ print ("✅ No ruff issues found." )
269+ except subprocess .CalledProcessError :
270+ print ("❌ Ruff issues found. Please fix them manually." )
271+ print (" Run 'poetry run dev ruff' to see all issues" )
272+ sys .exit (1 )
261273
262- # 4 . Run all tests
274+ # 5 . Run all tests
263275 test_all ()
264276
265277 print ("\n All PR preparation checks completed successfully!" )
266278 print ("\n Summary of checks performed:" )
267- print (" ✓ Code formatted with shed " )
268- print (" ✓ Linting passed (flake8, shed check)" )
279+ print (" ✓ Code formatting is correct (black, ruff) " )
280+ print (" ✓ Linting passed (flake8, ruff check)" )
269281 print (" ✓ All tests passed (unit + integration)" )
270282 print (" ✓ Coverage report generated" )
271283 print ("\n Your PR is ready for submission!" )
@@ -279,10 +291,11 @@ def main():
279291 print ("\n Available commands:" )
280292 print (" init-dev - Initialize development environment" )
281293 print (" install-dev - Install package in editable mode" )
282- print (" format - Format code with shed " )
283- print (" lint - Run linting checks (read-only)" )
294+ print (" format - Format code with black and ruff " )
295+ print (" lint - Run flake8 linting (read-only)" )
284296 print (" lint-fix - Run linting and fix issues automatically" )
285297 print (" flake8 - Run flake8 linting only" )
298+ print (" ruff - Run ruff linting only" )
286299 print (" check - Run all static analysis checks" )
287300 print (" test - Run unit tests" )
288301 print (" test-unit - Run unit tests only" )
@@ -302,10 +315,11 @@ def main():
302315 print ("\n Available commands:" )
303316 print (" init-dev - Initialize development environment" )
304317 print (" install-dev - Install package in editable mode" )
305- print (" format - Format code with shed " )
306- print (" lint - Run linting checks (read-only)" )
318+ print (" format - Format code with black and ruff " )
319+ print (" lint - Run flake8 linting (read-only)" )
307320 print (" lint-fix - Run linting and fix issues automatically" )
308321 print (" flake8 - Run flake8 linting only" )
322+ print (" ruff - Run ruff linting only" )
309323 print (" check - Run all static analysis checks" )
310324 print (" test - Run unit tests" )
311325 print (" test-unit - Run unit tests only" )
@@ -326,6 +340,7 @@ def main():
326340 "lint" : lint ,
327341 "lint-fix" : lint_fix ,
328342 "flake8" : flake8 ,
343+ "ruff" : ruff ,
329344 "check" : check ,
330345 "test" : test ,
331346 "test-unit" : test_unit ,
0 commit comments