Skip to content

ci: Migrate to uv#6546

Merged
khvn26 merged 15 commits into
mainfrom
ci/packaging-for-dev
May 12, 2026
Merged

ci: Migrate to uv#6546
khvn26 merged 15 commits into
mainfrom
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.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment May 12, 2026 11:12am
flagsmith-frontend-preview Ready Ready Preview, Comment May 12, 2026 11:12am
flagsmith-frontend-staging Ready Ready Preview, Comment May 12, 2026 11:12am

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.46%. Comparing base (d8cd275) to head (7f9601c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6546      +/-   ##
==========================================
+ Coverage   98.44%   98.46%   +0.01%     
==========================================
  Files        1399     1398       -1     
  Lines       52669    52647      -22     
==========================================
- Hits        51849    51837      -12     
+ Misses        820      810      -10     

☔ 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.
@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-api-test:pr-6546 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-6546 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-6546 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith:pr-6546 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-6546 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api-test:pr-6546 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-private-cloud:pr-6546 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-6546 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-6546 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-6546 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api: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)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  38.5 seconds
commit  7f9601c
info  🔄 Run: #16703 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.5 seconds
commit  7f9601c
info  🔄 Run: #16703 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  31 seconds
commit  7f9601c
info  🔄 Run: #16703 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  38.8 seconds
commit  e5ce8ce
info  🔄 Run: #16702 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  43 seconds
commit  e5ce8ce
info  🔄 Run: #16702 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  36 seconds
commit  7f9601c
info  🔄 Run: #16703 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.5 seconds
commit  e5ce8ce
info  🔄 Run: #16702 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  39 seconds
commit  e5ce8ce
info  🔄 Run: #16702 (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
Bring forward django 5.2.14 and requests 2.33.0 bumps from main;
drop the legacy [tool.poetry] block (replaced by uv config) and
re-run uv lock.

beep boop
Comment thread .github/workflows/api-deploy-production-ecs.yml Outdated
Comment thread .pre-commit-config.yaml Outdated
khvn26 added 4 commits May 12, 2026 12:06
Pin uv at one place — api/pyproject.toml's [tool.uv].required-version —
and let setup-uv read it via version-file. Wrap setup-uv in a composite
action so the version-file + cache config aren't repeated across the
five api workflows. The Makefile reads the same field via tomllib.

beep boop
uv exposes --directory to switch into the project dir, so we don't
need bash -c plus cd to run mypy from api/.

beep boop
Bring urllib3 2.7.0 across from main and re-run uv lock.

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 12, 2026
@khvn26 khvn26 requested a review from gagantrivedi May 12, 2026 11:12
@github-actions github-actions Bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels May 12, 2026
@khvn26 khvn26 merged commit bcdcf25 into main May 12, 2026
34 checks passed
@khvn26 khvn26 deleted the ci/packaging-for-dev branch May 12, 2026 12:01
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