mod eb_module

module eb_module

Checks for Python modules that travel with recipes, such as easyblocks.

An easyblock is a Python module, not an easyconfig, so the easyconfig rules in crate::eb_style do not apply to it. The easyblocks repository’s CI runs flake8 with the repository’s setup.cfg (max-line-length = 120, flake8-comprehensions), and its test suite rejects run_cmd and run_cmd_qa (easybuild-easyblocks#3426). This module runs the checks that need no Python interpreter, and merges real flake8 output when flake8 is on PATH.

Variables

const FLAKE8_DEFAULT_MAX_LINE: usize

flake8’s line length when no configuration file sets one.

Functions

fn enclosing_scope(text: &str, line: usize) -> Option<String>

The def or class a 1-based line sits in, qualified by the classes around it (EB_Foo.configure_step). None at module level.

fn flake8_config(path: &Path) -> Option<(PathBuf, usize)>

The [flake8] configuration that governs path: the nearest .flake8, setup.cfg or tox.ini above it that has a [flake8] section, with its max-line-length (flake8’s default when the section does not set one).

fn lint_module(path: &Path, text: &str, base: Option<&str>, flake8: bool) -> (ModuleLintFile, Flake8Report)

Lint one module. With base (the module before the edits), a finding whose code and line text were already in base is info (pre-existing) and does not block clean. flake8 findings replace the native finding with the same code on the same line.

fn lint_module_text(text: &str, max_line: usize) -> Vec<StyleFinding>

Native checks on a module’s text: E999 (not valid Python), E501 at max_line, W291/W293 (trailing whitespace), W292/W391 (end of file), EBM_RUN_CMD (run_cmd/run_cmd_qa, gone in EasyBuild 5) and the EBM_OLD_SUPER warning (super(Class, self), easybuild-easyblocks#3681 moved every easyblock to super()), and the EBM_CFG_OVERRIDE and EBM_TEST_STEP_OWN_CMD warnings (an easyconfig value the easyblock overwrites or ignores), and the EBM_THREADED_VARIANT warning (a plain toolchain library variable read with no threaded choice).

fn parse_flake8(text: &str) -> Vec<StyleFinding>

Parse path:line:col: CODE message lines.

fn run_flake8(path: &Path, config: Option<&Path>) -> (Flake8Report, Vec<StyleFinding>)

Run flake8 on path, with config when given. Findings carry origin flake8.

Structs and Unions

struct Flake8Report

Whether flake8 ran, and how it ended.

ran: bool

True when flake8 was found and started.

exit_code: Option<i32>

flake8’s exit code.

detail: String

Why it did not run, or a short note on its output.

struct ModuleLintFile

The checks on one Python module.

path: String

The module as given.

max_line_length: usize

The line length E501 used.

config: Option<String>

The configuration file that set max_line_length, when one did.

findings: Vec<StyleFinding>

Every finding, native and flake8.

clean: bool

True when no finding is an error outside info.