Skip to content

ci: Migrate to uv#6546

Open
khvn26 wants to merge 10 commits intomainfrom
ci/packaging-for-dev
Open

ci: Migrate to uv#6546
khvn26 wants to merge 10 commits intomainfrom
ci/packaging-for-dev

Conversation

@khvn26
Copy link
Copy Markdown
Member

@khvn26 khvn26 commented Jan 17, 2026

Why move to uv now

api/ is a Poetry project with package-mode = false, so it isn't pip-installable. Downstream private packages (flagsmith-private, flagsmith-saml, flagsmith-workflows, ...) consume the api by cloning the repo and symlinking tests into it, each carrying its own copy of the api dependency graph.

Migrating to uv + PEP 621 + setuptools makes the api a real, pip-installable package. Downstreams can list it as a [tool.uv.sources] git dep and import normally.

Testing gain

With the api installable, fixtures in api/tests/conftest.py are reachable from any consumer's venv. Consumers opt in with pytest_plugins = ["tests.conftest"] in their rootdir conftest and inherit every api fixture (project, feature, environment, ...) — no symlinks, no clones, no path tricks.

Why the conftest refactor

api/conftest.py previously held hooks + fixtures. Two non-options for sharing it:

  • Installing it as a top-level conftest py-module pollutes every downstream venv (collides with any project that has its own root conftest.py).
  • An entry-point pytest11 plugin doesn't work either: entry-point modules are imported before pytest-django's tryfirst Django setup, so module-level Django imports explode with AppRegistryNotReady (see pytest #935).

The fix: collapse hooks + fixtures into api/tests/conftest.py and have consumers opt in via pytest_plugins. pytest_plugins resolves after pytest-django's Django setup, so module-level Django imports are safe.

Locked versions

Every dep version in uv.lock is byte-identical to poetry.lock on main. No silent upgrades.

Test plan

  • API unit tests pass on 3.11 / 3.12 / 3.13
  • codecov/patch green
  • Downstream flagsmith-private consumes the new package and inherits fixtures via pytest_plugins

@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview May 11, 2026 1:11am
flagsmith-frontend-preview Ignored Ignored Preview May 11, 2026 1:11am
flagsmith-frontend-staging Ignored Ignored Preview May 11, 2026 1:11am

Request Review

@github-actions github-actions Bot added api Issue related to the REST API ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels Jan 17, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.38%. Comparing base (e4651d1) to head (427beea).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6546      +/-   ##
==========================================
- Coverage   98.44%   98.38%   -0.06%     
==========================================
  Files        1398     1397       -1     
  Lines       52654    52470     -184     
==========================================
- Hits        51834    51622     -212     
- Misses        820      848      +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels Jan 17, 2026
- Convert api/pyproject.toml from poetry to PEP 621 + setuptools so the
  api becomes pip-installable (was package-mode = false).
- Replace api/poetry.lock with api/uv.lock; pin every package to the
  exact version main was on (no silent upgrades).
- Express each optional poetry group as a PEP 621 optional-dependencies
  extra (auth-controller, saml, ldap, workflows, licensing,
  release-pipelines) plus the existing dev extra.
@khvn26 khvn26 force-pushed the ci/packaging-for-dev branch from b4057ee to e5c67b4 Compare May 10, 2026 21:32
@github-actions github-actions Bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels May 10, 2026
khvn26 added 3 commits May 10, 2026 22:43
Rewrite all api/Makefile targets that called poetry to use uv (install-uv,
uv sync, uv run). Switch the python-typecheck pre-commit hook entry from
'poetry -C api run' to 'uv run' (executed inside api/), and replace the
poetry-check hook with astral-sh/uv-pre-commit's uv-lock check.

beep boop
Replace poetry installation and setup-python's cache:poetry option in the
api workflows with astral-sh/setup-uv@v6 (cache keyed on api/uv.lock), and
swap poetry-style --with group args for uv --extra extras when calling
make install-packages.

beep boop
Replace poetry-based install in build-python and build-python-private
stages with uv sync. Translate --with X poetry group args to uv --extra
flags and add UV_PROJECT_ENVIRONMENT, UV_PYTHON, UV_LINK_MODE config so
the resulting venv lands at /build/.venv (the same layout the runtime
stages copy from).

beep boop
@github-actions github-actions Bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels May 10, 2026
@khvn26 khvn26 changed the title ci: Migrate api/ from Poetry to uv ci: Migrate to uv May 10, 2026
…ts/fixtures.py

The api conftest.py is shipped as a top-level `py-module` in the installed
wheel. Downstream consumers that install the api into their venv could not
re-use its fixtures via `from conftest import *` because their own root
`conftest.py` collides with the api's top-level `conftest` module.

Move every `@pytest.fixture` (and the helper constants they reference)
out of `api/conftest.py` into a regular module at `api/tests/fixtures.py`,
and have `api/conftest.py` re-export them with `from tests.fixtures import *`.

Pytest hooks (`pytest_addoption`, `pytest_configure`) stay in `api/conftest.py`
because pytest only invokes hooks from conftest / registered plugin modules.

Downstream consumers can now write:

    # consumer's conftest.py
    from tests.fixtures import *  # noqa: F401, F403

without any importlib shenanigans.
@github-actions github-actions Bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels May 10, 2026
- Ship api/tests/plugin.py as a pytest11 entry point so the api's
  --ci option and fixture set are auto-discovered by any venv with
  flagsmith-api[dev] installed.
- Drop py-modules = ["conftest", "manage"]; api/conftest.py is gone
  (its hooks moved into the plugin).
- Fixtures stay in api/tests/fixtures.py and get lazily registered
  in pytest_configure (after pytest-django has set up Django).
@github-actions github-actions Bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels May 10, 2026
Drop the pytest11 entry point in favour of consumer-declared
pytest_plugins = ["tests.conftest"]. Entry-point plugins are imported
before pytest-django's tryfirst Django setup, which forced lazy fixture
registration; declaring pytest_plugins in a consumer's rootdir conftest
loads the plugin after pytest-django has run, so api/tests/conftest.py
can keep its top-level Django imports.

Collapses api/tests/plugin.py + api/tests/fixtures.py back into
api/tests/conftest.py — one home for hooks and fixtures.

Refs pytest-dev/pytest#935
@github-actions github-actions Bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels May 10, 2026
The pyfakefs `fs` fixture computes its mount root via
os.path.dirname(os.path.abspath(__file__)). When this fixture lived in
api/conftest.py the root resolved to api/; after moving into
api/tests/conftest.py the root regressed to api/tests/, which dropped
api/app/templates/, api/users/templates/, etc. from the fake filesystem
and caused TemplateDoesNotExist failures on pyfakefs-using tests.
@github-actions github-actions Bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels May 10, 2026
…e branches

The PR's diff includes the api/tests/conftest.py rewrite, which exposed
pre-existing dead/defensive code to codecov/patch:

- xero_subscription and manage_user_group_permission fixtures had no
  callers anywhere in the test suite, so delete them (also drops the
  XERO, MANAGE_USER_GROUPS, and OrganisationPermissionModel imports).
- restrict_http_requests' inner urlopen_mock branches and the fs
  fixture's "site-packages outside api/" branch are defensive paths
  that only fire in environments the CI suite doesn't exercise; mark
  the specific lines (not the whole fixture) with `# pragma: no cover`.
@khvn26 khvn26 force-pushed the ci/packaging-for-dev branch from 3dab602 to 0796a91 Compare May 11, 2026 00:39
@github-actions github-actions Bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels May 11, 2026
@khvn26 khvn26 marked this pull request as ready for review May 11, 2026 00:48
@khvn26 khvn26 requested review from a team as code owners May 11, 2026 00:48
@khvn26 khvn26 requested review from gagantrivedi and removed request for a team May 11, 2026 00:48
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@github-actions github-actions Bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels May 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-6546 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-6546 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api-test:pr-6546 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-6546 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-6546 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-6546 Finished ✅ Results

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  38.9 seconds
commit  0796a91
info  🔄 Run: #16641 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  42.6 seconds
commit  0796a91
info  🔄 Run: #16641 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  42 seconds
commit  0796a91
info  🔄 Run: #16641 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  57.1 seconds
commit  0796a91
info  🔄 Run: #16641 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  33.1 seconds
commit  427beea
info  🔄 Run: #16642 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  3.4 seconds
commit  427beea
info  🔄 Run: #16642 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  56.5 seconds
commit  427beea
info  🔄 Run: #16642 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  59.6 seconds
commit  427beea
info  🔄 Run: #16642 (attempt 1)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

Visual Regression

16 screenshots compared. See report for details.
View full report

Let astral-sh/setup-uv install Python via python-version, and add
BuildKit cache mounts on /root/.cache/uv to every Dockerfile stage
that runs uv sync.

beep boop
@github-actions github-actions Bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API ci-cd Build, test and deployment related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants