scitex_linter

SciTeX Linter — enforce reproducible research patterns via AST analysis.

scitex_linter.list_rules(category=None)[source]

Return all rules (built-in + plugin), optionally filtered by category.

Parameters:

category (str, optional) – If provided, only return rules whose category matches this value.

Returns:

All matching Rule objects from built-in definitions and loaded plugins.

Return type:

list of Rule

Submodules

scitex_linter.checker

AST-based checker that detects SciTeX anti-patterns.

class scitex_linter.checker.Issue(rule, line, col, source_line='')[source]

Bases: object

rule: Rule
line: int
col: int
source_line: str = ''
__init__(rule, line, col, source_line='')
scitex_linter.checker.is_script(filepath, config=None)[source]

Check if file is a script (not a library module).

Uses config.library_patterns and config.library_dirs to determine which files are library modules (exempt from script-only rules).

Return type:

bool

scitex_linter.checker.lint_file(filepath, config=None)[source]

Lint a Python file or Jupyter notebook; returns list of Issues.

.ipynb files are routed to _ipynb.lint_ipynb, which extracts code cells and calls back into lint_source per cell.

Return type:

list

scitex_linter.checker.lint_source(source, filepath='<stdin>', config=None)[source]

Lint Python source code and return list of Issues.

Return type:

list

scitex_linter.rules

Rule definitions for SciTeX linter.

Thin re-export module: actual definitions live in _rules/ sub-modules.

class scitex_linter.rules.Rule(id, severity, category, message, suggestion, requires='')[source]

Bases: object

id: str
severity: str
category: str
message: str
suggestion: str
requires: str = ''
__init__(id, severity, category, message, suggestion, requires='')

scitex_linter.formatter

Output formatting for terminal and JSON.

scitex_linter.formatter.format_issue(issue, filepath, color=True)[source]
Return type:

str

scitex_linter.formatter.format_summary(issues, filepath, color=True)[source]
Return type:

str

scitex_linter.formatter.to_json(issues, filepath)[source]
Return type:

dict

scitex_linter.runner

Run a Python script after linting it.

Core function used by the scitex-linter python subcommand.

scitex_linter.runner._is_git_root()[source]

Check if the current working directory is a git repository root.

Return type:

bool

scitex_linter.runner.run_script(filepath, strict=False, script_args=None)[source]

Lint a script then execute it.

Returns the subprocess return code, or 2 if strict mode blocks execution.

Return type:

int

scitex_linter.cli

CLI entry point for scitex-linter.

Usage:

scitex-linter check <path> [–json] [–severity] [–category] [–no-color] scitex-linter format <path> [–check] [–diff] scitex-linter python <script.py> [–strict] [– script_args…] scitex-linter rule [–json] [–category] [–severity] scitex-linter list-python-apis [-v|-vv|-vvv] [–json] scitex-linter mcp start scitex-linter mcp list-tools [-v|-vv|-vvv] scitex-linter –help-recursive

scitex_linter.cli._collect_files(path, recursive=True, config=None)[source]

Collect Python files from a path.

Return type:

list

scitex_linter.cli._print_help_recursive(parser, subparsers_actions)[source]

Print help for all commands recursively.

Return type:

None

scitex_linter.cli.main(argv=None)[source]
Return type:

int

scitex_linter.config

Configuration system for scitex-linter.

class scitex_linter.config.LinterConfig(severity='info', exclude_dirs=<factory>, library_patterns=<factory>, library_dirs=<factory>, script_dirs=<factory>, disable=<factory>, enable=<factory>, per_rule_severity=<factory>, required_injected=<factory>)[source]

Bases: object

Configuration for scitex-linter behavior.

severity: str = 'info'
exclude_dirs: list[str]
library_patterns: list[str]
library_dirs: list[str]
script_dirs: list[str]
disable: list[str]
enable: list[str]
per_rule_severity: dict[str, str]
required_injected: list[str]
__init__(severity='info', exclude_dirs=<factory>, library_patterns=<factory>, library_dirs=<factory>, script_dirs=<factory>, disable=<factory>, enable=<factory>, per_rule_severity=<factory>, required_injected=<factory>)
scitex_linter.config.load_config(start_path=None)[source]

Load configuration from defaults, pyproject.toml, and environment variables.

Priority: env vars > pyproject.toml > defaults

Parameters:

start_path (str | None) – File or directory to start pyproject.toml search from. If a file path, searches from its parent directory. Defaults to cwd.

Return type:

LinterConfig

Returns:

Merged configuration

scitex_linter.flake8_plugin

Flake8 plugin for SciTeX linter.

Usage:

pip install scitex-linter flake8 –select STX script.py

class scitex_linter.flake8_plugin.SciTeXFlake8Checker(tree, filename='<stdin>', lines=None)[source]

Bases: object

Flake8 checker wrapping the SciTeX AST visitor.

name = 'scitex-linter'
version = '0.1.0'
__init__(tree, filename='<stdin>', lines=None)[source]
run()[source]

Yield (line, col, message, type) tuples for flake8.

scitex_linter._fm_checker

FM (Figure/Millimeter) rule detection — opt-in category.

Detects inch-based matplotlib patterns and suggests mm-based alternatives. Used as a second-pass AST visitor from lint_source when “FM” is enabled.

scitex_linter._fm_checker._is_exempt_call(node)[source]

Check if the call is on a stx.* or fr.* object (exempt from FM rules).

scitex_linter._fm_checker._has_kwarg(node, name, value=None)[source]

Check if call has a specific keyword argument.

class scitex_linter._fm_checker.FMChecker(source_lines, config)[source]

Bases: NodeVisitor

AST visitor for FM (Figure/Millimeter) rules.

category = 'figure'
__init__(source_lines, config)[source]
visit_Call(node)[source]
visit_Assign(node)[source]
_check_call(node)[source]

Check Call nodes for FM001-FM006.

_check_assign(node)[source]

Check Assign nodes for FM007 (rcParams modification).

scitex_linter._packages

Detect available packages for conditional rule gating.

scitex_linter._packages._can_import(name)[source]

Check if a package is importable.

scitex_linter._packages.detect()[source]

Detect available packages. Cached after first call.

Returns dict with keys: “scitex”, “figrecipe”. “figrecipe” is True if either figrecipe or scitex.plt is importable.

scitex_linter._packages.reset()[source]

Reset cache (for testing).