spin

0.18 · active · verified Wed Apr 15

spin is a developer tool designed to simplify common tasks for scientific Python libraries, such as environment setup, testing, and documentation builds. It focuses on standardizing development workflows using `pyproject.toml`. Current version is 0.18, with releases occurring periodically to add features and fix bugs.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a minimal `spin` project (a `pyproject.toml` with a task) and then programmatically invoke a `spin` command using `subprocess`. While `spin` has a Python API (`spin.app.run_spin`), direct `subprocess` invocation is often more robust for quickstarts and automation, as `run_spin` can cause `sys.exit()`.

import os
import subprocess
import sys
import tempfile
from pathlib import Path

# Create a temporary project directory to run spin in
with tempfile.TemporaryDirectory() as tmpdir_name:
    project_path = Path(tmpdir_name)
    os.chdir(project_path)

    # Define a simple pyproject.toml with a 'hello' task
    pyproject_content = """
[project]
name = "my-spin-project"
version = "0.1.0"

[tool.spin]
tasks.hello = "echo Hello from spin!"
"""
    (project_path / "pyproject.toml").write_text(pyproject_content)

    print(f"Temporary project created at: {project_path}")
    print("Attempting to run 'spin hello' via subprocess...")

    try:
        # Invoke spin using `python -m spin` to simulate CLI execution
        # and allow the Python script to continue after spin completes.
        result = subprocess.run([sys.executable, '-m', 'spin', 'hello'],
                                capture_output=True, text=True, check=True)
        
        print("\n--- spin output ---")
        print(result.stdout.strip())
        print("--- end spin output ---")
        
        assert "Hello from spin!" in result.stdout
        print("Quickstart successful: 'spin hello' task executed and verified.")

    except subprocess.CalledProcessError as e:
        print(f"Error running spin command (exit code {e.returncode}):")
        print(f"Stdout: {e.stdout}")
        print(f"Stderr: {e.stderr}")
        sys.exit(1)
    except Exception as e:
        print(f"An unexpected error occurred: {e}")
        sys.exit(1)

view raw JSON →