- __init__.py added to all folders - preparing docs - .gitignore updated - .vscode/settings.json updated - mypy.ini updated - pyproject.toml updated - plansandideas/Coding optimization plan.md added - plansandideas/REORGANIZATION.md added - scripts/lint.py added - scripts/setup_dev.py added - requirements-dev.txt added - and more.
109 lines
3.2 KiB
Python
109 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Development environment setup script."""
|
|
import os
|
|
import platform
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def check_python_version():
|
|
"""Ensure Python version meets minimum requirements."""
|
|
min_version = (3, 8)
|
|
current = sys.version_info[:2]
|
|
if current < min_version:
|
|
raise SystemError(
|
|
f"Python {min_version[0]}.{min_version[1]} or higher required"
|
|
)
|
|
|
|
|
|
def clean_existing_venv():
|
|
"""Remove existing virtual environment if present."""
|
|
venv_path = Path(".venv")
|
|
if venv_path.exists():
|
|
shutil.rmtree(venv_path)
|
|
|
|
|
|
def initialize_environment():
|
|
"""Create and initialize development environment."""
|
|
# Allow configurable venv path
|
|
venv_path = os.getenv("VENV_PATH", ".sandpypi_venv")
|
|
|
|
# Create and activate virtual environment
|
|
subprocess.run([sys.executable, "-m", "venv", venv_path], check=True)
|
|
|
|
# Get the correct paths based on OS
|
|
is_windows = platform.system() == "Windows"
|
|
scripts_path = "Scripts" if is_windows else "bin"
|
|
|
|
# Setup commands using virtual environment paths
|
|
pip_cmd = os.path.join(venv_path, scripts_path, "pip")
|
|
|
|
# Update pip and install dependencies
|
|
subprocess.run([pip_cmd, "install", "--upgrade", "pip"], check=True)
|
|
subprocess.run([pip_cmd, "install", "pre-commit"], check=True)
|
|
subprocess.run([pip_cmd, "install", "-e", ".[dev]"], check=True)
|
|
# Install and configure pre-commit hooks
|
|
precommit_cmd = os.path.join(venv_path, scripts_path, "pre-commit")
|
|
subprocess.run([precommit_cmd, "install"], check=True)
|
|
subprocess.run(
|
|
[precommit_cmd, "install", "--hook-type", "pre-push"], check=True
|
|
)
|
|
|
|
|
|
def setup_docs():
|
|
"""Initialize documentation structure."""
|
|
docs_path = Path("docs")
|
|
if not docs_path.exists():
|
|
subprocess.run(
|
|
[
|
|
os.path.join(
|
|
".venv",
|
|
"Scripts" if platform.system() == "Windows" else "bin",
|
|
"sphinx-quickstart",
|
|
),
|
|
"docs",
|
|
"--sep",
|
|
"--project=Sandpypi",
|
|
"--author=Stan44",
|
|
],
|
|
check=True,
|
|
)
|
|
|
|
|
|
def main():
|
|
"""Execute the complete development environment setup."""
|
|
try:
|
|
check_python_version()
|
|
clean_existing_venv()
|
|
# setup_git_hooks()
|
|
initialize_environment()
|
|
setup_docs()
|
|
|
|
print("\n✅ Development environment setup complete!")
|
|
print("\nNext steps:")
|
|
print("1. Activate your virtual environment:")
|
|
activate_cmd = (
|
|
"source .venv/Scripts/activate"
|
|
if platform.system() == "Windows"
|
|
else "source .venv/bin/activate"
|
|
)
|
|
print(activate_cmd)
|
|
print("2. Run tests: pytest")
|
|
print("3. Build docs: cd docs && make html")
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"\n❌ Setup failed: {e}")
|
|
sys.exit(1)
|
|
except (OSError, IOError) as e:
|
|
print(f"\n❌ File system error: {e}")
|
|
sys.exit(1)
|
|
except ImportError as e:
|
|
print(f"\n❌ Dependency error: {e}")
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|