Skip to content

pants-pyrefly 1.1.0

Choose a tag to compare

@tague tague released this 09 Nov 20:21
· 18 commits to main since this release
1aed58a

pants check no longer rebuilds the third-party venv on every Pyrefly run, which on a large lockfile was most of its time. Pyrefly now gets one config for every file it loads. Every stable Pyrefly from 1.1.1 is pinned, and the default is now 1.3.2. No breaking changes: the goals, [pyrefly] options, and skip_pyrefly field behave as before. Some diagnostics can change, from the newer default Pyrefly and from the config handling; the entries below say when.

  • Every stable Pyrefly from 1.1.1 up to the default is now pinned: 1.1.1, 1.2.0, 1.2.1, 1.3.0, 1.3.1, and 1.3.2. Select any of them with just [pyrefly].version = "..."; no known_versions override is needed. Existing version = "1.1.1" or "1.2.0" pins keep working after upgrading the plugin. (The 1.0.0 entry's advice to pin 1.1.1 did not actually work on 1.0.0, which pinned only 1.2.0; it works as of this release.) See Supported Pyrefly versions for the policy.

  • The default pinned Pyrefly is now 1.3.2 (was 1.2.0). No plugin behavior changes, but the newer Pyrefly changes what some builds report:

    • Renamed error kind. The dataclass-field-assigned-an-inconsistent-data-descriptor error that 1.2.0 reported as bad-class-definition is bad-dataclass-descriptor in 1.3. Anything that names the old kind stops matching it under 1.3.x: 1.2.0-era baseline entries, # pyrefly: ignore[bad-class-definition] comments (including ones pants pyrefly-suppress wrote), [pyrefly].only, and [errors] settings in your Pyrefly config. Under the no-config basic preset, 1.3.2 does not report this error at all.
    • New diagnostics can surface errors 1.2.0 did not report, e.g. invalid literal regular expressions (regex). Which ones fire depends on your config: regex is reported when a Pyrefly config file is in effect, but not under the basic preset. Invalid mock.patch targets are reported as warnings (missing-attribute-patch-target), which the default error severity hides. Open-type match exhaustiveness (non-exhaustive-match-open-type) is off unless you enable it in [errors]. The summary line now also counts hidden warnings (INFO 2 errors (… 1 warning not shown)).
    • Compact baseline format. pants pyrefly-update-baseline now writes entries with path, column, name, concise_description, and severity, and drops line, stop_line, stop_column, code, and description, so regenerating a committed baseline rewrites the whole file once. 1.3.x still honors existing full-format baselines, except entries for the renamed kind above. The change is one-way: a baseline written by 1.3.x does not suppress anything under older Pyrefly, so regenerate it after pinning back.
    • # type: ignore[<code>] comments carrying another tool's codes (e.g. a MyPy code) still suppress everything on the line, as before. 1.3 adds # type: ignore[pyrefly:<code>] for targeted suppression.
  • Removed Pyrefly versions now fail with a reason. A version is removed from the pins only deliberately, with the reason recorded in DENYLISTED_VERSIONS (in subsystems.py) and a CHANGELOG note. Selecting one with [pyrefly].version fails with DenylistedPyreflyVersion: Pyrefly X is not supported by pants-pyrefly: <reason>. Set [pyrefly].version to a supported release (<default>). instead of Pants's generic UnknownVersion. Supplying your own [pyrefly].known_versions entry for it still works. The denylist is empty in this release.

  • Fixed: Pyrefly 1.3's baseline flags in [pyrefly].args.

    • --error-stale-baseline now works. Before, every partition received the whole merged baseline. Inside a partition's sandbox, entries for files checked by other partitions point at paths that do not exist, so Pyrefly reported them as stale. check then failed every partition even when nothing was stale, and also failed when checking a subset such as pants check src/a::. Each partition now gets only the entries for its own files. A truly stale entry fails only the partition that checks its file. Entries for deleted files are still reported as stale, once per run, by the first partition, so a subset run can fail on them too. Without the flag, the same errors are gated as before; an entry only ever matched errors in its own file.
    • Known limitation: baseline entries are keyed by path only. A file checked by several partitions (e.g. parametrize over interpreter constraints) with an error in only some of them keeps failing --error-stale-baseline. Use an inline # pyrefly: ignore[<error-kind>] for such errors. See the README.
    • pants pyrefly-update-baseline ignores --error-stale-baseline. Before, it failed with exit code 2, because Pyrefly rejects the flag alongside --update-baseline.
    • --prune-baseline now fails fast. check and pyrefly-update-baseline exit with a PyreflyArgsError that names pants pyrefly-update-baseline ::. Before, check passed and the baseline file was silently left unchanged, because Pyrefly pruned a temporary copy in the sandbox; pyrefly-update-baseline failed with exit code 2. When check fails on stale entries, Pyrefly's "rerun with --prune-baseline" hint now says to run pants pyrefly-update-baseline :: instead. The README now warns that update-baseline rewrites the whole file from only the targets given, so a subset run drops all other entries.
  • Missing-import hints now name your real source roots. Pyrefly's Looked in these locations hint listed the plugin's internal sandbox directories, e.g. Search path override (from command line): ["__pyrefly_root_0", "__pyrefly_root_1"]. It now lists the source roots they stand for, e.g. [".", "src/python"] (. is the build root), in every [pyrefly].output_format, with or without --color=always. The same applies to the description field of baselines written by pants pyrefly-update-baseline under Pyrefly older than 1.3, which also recorded the absolute sandbox path and so changed on every regeneration; regenerate such a baseline once to clean it up. Gating is unaffected, since Pyrefly does not match baseline entries on description. Only the internal names the plugin generated for that run are rewritten, and only as whole path segments, so user code or messages that merely contain such a name are left alone.

  • Fixed: every Pyrefly run rebuilt the third-party venv. Pyrefly finds your third-party packages through a venv that Pants keeps in its shared pex_root named cache. The plugin did not mount that cache into Pyrefly's sandbox, so each Pyrefly process (check and the pyrefly-* goals that read your third-party packages) rebuilt the whole venv before Pyrefly started, even when nothing had changed. The rebuild time grows with the size of the resolve; with a large lockfile it was most of the time pants check spent. The venv is now built once and reused, as it is for Pants' own Python tools. A CI runner that starts with an empty named-caches directory still builds it once per run.

    Because the venv now lives outside the sandbox, the plugin also passes your discovered config (pyrefly.toml, or pyproject.toml with [tool.pyrefly]; pyrefly.toml wins if both exist, as in Pyrefly) to Pyrefly as --config, as it already did for [pyrefly].config. Pyrefly then uses that one config for your code and your third-party packages, as pyrefly check does in project mode and as Pyrefly's Bazel and Buck integrations do, so third-party packages are still analyzed with your config. A discovered config now behaves exactly like one set with [pyrefly].config, which changes three edge cases:

    • disable-project-excludes-heuristics = true is now honored: files Pants passes in under venv/, node_modules/ or __pycache__/ directories are checked, instead of skipped with a Skipping include pattern warning.
    • A config that fails to parse is a fatal error, instead of Pyrefly printing the parse error and checking with defaults.
    • A third-party package that ships its own pyrefly.toml or [tool.pyrefly] is analyzed with your config instead of its own.

    A --config or -c in [pyrefly].args still replaces the plugin's, since Pyrefly rejects a repeated --config.

    If the plugin finds no config to pass (no root pyrefly.toml or [tool.pyrefly], or config_discovery = false without [pyrefly].config), it passes a generated one holding what Pyrefly uses when it finds none, preset = "basic". Pyrefly no longer searches for a config per file, so no config outside your repo applies: before, a Pyrefly, mypy or pyright config in a directory above Pants' sandbox could apply to your files, and one above Pants' cache (such as your home directory) to third-party packages. Visible changes for projects without a config:

    • Third-party packages that ship a mypy.ini or pyrightconfig.json are analyzed with the basic preset instead of a config Pyrefly converted from theirs, so code that uses them can report errors it did not before. Pyrefly's warnings about converting those files (e.g. Invalid search-path: .../site-packages/<package>/...) are gone.
    • Pyrefly's "No pyrefly.toml found — using preset basic" notice no longer appears. Run pants pyrefly-init to create a config.
    • pants pyrefly-dump-config shows the generated config (preset = "basic", at __pyrefly_config.toml in the sandbox) instead of Pyrefly's default configuration.
  • Releases are now gated on a Pyrefly compatibility suite (build-support/ci/compat_test.sh, run by .github/workflows/compat.yml for every supported version). It drives real Pants runs of check, pyrefly-update-baseline, and pyrefly-suppress with only --pyrefly-version set, and asserts that the requested Pyrefly binary is the one that ran. It also runs the default Pyrefly on the latest patch of every supported Pants minor: 2.27.1, 2.28.1, 2.29.1, 2.30.2, 2.31.0, 2.32.1, and 2.33.1, and against a CPython==3.9.* project, asserting that Pyrefly checks it as Python 3.9. The release workflow publishes nothing if any of these jobs fails.

  • Maintenance: build-support/bin/generate_known_versions.py now manages the pins. --write only adds pins (stable releases up to the default, skipping pre-releases and denylisted versions) and never rewrites existing ones. --check verifies only the shipped pins (checksums, default pinned, order, nothing denylisted), so new upstream releases or backports never fail it. --check-upstream lists stable releases that are neither pinned nor denylisted. --remove is the only way to drop a version, --list-versions prints the supported set, and --default-version prints the default. --write and --remove edit subsystems.py line by line, leaving comments and formatting untouched, and denylist reasons are written as single-line UTF-8 literals in ruff format's quote style. Failures print a single error: ... line (with file and line where relevant), never a traceback. The script sends the GitHub token only to api.github.com, rejects malformed .sha256 sidecars, and retries transient network failures, including downloads cut off mid-body.

  • Maintenance: a weekly workflow (.github/workflows/upstream.yml) runs generate_known_versions.py --check-upstream and fails when a stable Pyrefly release is neither pinned nor denylisted, showing the script's output in the job summary. It only reports: it never writes pins or opens a PR. On failure, --check-upstream prints the exact commands to pin the new releases (or skip one).

  • Maintenance: Dependabot (.github/dependabot.yml) now opens one grouped weekly PR for GitHub Actions updates. Python dependencies stay out of it, since Dependabot cannot regenerate Pants lockfiles.

  • Maintenance: the repo now develops, tests, and builds releases on Pants 2.33.1 (was 2.32.0). PR CI smoke-tests the latest patch of a subset of the supported minors: 2.27.1, 2.31.0, 2.32.1, and 2.33.1. The supported Pants range (2.27–2.33) and the published wheel's requirements are unchanged.