Skip to content

Instantly share code, notes, and snippets.

@suryastef
Created May 19, 2025 20:17
Show Gist options
  • Select an option

  • Save suryastef/0b1b29bbcfdc2f5e0efeaa21db7f90f9 to your computer and use it in GitHub Desktop.

Select an option

Save suryastef/0b1b29bbcfdc2f5e0efeaa21db7f90f9 to your computer and use it in GitHub Desktop.
pylynt + pyright
#!/usr/bin/env python3
"""
Combined Python code checker that runs both Pyright and Pylint
"""
import subprocess
import sys
from pathlib import Path
def run_pyright(target_path: str) -> bool:
"""Run Pyright type checker and return True if successful"""
try:
print("\n" + "="*50)
print("Running Pyright type checking...")
print("="*50 + "\n")
result = subprocess.run(
["pyright", target_path],
check=False,
text=True,
capture_output=True
)
print(result.stdout)
if result.stderr:
print(result.stderr, file=sys.stderr)
return result.returncode == 0
except FileNotFoundError:
print("Error: Pyright not found. Install with 'npm install -g pyright'", file=sys.stderr)
return False
def run_pylint(target_path: str) -> bool:
"""Run Pylint and return True if successful"""
try:
print("\n" + "="*50)
print("Running Pylint...")
print("="*50 + "\n")
result = subprocess.run(
["pylint", target_path],
check=False,
text=True,
capture_output=True
)
print(result.stdout)
if result.stderr:
print(result.stderr, file=sys.stderr)
return result.returncode == 0
except FileNotFoundError:
print("Error: Pylint not found. Install with 'pip install pylint'", file=sys.stderr)
return False
def main():
"""Main Function"""
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} <python_file_or_directory>")
sys.exit(1)
target = sys.argv[1]
if not Path(target).exists():
print(f"Error: Target '{target}' does not exist", file=sys.stderr)
sys.exit(1)
pyright_success = run_pyright(target)
pylint_success = run_pylint(target)
print("\n" + "="*50)
print("Summary:")
print(f"Pyright: {'SUCCESS' if pyright_success else 'FAILED'}")
print(f"Pylint: {'SUCCESS' if pylint_success else 'FAILED'}")
print("="*50 + "\n")
if not pyright_success or not pylint_success:
sys.exit(1)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment