Skip to content

Package management in Flow: native install/add/sync and flowc package imports - #989

Merged
godofecht merged 5 commits into
mainfrom
port/pkg-native
Sep 29, 2026
Merged

godofecht merged 5 commits into
mainfrom
port/pkg-native

Conversation

@godofecht

@godofecht godofecht commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

What

Package management no longer needs Python, and flowc resolves registry package imports.

This branch contains #960 (first five commits). Merge #960 first, or merge this and close #960.

Package manager in Flow

compiler/src/pkg.flow is the package manager that src/flow/package.py was for add, install, sync, search, info and the install step of flow run:

  • registry index reading, including FLOW_REGISTRY_PATH, FLOW_REGISTRY_URL (curl, cached under $FLOW_HOME/cache) and the legacy packets/crates keys;
  • version selection with the registry's exact parse_semver/version_matches rules (compiler/src/semver.flow);
  • path, git (tag, rev, branch, subdir) and stdlib installs into flow_packages/;
  • flow.lock written byte for byte as json.dumps(indent=2) wrote it; flow add rewrites flow.toml as FlowPackage.to_toml did.

compiler/src/pkg_json.flow is the value tree with a JSON reader/writer and a TOML reader. compiler/src/pkg_main.flow is the CLI with the old argparse interface and exit codes.

Flow calls system()/popen() with one command line, so git, curl, tar and cp run through scripts/tools/pkg_fetch.sh. The shim only executes; every decision (what to fetch, which ref, what to do on failure, the error text) is in Flow.

flow-driver builds the tool with the Stage-A compiler and routes add, sync, install (with a flow.toml), search, info, pkg add|install|sync|search|info and flow run's install step to it.

flowc resolves import json.lib

compiler/src/resolve.flow: a dotted import whose first segment is a key of the project's [dependencies] (and not of [paths], and not std) resolves under <project>/flow_packages/<name>/src, then <project>/flow_packages/<name>, longest module prefix first. The project is the nearest flow.toml above the entry. These are the Python host's module_resolver rules. A declared package that is not installed is an error that names flow sync. Bootstrap C regenerated in its own commit.

A recursion fixed on the way

With #960, flow run builds pkg_sync through ensure_flowc.sh. When compiler/src has local edits, ensure_flowc starts the Python roundtrip, which calls flow run, which builds pkg_sync, which calls ensure_flowc again, without end. This hit the AGENTS.md regeneration step. Helper tools are now built with ensure_flowc.sh --cc-only, which uses the checked-in bootstrap C and never starts the roundtrip.

Python removed

  • src/flow/package.py: 611 lines. Gone: add, install, install_package, _install_git_dependency, sync_for_program, search, info, the lock and git helpers, and their CLI subcommands. Kept: init, publish, build, run, clean, build_native/run_native (flow-driver's demos call them), FlowPackage.
  • src/flow/registry.py: 164 lines. Kept what publish needs.
  • compiler/scripts/build_pkg.sh (it built the old Stage-A pkg stub through the Python transpiler), its test, and the unused compiler/src/toml.flow and project_config.flow.
  • The unit tests for the removed code now run the Flow package manager through flow-driver with the same assertions.

scripts/python_ratchet.sh --update tightened the baseline.

Proof

Parity, scripts/check_pkg_parity.sh: each case runs in two fresh copies of a project, one per implementation, with the Python side read from git history (660ff30d). It compares stdout (colours included), exit status, flow.toml, flow.lock, and flow_packages/ (file list, contents, modes; for git clones the checked-out commit).

parity: pass=134 fail=0

Cases: install, sync --program, add and add name@^0.1.0 for all 19 packages in registry/packages plus flow-verify; @latest, >=, ==; unknown package (add, install, sync); bad and garbage version constraints; partial failure; existing lock with foreign entries and non-ASCII; malformed lock; path dir/file/missing; stdlib; local file; unsupported spec; git tag/rev/branch+subdir/bad subdir/bad tag; git URL shorthand; a registry override with several versions, a yanked one, v-prefixed and pre-release versions, a git source; search and info.

No Python, scripts/check_run_without_python.sh from a clean compiler/build and build/, python and python3 stubbed to log and exit 127:

PASS run project importing a registry package that is not installed (json) (exit 3)
PASS flow.lock and flow_packages/json written
PASS run the same project again (already installed) (exit 3)
PASS flow sync (exit 0)
PASS flow add toml (exit 0)
PASS flow pkg install (exit 0)
PASS flow search json (exit 0)
PASS flow info json (exit 0)
PASS flow add installed and locked toml
PASS run project with an unknown dependency fails (exit 1)
PASS unknown dependency is reported

programs: pass=20 fail=0
python stubs called: 0
check_run_without_python: PASS

Compiler: fixed point OK; bootstrap_from_c.sh --verify, self_host_full.sh, roundtrip.sh, selfcompile_audit.sh all pass (the new pkg modules compile with 0 diagnostics). The tests/lang bootstrap suite gives the same pass/fail set as origin/main's bootstrap (119/19). pytest tests/unit -m "not slow": 1771 passed; the 2 errors in test_match_exhaustive_returns.py are on main too (it reads build/m.c, but flow run now builds in build/run.XXXXXX).

With the packages installed natively and built by flowc, 13 of the 16 examples/ecosystem demos build and run, including json, toml, serde, http, sqlite and compress.

What remains

  • check_pkg_parity.sh is not in CI. A job needs fetch-depth: 0 and python3. I did not edit the workflow.
  • init, publish, build, build-native, run-native, clean are still Python.
  • log_demo, testing_demo and app_cache do not build on flowc: the log package uses effects and testing fails the Stage-A typecheck. Resolution works; the packages hit Stage-A gaps.
  • Tarball sources: package.py never had them, so neither does this.
  • Floats in flow.lock or the index are written back as parsed. Python would print its own repr. Neither file has floats.

godofecht added a commit that referenced this pull request Sep 29, 2026
Rebased onto main containing #1003, #999, #998 and #989. Carries #1001's
parse-only mode, located parse errors (flowc_parser_print_error, which the
driver, emit and bundle paths now use), theorem/assume/therefore/claim
references, flow blocks, handle, ui layout and pipeline blocks, let without
initializer, contextual unit, distinct, effect rows, or-patterns, guards,
nested patterns, [T; N], capability types, ?, vector literals, soft names,
sort-by keys, entropy policies and module blocks, the parse coverage script
and its CI floor, and the Python-grammar parser contract test. The
#1001/#1003 reconciliation follows the one in #1012.
godofecht added a commit that referenced this pull request Sep 29, 2026
Rebased onto main containing #1003, #999, #998 and #989. Carries #1001's
parse-only mode, located parse errors (flowc_parser_print_error, which the
driver, emit and bundle paths now use), theorem/assume/therefore/claim
references, flow blocks, handle, ui layout and pipeline blocks, let without
initializer, contextual unit, distinct, effect rows, or-patterns, guards,
nested patterns, [T; N], capability types, ?, vector literals, soft names,
sort-by keys, entropy policies and module blocks, the parse coverage script
and its CI floor, and the Python-grammar parser contract test. The
#1001/#1003 reconciliation follows the one in #1012.
compiler/src/pkg.flow now holds the package manager that src/flow/package.py
was for these commands: registry index reading (FLOW_REGISTRY_PATH and
FLOW_REGISTRY_URL included), version selection, path/git/stdlib installs into
flow_packages/, and flow.lock written byte for byte as json.dumps(indent=2)
wrote it. pkg_json.flow is the value tree with the JSON reader/writer and a
TOML reader; semver.flow follows the registry's parse_semver and
version_matches exactly.

Flow calls system()/popen() with one command line, so git, curl, tar and cp
run through scripts/tools/pkg_fetch.sh. Every decision stays in Flow.

flow-driver builds the tool with the Stage-A compiler from the checked-in
bootstrap C (ensure_flowc.sh --cc-only) and routes add, install, sync,
search, info and the install step of flow run to it. Building helper tools
through the Python roundtrip recursed without end whenever compiler/src had
local edits, because the roundtrip itself calls flow run.

scripts/check_pkg_parity.sh compares both implementations on 134 cases:
every registry package, path/git/stdlib dependencies, a registry override
with several versions, and the error paths. All pass.

The unused Stage-A pkg scaffolding (build_pkg.sh, its test, toml.flow,
project_config.flow) is removed.
A dotted import whose first segment is a key of the project's
[dependencies] (and not of [paths], and not std) now resolves under
<project>/flow_packages/<name>/src, then <project>/flow_packages/<name>,
longest module prefix first. The project is the nearest flow.toml above the
entry file. These are the Python host's module_resolver rules. A declared
package that is not installed is an error that names flow sync.

check_run_without_python.sh now runs a program that imports json.lib with
nothing installed: flow run installs the package with the Flow package
manager, writes flow.lock, resolves the import and runs it, all with the
python stubs never called. It also runs flow sync, add, pkg install, search,
info, and an unknown dependency. The check needs the regenerated bootstrap
C to pass from a clean checkout.
src/flow/package.py keeps init, publish, build, clean and the native
build/run that flow-driver's demos call. add, install, sync, search, info,
the lock helpers, the git helpers and sync_for_program are gone (611 lines).
src/flow/registry.py keeps what publish needs: loading the index and
publish_local (164 lines less).

The unit tests for the removed code now run the Flow package manager through
flow-driver with the same assertions. docs/project/package-registry.md says
which commands are Flow and how flowc resolves package imports.
shellcheck SC2012 failed Lint. The script reads the mode of a single
regular file, where ls -l is the portable choice.
@godofecht
godofecht merged commit ae05237 into main Sep 29, 2026
25 checks passed
godofecht added a commit that referenced this pull request Sep 29, 2026
Rebased onto main containing #1003, #999, #998 and #989. Carries #1001's
parse-only mode, located parse errors (flowc_parser_print_error, which the
driver, emit and bundle paths now use), theorem/assume/therefore/claim
references, flow blocks, handle, ui layout and pipeline blocks, let without
initializer, contextual unit, distinct, effect rows, or-patterns, guards,
nested patterns, [T; N], capability types, ?, vector literals, soft names,
sort-by keys, entropy policies and module blocks, the parse coverage script
and its CI floor, and the Python-grammar parser contract test. The
#1001/#1003 reconciliation follows the one in #1012.
@godofecht
godofecht deleted the port/pkg-native branch October 1, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant