Skip to content

feat(ecosystems): add Homebrew ecosystem and pkg:brew purl mapping#5660

Draft
andrew wants to merge 1 commit into
google:masterfrom
andrew:homebrew-ecosystem
Draft

feat(ecosystems): add Homebrew ecosystem and pkg:brew purl mapping#5660
andrew wants to merge 1 commit into
google:masterfrom
andrew:homebrew-ecosystem

Conversation

@andrew

@andrew andrew commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Overview

Add the Homebrew ecosystem to _ecosystems.py with a PkgVersion comparator, and map it to the pkg:brew purl type in purl_helpers.py, so BREW-* records from https://github.com/Homebrew/advisory-database can be queried by version and purl once imported.

Refs #5659

Details

osv/ecosystems/homebrew.py ports Homebrew's PkgVersion and Version#<=> as a functools.total_ordering class: the version segment is tokenised into numeric / prerelease-marker (alpha/beta/pre/rc) / patch-marker (p/.post) / string parts and compared with the same two-pointer walk (prerelease below the release, string/patch/post above, numeric zero equal to a missing token so 2.1.0-p194 and 2.1-p194 align), then the numeric _N revision suffix breaks ties. Homebrew is an OrderedEcosystem (no version enumeration; formulae.brew.sh only exposes the current version) with a coarse_version over the leading numeric prefix.

pkg:brew (registered in package-url/purl-spec#796) maps to Homebrew with no namespace. The Homebrew ecosystem and BREW- prefix were registered in ossf/osv-schema#576.

I've kept this to the Python side per the new-data-source docs; happy to add the Go entries in go/osv/ecosystem/ and go/purl/ here or in a follow-up if preferred.

Testing

  • osv/ecosystems/homebrew_test.py: 51 comparison cases lifted from Homebrew's own test/version_spec.rb plus _N revision cases; registration/sort/coarse checks.
  • osv/ecosystems/coarse_version_monotonicity_test.py: hypothesis strategy for realistic Homebrew version strings; monotonicity property holds.
  • osv/purl_helpers_test.py: pkg:brew/openssl%403@3.5.0 round-trips.
  • poetry run python -m unittest osv.ecosystems.homebrew_test osv.purl_helpers_test osv.ecosystems.coarse_version_monotonicity_test osv.ecosystems._ecosystems_test — 26 tests pass.
  • poetry run pylint on all touched files: 10.00/10. yapf -d clean.

This PR was drafted with AI assistance (Claude Code); I read the diff, verified the comparison table against version_spec.rb, and ran the tests locally.

Add Homebrew as an OrderedEcosystem with a version comparator that ports
Homebrew's PkgVersion/Version#<=> (tokenised two-pointer walk with
alpha/beta/pre/rc below the release, string/patch/post above, numeric
zero equal to a missing token, then _N revision as a numeric
tie-breaker) and a coarse_version over the leading numeric prefix. Map
the ecosystem to the pkg:brew purl type (no namespace) and add
formulae.brew.sh as the package_urls entry.

Comparison test cases are lifted from Homebrew's own version_spec.rb; a
hypothesis strategy covers coarse-version monotonicity.

Refs google#5659

Signed-off-by: Andrew Nesbitt <andrewnez@gmail.com>
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