:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(ci): Add CI check for unbounded >= version specifiers (#56670)
Julian Bez60cf2b9a4a39
diff --git a/.github/scripts/check-version-specifiers.py b/.github/scripts/check-version-specifiers.pynew file mode 100644index 000000000000..0c3993d4d57d--- /dev/null+++ b/.github/scripts/check-version-specifiers.py@@ -0,0 +1,145 @@+#!/usr/bin/env python3+# ruff: noqa: T201 allow print statements+"""+CI check: flag unbounded >= version specifiers in pyproject.toml.++Prefer ~= (compatible release) over >= (unbounded floor). A bare >= lets any+future major version satisfy the requirement with no signal to reviewers or+tooling (Dependabot, security scanners) that an update is in-range.++Exemptions:+ - >= paired with an upper bound (< or <=) on the same requirement, e.g.+ "pkg>=1.0,<2.0" — that is an explicit bounded range, not a floor.+ - Environment markers are ignored when checking for upper bounds, so+ "pkg>=1.0; python_version<'3.12'" is correctly flagged as unbounded.+ - Comment lines and non-dependency fields (requires-python, etc.) are skipped.++Usage:+ python .github/scripts/check-version-specifiers.py++Exit codes:+ 0 - No unbounded >= specifiers found+ 1 - One or more unbounded >= specifiers found (fix: replace with ~=)+"""++import os+import re+import sys+import tomllib+from pathlib import Path++REPO_ROOT = Path(__file__).resolve().parent.parent.parent+PYPROJECT_PATH = REPO_ROOT / "pyproject.toml"++_HAS_GTE = re.compile(r">=")+_HAS_UPPER = re.compile(r"[<]=?")++# Matches a dep string that is the first (and only significant) quoted value on+# a TOML array line, i.e. lines like: "somepackage>=1.0",+_DEP_LINE = re.compile(r'^\s*"([^"]+)"')++IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true"+++def _is_unbounded_gte(spec: str) -> bool:+ """Return True if spec contains >= with no accompanying upper-bound operator.++ Strips the environment marker (everything after the first ';') before+ checking for upper bounds, so 'pkg>=1.0; python_version<"3.12"' is+ correctly identified as unbounded.+ """+ version_part = spec.split(";", 1)[0]+ if not _HAS_GTE.search(version_part):+ return False+ return not _HAS_UPPER.search(version_part)+++def collect_deps(data: dict) -> list[str]:+ """Return all requirement strings from dependency lists."""+ results: list[str] = []++ project = data.get("project", {})+ results.extend(project.get("dependencies", []))+ for deps in project.get("optional-dependencies", {}).values():+ results.extend(deps)++ uv = data.get("tool", {}).get("uv", {})++ # dev-dependencies: first-class declared requirements (legacy uv flat list)+ # constraint-dependencies / override-dependencies are intentionally excluded:+ # they express version floors on transitive deps where bare >= is correct usage.+ field = uv.get("dev-dependencies", [])+ if isinstance(field, list):+ results.extend(d for d in field if isinstance(d, str))++ # Grouped fields (dev, optional)+ for section_name in ("dev", "optional"):+ uv_section = uv.get(section_name, {})+ if isinstance(uv_section, list):+ results.extend(uv_section)+ elif isinstance(uv_section, dict):+ for deps in uv_section.values():+ results.extend(deps)++ # dependency-groups (PEP 735)+ for deps in data.get("dependency-groups", {}).values():+ results.extend(d for d in deps if isinstance(d, str))++ return results+++def find_line_numbers(bad_deps: set[str]) -> dict[str, int]:+ """Return {dep_string: line_number} by scanning the raw file."""+ lines = PYPROJECT_PATH.read_text().splitlines()+ found: dict[str, int] = {}+ for lineno, line in enumerate(lines, start=1):+ m = _DEP_LINE.match(line)+ if m and m.group(1) in bad_deps:+ found[m.group(1)] = lineno+ return found+++def annotate(dep: str, lineno: int | None) -> None:+ msg = f"Prefer ~= over >=: {dep!r} uses an unbounded floor. Use ~=X.Y or >=X,<Y instead."+ if IN_GITHUB_ACTIONS:+ if lineno is not None:+ print(f"::error file=pyproject.toml,line={lineno},title=Version specifier::{msg}")+ else:+ print(f"::error file=pyproject.toml,title=Version specifier::{msg}")+ else:+ loc = f"pyproject.toml:{lineno}" if lineno is not None else "pyproject.toml"+ print(f" {loc}: {msg}")+++def main() -> int:+ with open(PYPROJECT_PATH, "rb") as f:+ data = tomllib.load(f)++ violations = [dep for dep in collect_deps(data) if _is_unbounded_gte(dep)]++ if not violations:+ print("check-version-specifiers: OK")+ return 0++ line_numbers = find_line_numbers(set(violations))++ print("check-version-specifiers: FAIL — unbounded >= specifiers found in pyproject.toml")+ if not IN_GITHUB_ACTIONS:+ print()+ print("Prefer ~= (compatible release) over >= (unbounded floor).")+ print(" ~=X.Y allows >=X.Y, <(X+1) (minor-compat)")+ print(" ~=X.Y.Z allows >=X.Y.Z, <X.(Y+1) (patch-compat)")+ print("If you need a wider range, use >=X,<Y to make the ceiling explicit.")+ print()++ for dep in violations:+ annotate(dep, line_numbers.get(dep))++ if not IN_GITHUB_ACTIONS:+ print()+ print(f"{len(violations)} violation(s) found.")+ return 1+++if __name__ == "__main__":+ sys.exit(main())diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.ymlindex 3a9fed438a92..ace858f45cad 100644--- a/.github/workflows/ci-backend.yml+++ b/.github/workflows/ci-backend.yml@@ -533,6 +533,9 @@ jobs:- name: Lint product structurerun: ./bin/hogli product:lint --all+ - name: Check version specifiers+ run: python .github/scripts/check-version-specifiers.py+- name: Check IDOR model coveragerun: python .github/scripts/check-idor-model-coverage.pydiff --git a/pyproject.toml b/pyproject.tomlindex 2f532b27231f..83efb99ae8c3 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -184,13 +184,13 @@ dependencies = ["markdown-to-mrkdwn~=0.2.0","webauthn>=2.1.0,<2.3.0","botocore[crt]~=1.40.49",- "defusedxml>=0.7.1",- "confluent-kafka>=2.13.0",- "blake3>=1.0.8",+ "defusedxml~=0.7.1",+ "confluent-kafka~=2.13",+ "blake3>=1.0.8,<2","pixelhog~=1.2.0",- "google-re2>=1.1.20251105",+ "google-re2>=1.1.20251105,<2","scrubadub~=2.0.1",- "braintrust-core>=0.0.59",+ "braintrust-core>=0.0.59,<1",][dependency-groups]@@ -262,7 +262,7 @@ dev = ["types-requests==2.31.0.6","types-retry==0.9.9.4","types-tzlocal~=5.1.0.1",- "pywatchman>=2.0.0",+ "pywatchman~=3.0","watchdog==5.0.3",# Developer CLI"hogli",@@ -274,6 +274,7 @@ sentiment = [[tool.uv]required-version = "~=0.10.2"+add-bounds = "major"exclude-newer = "7 days"exclude-newer-package = { hogql-parser = false, posthoganalytics = false, pixelhog = false }constraint-dependencies = [diff --git a/uv.lock b/uv.lockindex 0a531a49fcd2..c85b7ddecaa9 100644--- a/uv.lock+++ b/uv.lock@@ -11,7 +11,7 @@ resolution-markers = [][options]-exclude-newer = "2026-04-29T07:11:12.944613Z"+exclude-newer = "2026-05-04T09:17:41.700000357Z"exclude-newer-span = "P7D"[options.exclude-newer-package]@@ -5377,10 +5377,10 @@ requires-dist = [{ name = "azure-storage-blob", specifier = "~=12.27.0" },{ name = "beautifulsoup4", specifier = "==4.12.3" },{ name = "bingads", specifier = "~=13.0.26" },- { name = "blake3", specifier = ">=1.0.8" },+ { name = "blake3", specifier = ">=1.0.8,<2" },{ name = "boto3", specifier = "==1.40.49" },{ name = "botocore", extras = ["crt"], specifier = "~=1.40.49" },- { name = "braintrust-core", specifier = ">=0.0.59" },+ { name = "braintrust-core", specifier = ">=0.0.59,<1" },{ name = "brotli", specifier = "==1.2.0" },{ name = "cachetools", specifier = "~=5.5.2" },{ name = "celery", specifier = "==5.6.3" },@@ -5392,7 +5392,7 @@ requires-dist = [{ name = "clickhouse-connect", specifier = "==0.8.17" },{ name = "clickhouse-driver", specifier = "==0.2.9" },{ name = "clickhouse-pool", specifier = "==0.5.3" },- { name = "confluent-kafka", specifier = ">=2.13.0" },+ { name = "confluent-kafka", specifier = "~=2.13" },{ name = "croniter", specifier = "~=6.0.0" },{ name = "cryptography", specifier = "==46.0.7" },{ name = "css-inline", specifier = "==0.18.0" },@@ -5408,7 +5408,7 @@ requires-dist = [{ name = "dagster-webserver", specifier = "==1.10.18" },{ name = "databricks-sdk", specifier = "~=0.102.0" },{ name = "databricks-sql-connector", specifier = "~=4.2.5" },- { name = "defusedxml", specifier = ">=0.7.1" },+ { name = "defusedxml", specifier = "~=0.7.1" },{ name = "deltalake", extras = ["pyarrow"], specifier = "==1.4.0" },{ name = "disposable-email-domains", specifier = "~=0.0.140" },{ name = "dj-database-url", specifier = "~=3.0.0" },@@ -5446,7 +5446,7 @@ requires-dist = [{ name = "google-cloud-bigquery-storage", specifier = "==2.32.0" },{ name = "google-cloud-iam", specifier = "==2.21" },{ name = "google-genai", specifier = "==1.46.0" },- { name = "google-re2", specifier = ">=1.1.20251105" },+ { name = "google-re2", specifier = ">=1.1.20251105,<2" },{ name = "grimp", specifier = "~=3.14" },{ name = "grpcio", specifier = "~=1.71.0" },{ name = "gspread", specifier = "==6.2.1" },@@ -5595,7 +5595,7 @@ dev = [{ name = "pytest-timeout", specifier = "~=2.4.0" },{ name = "pytest-xdist", specifier = "~=3.8.0" },{ name = "python-dateutil", specifier = "~=2.9.0" },- { name = "pywatchman", specifier = ">=2.0.0" },+ { name = "pywatchman", specifier = "~=3.0" },{ name = "requests-mock", specifier = "~=1.12.1" },{ name = "responses", specifier = "==0.23.1" },{ name = "ruff", specifier = "~=0.14.11" },