2019-04-15 17:17:10 +03:00
|
|
|
export PYTHON_COMMAND=python3
|
2018-09-05 12:23:49 +03:00
|
|
|
|
2019-10-22 12:24:05 +03:00
|
|
|
# As we're using user-local installs inside the docker-container we need
|
|
|
|
# to be cautious about uprading pip and not confusing it with the
|
|
|
|
# globally installed version. This will take `$PYTHONUSERBASE` and `$PIP_USER`
|
|
|
|
# into account.
|
|
|
|
# See https://github.com/pypa/pip/issues/7205
|
|
|
|
export PIP_COMMAND=$(PYTHON_COMMAND) -m pip
|
2019-08-29 14:10:25 +03:00
|
|
|
APP=src/olympia/
|
|
|
|
|
2017-06-15 11:41:40 +03:00
|
|
|
NODE_MODULES := $(NPM_CONFIG_PREFIX)node_modules/
|
|
|
|
|
2024-05-06 13:50:34 +03:00
|
|
|
REQUIRED_FILES := \
|
|
|
|
Makefile \
|
|
|
|
Makefile-os \
|
|
|
|
Makefile-docker \
|
|
|
|
/deps/package.json \
|
|
|
|
/deps/package-lock.json \
|
|
|
|
/addons-server-docker-container \
|
|
|
|
|
2019-02-13 18:21:05 +03:00
|
|
|
.PHONY: help_redirect
|
2017-06-15 11:41:40 +03:00
|
|
|
help_redirect:
|
|
|
|
@$(MAKE) help --no-print-directory
|
|
|
|
|
2024-05-06 13:50:34 +03:00
|
|
|
.PHONY: check_debian_packages
|
|
|
|
check_debian_packages: ## check the existence of multiple debian packages
|
|
|
|
./scripts/check_debian_packages.sh
|
|
|
|
|
2024-05-20 13:34:34 +03:00
|
|
|
.PHONY: check_pip_packages
|
|
|
|
check_pip_packages: ## check the existence of multiple python packages
|
2024-10-18 18:39:49 +03:00
|
|
|
@ ./scripts/check_pip_packages.sh prod.txt
|
|
|
|
# "production" corresponds to the "propduction" DOCKER_TARGET defined in the Dockerfile
|
|
|
|
# When the target is "production" it means we cannot expect dev.txt dependencies to be installed.
|
|
|
|
@if [ "$(DOCKER_TARGET)" != "production" ]; then \
|
|
|
|
./scripts/check_pip_packages.sh dev.txt; \
|
|
|
|
fi
|
2024-05-20 13:34:34 +03:00
|
|
|
|
2024-05-06 13:50:34 +03:00
|
|
|
.PHONY: check_files
|
|
|
|
check_files: ## check the existence of multiple files
|
|
|
|
@for file in $(REQUIRED_FILES); do test -f "$$file" || (echo "$$file is missing." && exit 1); done
|
|
|
|
@echo "All required files are present."
|
|
|
|
|
|
|
|
.PHONY: check_olympia_user
|
|
|
|
check_olympia_user: ## check if the olympia user exists and is current user
|
|
|
|
@if [ "$$(id -u olympia)" != "$$(id -u)" ]; then echo "The current user is not the olympia user."; exit 1; fi
|
|
|
|
@echo "The current user is the olympia user."
|
|
|
|
|
2024-05-03 16:49:12 +03:00
|
|
|
.PHONY: check_django
|
|
|
|
check_django: ## check if the django app is configured properly
|
|
|
|
echo 'from olympia.lib.settings_base import *' > settings_local.py
|
|
|
|
DJANGO_SETTINGS_MODULE='settings_local' python3 ./manage.py check
|
|
|
|
rm settings_local.py
|
|
|
|
|
2024-10-07 18:51:50 +03:00
|
|
|
.PHONY: check_nginx
|
|
|
|
check_nginx: ## check if the nginx config for local development is configured properly
|
|
|
|
@if [ "$$(curl -sf http://nginx/user-media/.check)" != "OK" ]; then echo "Requesting http://nginx/user-media/.check failed"; exit 1; fi
|
|
|
|
@echo "Nginx user-media configuration looks correct."
|
|
|
|
|
2024-05-03 16:49:12 +03:00
|
|
|
.PHONY: check
|
2024-10-07 18:51:50 +03:00
|
|
|
check: check_nginx check_files check_olympia_user check_debian_packages check_pip_packages check_django
|
2024-05-03 16:49:12 +03:00
|
|
|
|
2024-09-26 20:12:21 +03:00
|
|
|
.PHONY: data_dump
|
|
|
|
data_dump:
|
|
|
|
./manage.py data_dump $(ARGS)
|
|
|
|
|
|
|
|
.PHONY: data_load
|
|
|
|
data_load:
|
|
|
|
./manage.py data_load $(ARGS)
|
|
|
|
|
2019-02-13 18:21:05 +03:00
|
|
|
.PHONY: update_assets
|
2017-06-15 11:41:40 +03:00
|
|
|
update_assets:
|
2024-03-01 13:47:11 +03:00
|
|
|
# Copy files required in compress_assets to the static folder
|
2018-10-11 11:35:46 +03:00
|
|
|
# If changing this here, make sure to adapt tests in amo/test_commands.py
|
2019-01-14 17:22:32 +03:00
|
|
|
$(PYTHON_COMMAND) manage.py compress_assets
|
2019-01-21 12:09:18 +03:00
|
|
|
$(PYTHON_COMMAND) manage.py generate_jsi18n_files
|
2024-03-05 17:50:07 +03:00
|
|
|
# Collect static files: This MUST be run last or files will be missing
|
|
|
|
$(PYTHON_COMMAND) manage.py collectstatic --noinput
|
2017-06-15 11:41:40 +03:00
|
|
|
|
|
|
|
|
2024-10-11 20:08:39 +03:00
|
|
|
# TOOD: remove this after we migrate addons-frontned to not depend on it.
|
2019-02-13 18:21:05 +03:00
|
|
|
.PHONY: setup-ui-tests
|
2018-04-25 12:32:40 +03:00
|
|
|
setup-ui-tests:
|
2024-10-11 20:08:39 +03:00
|
|
|
@echo "This is a deprecated target, please stop using it."
|
2018-04-25 12:32:40 +03:00
|
|
|
|
2020-05-15 16:53:13 +03:00
|
|
|
.PHONY: lint
|
|
|
|
lint: ## lint the code
|
2023-05-10 12:14:51 +03:00
|
|
|
ruff check .
|
2023-11-02 17:35:10 +03:00
|
|
|
ruff format --check .
|
2023-02-09 15:09:13 +03:00
|
|
|
NODE_PATH=$(NODE_MODULES) npm exec $(NPM_ARGS) -- prettier --check '**'
|
2020-09-29 12:56:33 +03:00
|
|
|
curlylint src/
|
2019-02-07 09:56:39 +03:00
|
|
|
|
2020-05-15 16:53:13 +03:00
|
|
|
lint-codestyle: lint
|
|
|
|
|
2019-02-13 18:21:05 +03:00
|
|
|
.PHONY: docs
|
2019-08-29 16:34:26 +03:00
|
|
|
docs: ## build the documentation
|
2019-02-13 18:21:05 +03:00
|
|
|
$(MAKE) -C docs html SPHINXOPTS='-nW'
|
|
|
|
|
2019-08-29 14:10:25 +03:00
|
|
|
.PHONY: djshell
|
2019-08-29 16:34:26 +03:00
|
|
|
djshell: ## connect to django shell
|
2019-08-29 14:10:25 +03:00
|
|
|
$(PYTHON_COMMAND) ./manage.py shell_plus
|
|
|
|
|
|
|
|
.PHONY: dbshell
|
2019-08-29 16:34:26 +03:00
|
|
|
dbshell: ## connect to a database shell
|
2019-08-29 14:10:25 +03:00
|
|
|
$(PYTHON_COMMAND) ./manage.py dbshell
|
|
|
|
|
2019-02-13 18:21:05 +03:00
|
|
|
.PHONY: initialize
|
2024-10-11 20:08:39 +03:00
|
|
|
initialize: ## ensure database exists
|
|
|
|
@echo "Initializing data..."
|
|
|
|
@echo "args: $(ARGS)"
|
|
|
|
$(PYTHON_COMMAND) ./manage.py initialize $(ARGS)
|
2019-08-29 14:10:25 +03:00
|
|
|
|
2024-06-13 17:59:58 +03:00
|
|
|
PYTEST_SRC := src/olympia/
|
2024-05-31 12:53:45 +03:00
|
|
|
|
|
|
|
.PHONY: test_needs_locales_compilation
|
|
|
|
test_needs_locales_compilation:
|
2024-06-13 17:59:58 +03:00
|
|
|
pytest $(PYTEST_SRC) \
|
2024-05-31 12:53:45 +03:00
|
|
|
-m 'needs_locales_compilation' \
|
2024-06-13 17:59:58 +03:00
|
|
|
$(ARGS)
|
2024-05-31 12:53:45 +03:00
|
|
|
|
|
|
|
.PHONY: test_static_assets
|
|
|
|
test_static_assets: run_js_tests
|
2024-06-13 17:59:58 +03:00
|
|
|
pytest $(PYTEST_SRC) \
|
2024-05-31 12:53:45 +03:00
|
|
|
-m 'static_assets' \
|
2024-06-13 17:59:58 +03:00
|
|
|
$(ARGS)
|
2024-05-31 12:53:45 +03:00
|
|
|
|
|
|
|
.PHONY: test_main
|
|
|
|
test_main:
|
2024-06-13 17:59:58 +03:00
|
|
|
pytest $(PYTEST_SRC) \
|
|
|
|
-n auto \
|
|
|
|
-m 'not es_tests and not needs_locales_compilation and not static_assets and not internal_routes_allowed' \
|
|
|
|
$(ARGS)
|
2024-05-31 12:53:45 +03:00
|
|
|
|
|
|
|
.PHONY: test_internal_routes_allowed
|
|
|
|
test_internal_routes_allowed:
|
|
|
|
# We need to change the setting in the file because we can't
|
|
|
|
# override an env variable here, and the next command requires
|
|
|
|
# `INTERNAL_ROUTES_ALLOWED` to be set to `True`.
|
|
|
|
sed -i 's/^INTERNAL_ROUTES_ALLOWED.*/INTERNAL_ROUTES_ALLOWED=True/' settings_test.py
|
2024-06-13 17:59:58 +03:00
|
|
|
pytest \
|
|
|
|
$(PYTEST_SRC) \
|
|
|
|
-m 'internal_routes_allowed' \
|
|
|
|
$(ARGS)
|
2024-05-31 12:53:45 +03:00
|
|
|
|
|
|
|
.PHONY: test_es_tests
|
|
|
|
test_es_tests:
|
|
|
|
pytest \
|
2024-06-13 17:59:58 +03:00
|
|
|
$(PYTEST_SRC) \
|
|
|
|
-m 'es_tests and not needs_locales_compilation and not static_assets' \
|
|
|
|
$(ARGS)
|
2024-05-31 12:53:45 +03:00
|
|
|
|
2019-08-29 14:10:25 +03:00
|
|
|
.PHONY: test
|
2019-08-29 16:34:26 +03:00
|
|
|
test: ## run the entire test suite
|
2024-06-13 17:59:58 +03:00
|
|
|
pytest \
|
|
|
|
$(PYTEST_SRC) \
|
|
|
|
$(ARGS)
|
2019-08-29 14:10:25 +03:00
|
|
|
|
|
|
|
.PHONY: test_es
|
2019-08-29 16:34:26 +03:00
|
|
|
test_es: ## run the ES tests
|
2024-06-13 17:59:58 +03:00
|
|
|
pytest \
|
|
|
|
$(PYTEST_SRC) \
|
|
|
|
-m es_tests \
|
|
|
|
$(ARGS)
|
2019-08-29 14:10:25 +03:00
|
|
|
|
|
|
|
.PHONY: test_no_es
|
2019-08-29 16:34:26 +03:00
|
|
|
test_no_es: ## run all but the ES tests
|
2024-06-13 17:59:58 +03:00
|
|
|
pytest \
|
|
|
|
$(PYTEST_SRC) \
|
|
|
|
-m "not es_tests" \
|
|
|
|
$(ARGS)
|
2019-08-29 14:10:25 +03:00
|
|
|
|
|
|
|
.PHONY: test_force_db
|
2019-08-29 16:34:26 +03:00
|
|
|
test_force_db: ## run the entire test suite with a new database
|
2024-06-13 17:59:58 +03:00
|
|
|
pytest \
|
|
|
|
$(PYTEST_SRC) \
|
|
|
|
--create-db \
|
|
|
|
$(ARGS)
|
2019-08-29 14:10:25 +03:00
|
|
|
|
|
|
|
.PHONY: tdd
|
2019-08-29 16:34:26 +03:00
|
|
|
tdd: ## run the entire test suite, but stop on the first error
|
2024-06-13 17:59:58 +03:00
|
|
|
pytest \
|
|
|
|
$(PYTEST_SRC) \
|
|
|
|
-x --pdb \
|
|
|
|
$(ARGS)
|
2019-08-29 14:10:25 +03:00
|
|
|
|
|
|
|
.PHONY: test_failed
|
2019-08-29 16:34:26 +03:00
|
|
|
test_failed: ## rerun the failed tests from the previous run
|
2024-06-13 17:59:58 +03:00
|
|
|
pytest \
|
|
|
|
$(PYTEST_SRC) \
|
|
|
|
--lf \
|
|
|
|
$(ARGS)
|
2019-08-29 16:34:26 +03:00
|
|
|
|
2020-07-30 15:00:07 +03:00
|
|
|
.PHONY: run_js_tests
|
|
|
|
run_js_tests: ## Run the JavaScript test suite (requires compiled/compressed assets).
|
2024-05-16 15:49:37 +03:00
|
|
|
NODE_PATH=$(NODE_MODULES) npm exec $(NPM_ARGS) -- jest tests/js
|
2020-07-30 15:00:07 +03:00
|
|
|
|
|
|
|
.PHONY: watch_js_tests
|
|
|
|
watch_js_tests: ## Run+watch the JavaScript test suite (requires compiled/compressed assets).
|
2023-02-09 15:09:13 +03:00
|
|
|
NODE_PATH=$(NODE_MODULES) npm exec $(NPM_ARGS) -- jest --watch
|
2019-08-29 16:34:26 +03:00
|
|
|
|
2020-08-03 15:55:07 +03:00
|
|
|
.PHONY: format
|
|
|
|
format: ## Autoformat our codebase.
|
2023-02-09 15:09:13 +03:00
|
|
|
NODE_PATH=$(NODE_MODULES) npm exec $(NPM_ARGS) -- prettier --write '**'
|
2023-05-10 12:14:51 +03:00
|
|
|
ruff check --fix-only .
|
2023-11-02 17:35:10 +03:00
|
|
|
ruff format .
|
2020-08-03 15:55:07 +03:00
|
|
|
|
2024-01-30 11:50:34 +03:00
|
|
|
.PHONY: extract_locales
|
|
|
|
extract_locales: ## extracts and merges translation strings
|
|
|
|
./scripts/run_l10n_extraction.sh
|
|
|
|
|
2024-04-29 14:45:47 +03:00
|
|
|
.PHONE: compile_locales
|
|
|
|
compile_locales: ## compiles translation strings
|
2024-09-10 19:56:33 +03:00
|
|
|
$(PIP_COMMAND) install --progress-bar=off --no-deps -r requirements/locale.txt
|
2024-04-29 14:45:47 +03:00
|
|
|
./locale/compile-mo.sh ./locale/
|
|
|
|
|
2019-08-29 16:34:26 +03:00
|
|
|
.PHONY: help_submake
|
|
|
|
help_submake:
|
2019-09-12 19:48:45 +03:00
|
|
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile-docker | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|