Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/api-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,12 @@ jobs:
- name: Cloning repo
uses: actions/checkout@v5

- name: Install Poetry
run: make install-poetry

- uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
cache: poetry

- name: Install Dependencies
run: make install-packages
run: uv sync

- name: Create analytics database
env:
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/api-run-makefile-target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ jobs:
steps:
- uses: actions/checkout@v5

- name: Install Poetry
run: make install-poetry

- uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v5
with:
python-version: 3.11
cache: poetry
python-version: '3.11'

- name: Install Dependencies
run: make install-packages
run: uv sync

- name: Run `make ${{ inputs.target }} opts=${{ inputs.opts }}`
env:
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/api-tests-with-private-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ jobs:
- name: Cloning repo
uses: actions/checkout@v5

- name: Install Poetry
run: make install-poetry

- uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v5
with:
python-version: '3.12'
cache: poetry

- name: Install SAML Dependencies
run: sudo apt-get install -y xmlsec1
Expand All @@ -44,7 +40,7 @@ jobs:
run: |
echo "https://${{ secrets.GH_PRIVATE_ACCESS_TOKEN }}:@github.com" > ${HOME}/.git-credentials
git config --global credential.helper store
make install-packages opts="--with saml,auth-controller,workflows"
make install-packages opts="--extra dev --extra private"
make install-private-modules
make integrate-private-tests
rm -rf ${HOME}/.git-credentials
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/update-flagsmith-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ jobs:
steps:
- uses: actions/checkout@v5

- name: Set up Python 3.12
uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v5
with:
python-version: 3.12
cache: pip
python-version: '3.12'

- name: Install Dependencies
run: make install

- name: Update defaults
run: poetry run python manage.py updateflagsmithenvironment
run: uv run python manage.py updateflagsmithenvironment

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
Expand Down
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ repos:
- id: python-typecheck
name: python-typecheck
language: system
entry: poetry -C api run mypy .
entry: make -C api typecheck
require_serial: true
pass_filenames: false
types: [python]
stages: [pre-push]

- repo: https://github.com/python-poetry/poetry
rev: 2.2.1
hooks:
- id: poetry-check
args: ["-C", "api"]
- id: uv-lock-check
name: uv-lock-check
language: system
entry: uv lock --check --directory api
pass_filenames: false
types: [toml]

default_install_hook_types: [pre-commit, pre-push]
default_stages: [pre-commit]
Expand Down
20 changes: 8 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,11 @@ RUN apk add build-base linux-headers curl git \
python-${PYTHON_VERSION}-dev \
py${PYTHON_VERSION}-pip

COPY api/pyproject.toml api/poetry.lock api/Makefile ./
ENV POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_VIRTUALENVS_OPTIONS_ALWAYS_COPY=true \
POETRY_VIRTUALENVS_OPTIONS_NO_PIP=true \
POETRY_VIRTUALENVS_OPTIONS_NO_SETUPTOOLS=true \
POETRY_HOME=/opt/poetry \
PATH="/opt/poetry/bin:$PATH"
RUN make install opts='--without dev'
COPY api/pyproject.toml api/uv.lock api/Makefile ./
ENV UV_PROJECT_ENVIRONMENT=/build/.venv \
UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy
RUN make install

# * build-python-private [build-python]
FROM build-python AS build-python-private
Expand All @@ -109,11 +106,10 @@ FROM build-python AS build-python-private
# and integrate private modules
ARG SAML_REVISION
ARG RBAC_REVISION
ARG WITH="saml,auth-controller,ldap,workflows,licensing,release-pipelines"
RUN --mount=type=secret,id=github_private_cloud_token \
echo "https://$(cat /run/secrets/github_private_cloud_token):@github.com" > ${HOME}/.git-credentials && \
git config --global credential.helper store && \
make install-packages opts='--without dev --with ${WITH}' && \
make install-packages opts='--extra private' && \
make install-private-modules

# * api-runtime
Expand Down Expand Up @@ -161,7 +157,7 @@ FROM build-python AS api-test

COPY api /build/

RUN make install-packages opts='--with dev'
RUN make install-packages opts='--extra dev'

CMD ["make", "test"]

Expand All @@ -170,7 +166,7 @@ FROM build-python-private AS api-private-test

COPY api /build/

RUN make install-packages opts='--with dev' && \
RUN make install-packages opts='--extra dev' && \
make integrate-private-tests && \
git config --global --unset credential.helper && \
rm -f ${HOME}/.git-credentials
Expand Down
3 changes: 3 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ features/workflows/logic/

# Unit test coverage
.coverage

# Build artifacts
*.egg-info/
54 changes: 25 additions & 29 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,39 @@ COMPOSE_PROJECT_NAME ?= flagsmith

DOTENV_OVERRIDE_FILE ?= .env

POETRY_VERSION ?= 2.2.1
UV_VERSION ?= 0.5.14

SAML_REVISION ?= v1.6.6
RBAC_REVISION ?= v0.12.1

-include .env-local
-include $(DOTENV_OVERRIDE_FILE)

.PHONY: install-pip
install-pip:
python -m pip -q install --upgrade pip

.PHONY: install-poetry
install-poetry:
python -m pip -q install poetry==${POETRY_VERSION}
.PHONY: install-uv
install-uv:
@command -v uv >/dev/null 2>&1 || pip install uv==${UV_VERSION}

.PHONY: install-packages
install-packages:
poetry install --no-root $(opts)
uv sync $(opts)

.PHONY: install-private-modules
install-private-modules:
$(eval SITE_PACKAGES_DIR := $(shell poetry run python -c 'import site; print(site.getsitepackages()[0])'))
$(eval SITE_PACKAGES_DIR := $(shell uv run python -c 'import site; print(site.getsitepackages()[0])'))
git clone https://github.com/flagsmith/flagsmith-saml --depth 1 --branch ${SAML_REVISION} && mv ./flagsmith-saml/saml $(SITE_PACKAGES_DIR)
git clone https://github.com/flagsmith/flagsmith-rbac --depth 1 --branch ${RBAC_REVISION} && mv ./flagsmith-rbac/rbac $(SITE_PACKAGES_DIR)
rm -rf ./flagsmith-saml ./flagsmith-rbac

.PHONY: install
install: install-pip install-poetry install-packages
install: install-uv install-packages

.PHONY: lint
lint:
poetry run pre-commit run -a
uv run pre-commit run -a

.PHONY: typecheck
typecheck:
poetry run mypy .
uv run mypy .

.PHONY: docker-up
docker-up:
Expand All @@ -68,39 +64,39 @@ docker-build:

.PHONY: test
test:
poetry run pytest $(opts)
uv run pytest $(opts)

.PHONY: django-make-migrations
django-make-migrations:
poetry run python manage.py waitfordb
poetry run python manage.py makemigrations $(opts)
uv run python manage.py waitfordb
uv run python manage.py makemigrations $(opts)

.PHONY: django-squash-migrations
django-squash-migrations:
poetry run python manage.py waitfordb
poetry run python manage.py squashmigrations $(opts)
uv run python manage.py waitfordb
uv run python manage.py squashmigrations $(opts)

.PHONY: django-migrate
django-migrate:
poetry run python manage.py waitfordb
poetry run python manage.py migrate
poetry run python manage.py createcachetable
uv run python manage.py waitfordb
uv run python manage.py migrate
uv run python manage.py createcachetable

.PHONY: django-shell
django-shell:
poetry run python manage.py shell
uv run python manage.py shell

.PHONY: django-collect-static
django-collect-static:
poetry run python manage.py collectstatic --noinput
uv run python manage.py collectstatic --noinput

.PHONY: serve
serve: docker-up
poetry run flagsmith start --reload api
uv run flagsmith start --reload api

.PHONY: run-task-processor
run-task-processor: docker-up
poetry run flagsmith start --reload --bind 0.0.0.0:8001 task-processor
uv run flagsmith start --reload --bind 0.0.0.0:8001 task-processor

.PHONY: serve-with-task-processor
serve-with-task-processor: TASK_RUN_METHOD=TASK_PROCESSOR
Expand Down Expand Up @@ -137,8 +133,8 @@ generate-grafana-client-types:

.PHONY: integrate-private-tests
integrate-private-tests:
$(eval WORKFLOW_REVISION := $(shell grep -A 1 "\[tool.poetry.group.workflows.dependencies\]" pyproject.toml | awk -F '"' '{printf $$4}'))
$(eval AUTH_CONTROLLER_REVISION := $(shell grep -A 1 "\[tool.poetry.group.auth-controller.dependencies\]" pyproject.toml | awk -F '"' '{printf $$4}'))
$(eval WORKFLOW_REVISION := $(shell uv run python -c "import tomllib; deps=tomllib.load(open('pyproject.toml','rb'))['dependency-groups']['private']; print([d.split('@')[-1] for d in deps if 'flagsmith-workflows' in d][0])"))
$(eval AUTH_CONTROLLER_REVISION := $(shell uv run python -c "import tomllib; deps=tomllib.load(open('pyproject.toml','rb'))['dependency-groups']['private']; print([d.split('@')[-1] for d in deps if 'flagsmith-auth-controller' in d][0])"))

git clone https://github.com/flagsmith/flagsmith-saml --depth 1 --branch ${SAML_REVISION} && mv ./flagsmith-saml/tests tests/saml_tests
git clone https://github.com/flagsmith/flagsmith-rbac --depth 1 --branch ${RBAC_REVISION} && mv ./flagsmith-rbac/tests tests/rbac_tests
Expand All @@ -148,8 +144,8 @@ integrate-private-tests:

.PHONY: generate-docs
generate-docs:
poetry run flagsmith docgen metrics > ../docs/docs/administration-and-security/platform-configuration/metrics.md
uv run flagsmith docgen metrics > ../docs/docs/administration-and-security/platform-configuration/metrics.md

.PHONY: add-known-sdk-version
add-known-sdk-version:
poetry run python scripts/add-known-sdk-version.py $(opts)
uv run python scripts/add-known-sdk-version.py $(opts)
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ flags = flagsmith_client.get_identity_flags(
ai_enabled = flags.is_feature_enabled("ai")
```

To modify or add flags, edit [integrations/flagsmith/data/environment.json](integrations/flagsmith/data/environment.json), or run `poetry run python manage.py updateflagsmithenvironment`.
To modify or add flags, edit [integrations/flagsmith/data/environment.json](integrations/flagsmith/data/environment.json), or run `uv run python manage.py updateflagsmithenvironment`.
Loading
Loading