Skip to main content

AST-based linter enforcing SciTeX reproducible research patterns

Project description

SciTeX Linter

SciTeX Linter

PyPI version Python Versions Documentation License

scitex.ai · docs · pip install scitex-linter


AST-based Python linter enforcing SciTeX reproducible research patterns.

Part of the SciTeX ecosystem — guides both human researchers and AI agents toward reproducible science.

Why SciTeX Linter?

SciTeX scripts follow strict patterns for reproducibility: @stx.session decorators, stx.io for provenance-tracked I/O, stx.stats for complete statistical reporting, and relative paths for portability. SciTeX Linter enforces these patterns at the AST level — catching issues before they become irreproducible results.

Quick Start

pip install scitex-linter
# Lint a file
scitex-linter check script.py

# Lint then execute
scitex-linter python experiment.py --strict

# List all 35 rules
scitex-linter rule

Five Interfaces

Interface For Description
🖥️ CLI Terminal users scitex-linter check, scitex-linter python
Format Auto-fix scitex-linter format — auto-fix SciTeX issues
🐍 Python API Programmatic use from scitex_linter.checker import lint_file
🔌 flake8 Plugin CI pipelines flake8 --select STX
🔧 MCP Server AI agents 3 tools for Claude/GPT integration
🖥️ CLI Commands
scitex-linter --help                              # Show all commands
scitex-linter --help-recursive                    # Show help for all subcommands

# Check - Check for SciTeX pattern violations
scitex-linter check script.py                      # Check a file
scitex-linter check ./src/                         # Check a directory
scitex-linter check script.py --severity error     # Only errors
scitex-linter check script.py --category path      # Only path rules
scitex-linter check script.py --json               # JSON output for CI

# Format - Auto-fix SciTeX pattern issues
scitex-linter format script.py                     # Fix in place
scitex-linter format script.py --check             # Dry run (exit 1 if changes needed)
scitex-linter format script.py --diff              # Show diff of changes
scitex-linter format ./src/                        # Format a directory

# Python - Lint then execute
scitex-linter python experiment.py                # Lint and run
scitex-linter python experiment.py --strict       # Abort on errors
scitex-linter python experiment.py -- --lr 0.001  # Pass script args

# Rules - Browse available rules
scitex-linter rule                          # List all 35 rules
scitex-linter rule --category stats         # Filter by category
scitex-linter rule --json                   # JSON output

# MCP - AI agent server
scitex-linter mcp start                           # Start MCP server (stdio)
scitex-linter mcp list-tools                      # List MCP tools
🐍 Python API
from scitex_linter.checker import lint_file
from scitex_linter.formatter import format_issue

# Lint a file
issues = lint_file("script.py")
for issue in issues:
    print(format_issue(issue, "script.py"))

# Check source code directly
from scitex_linter.checker import lint_source
issues = lint_source("import argparse\npass\n")
🔌 flake8 Plugin

SciTeX Linter registers as a flake8 plugin with the STX prefix:

flake8 --select STX script.py
flake8 --select STX ./src/ --format=json

Integrates with existing flake8 workflows, pre-commit hooks, and CI pipelines.

🔧 MCP Server — 3 Tools for AI Agents
Tool Description
linter_check Check a Python file for SciTeX compliance
linter_list_rules List all available rules
linter_check_source Lint source code string

Claude Desktop (~/.config/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "scitex-linter": {
      "command": "scitex-linter",
      "args": ["mcp", "start"]
    }
  }
}

Install MCP extra: pip install scitex-linter[mcp]

35 Rules Across 7 Categories

Category Rules Severity What It Enforces
S Structure 5 error/warning @stx.session, __main__ guard, no argparse
I Import 7 warning/info Use stx.plt, stx.stats, stx.io instead of raw libs
IO I/O Calls 7 warning Use stx.io.save()/stx.io.load() for provenance
P Plot 5 info Use stx.plt tracked methods, logger over print()
ST Stats 6 warning Use stx.stats for auto effect size + CI + power
PA Path 5 warning/info Relative paths with ./, no open(), no os.chdir()
Example Output
script.py:1   STX-S003  [error]    argparse detected — @stx.session auto-generates CLI
  Suggestion: Remove `import argparse` and define parameters as function arguments:
    @stx.session
    def main(data_path: str, threshold: float = 0.5):
        # Auto-generates: --data-path, --threshold

script.py:5   STX-PA001 [warning]  Absolute path in `stx.io` call — use relative paths
  Suggestion: Use `stx.io.save(obj, './relative/path.ext')` — paths resolve to script_out/.

script.py: 2 issues (1 error, 1 warning)
Full Rules Reference

See Rules Reference for all 35 rules with descriptions and suggestions.

Claude Code Hook

SciTeX Linter works as a post-tool-use hook for Claude Code, automatically linting every Python file Claude writes or edits:

# In ~/.claude/to_claude/hooks/post-tool-use/run_lint.sh
# Errors (exit 2) → Claude must fix
# Warnings (exit 1) → Claude sees feedback

This ensures AI-generated code follows SciTeX patterns from the start.

Configuration

Configure via pyproject.toml or environment variables
[tool.scitex-linter]
severity = "info"                    # Minimum severity: error, warning, info
disable = ["STX-P004", "STX-I003"]   # Disable specific rules
exclude-dirs = ["venv", ".venv"]     # Directories to skip
library-dirs = ["src"]               # Exempt from script-only rules

[tool.scitex-linter.per-rule-severity]
STX-S003 = "warning"                 # Downgrade argparse rule

[tool.scitex-linter.session]
required-injected = ["CONFIG", "plt", "COLORS", "rngg", "logger"]

Environment variables (highest priority):

SCITEX_LINTER_SEVERITY=error
SCITEX_LINTER_DISABLE=STX-P004,STX-I003

Priority: CLI flags > env vars > pyproject.toml > defaults

What a Clean Script Looks Like

import scitex as stx

@stx.session
def main(data_path="./data.csv", threshold=0.5):
    df = stx.io.load(data_path)
    results = stx.stats.ttest_ind(df["group_a"], df["group_b"])
    stx.io.save(results, "./results.csv")
    return 0

if __name__ == "__main__":
    main()

Zero lint issues. Fully reproducible. Auto-CLI from function signature.

Documentation

📚 Full Documentation on Read the Docs


SciTeX
AGPL-3.0 · ywatanabe@scitex.ai

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scitex_linter-0.2.0.tar.gz (51.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scitex_linter-0.2.0-py3-none-any.whl (46.4 kB view details)

Uploaded Python 3

File details

Details for the file scitex_linter-0.2.0.tar.gz.

File metadata

  • Download URL: scitex_linter-0.2.0.tar.gz
  • Upload date:
  • Size: 51.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0rc1

File hashes

Hashes for scitex_linter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d8f8cd630db637d94e93537af2ec2bc635f6ff00f2407e840847e3911d2aa592
MD5 9f94f7451f163722a894ce5a41570e2f
BLAKE2b-256 44e753b7cbf24fae9963db5f24e894d74258e17a74bf98b3ceae90c4f3a1ae43

See more details on using hashes here.

File details

Details for the file scitex_linter-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: scitex_linter-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 46.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0rc1

File hashes

Hashes for scitex_linter-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7791ec857b109e72c1dda361cc228db68d76a057c93ab40485fe3f052dc17f34
MD5 53adc0640decc2856d0ad8d87a9b4a2e
BLAKE2b-256 732776f91289318705d8b8ca5eb70e3267083951a32ebe7dc1df654db384d32e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page