spin
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
- breaking Support for `setup.py` was completely removed in version 0.16.0. All project configuration and `spin` task definitions must now reside in `pyproject.toml`.
- breaking The way arguments are passed to tasks changed significantly in version 0.10.0. Tasks now receive arguments as a list of strings directly, rather than a single concatenated string.
- gotcha By default, `spin install` attempts to use `conda` for environment creation if a `conda` executable is found in the system's PATH. If `conda` is not available, it falls back to `pip`.
- gotcha spin commands must be executed from the root directory of a project that contains a `pyproject.toml` file with a valid `[tool.spin]` section. Running `spin` from a subdirectory or without this configuration will lead to errors.
Install
-
pip install spin
Imports
- run_spin
from spin.app import run_spin
Quickstart
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)