<commit_before># Shortcut to activate the virtual environment during development
VE := . venv/bin/activate ;

# Shortcut to set required environment variables during development
# Uses a custom `env.sh` or falls back to `env-example.sh`
EV := test -f ./env.sh && . ./env.sh || . ./env-example.sh ;

# Shortcut to run a Django manage.py task in the virtual environment
DJ ?= $(VE) $(EV) python3 manage.py

all: setup run

# Setup
# This exists just for consistency across projects;
# aliases to setting up the dev environment.
setup: venv-dev

# Setup virtual environment
venv: requirements.txt
	python3 -m venv venv
	$(VE) pip3 install -r requirements.txt
	touch venv

# Setup DEV virtual environment
venv-dev: requirements.txt requirements-dev.txt
	python3 -m venv venv
	$(VE) pip3 install -r requirements.txt
	$(VE) pip3 install -r requirements-dev.txt
	touch venv

# Build any static files
# Needs `venv` to setup virtualenv for Django collectstatic
# Uses Prod to avoid collecting static assets from packages not used in production e.g debug-toolbar
static: venv
	export DJANGO_CONFIGURATION="Prod"; $(DJ) collectstatic --noinput
.PHONY: static

# Create migrations
migrations: venv
	$(DJ) makemigrations

# Build a development database
create-devdb: venv
	rm -f db.sqlite3
	$(DJ) migrate
	$(DJ) runscript create_dev_users
	$(DJ) runscript create_dev_accounts
	$(DJ) runscript create_dev_account_roles
	$(DJ) runscript create_dev_projects
	$(DJ) runscript create_dev_project_roles

# Migrate the development database
migrate-devdb: venv
	$(DJ) migrate

# Migrate the production database
# Setting the DJANGO_CONFIGURATION to prod is necessary
# to avoid attempting to import apps that are not available in prod e.g. debug toolbar
migrate-proddb:
    DJANGO_CONFIGURATION="Prod" python3 manage.py migrate

# Run development server
run: venv
	$(DJ) runserver

# Lint everything
lint: lint-code lint-types lint-docs
	
# Lint code
lint-code:
	$(VE) flake8 --exclude=venv,migrations,storage --max-line-length=120 .

# Lint types
lint-types:
	$(VE) mypy --config-file mypy.ini .

# Lint docs
lint-docs:
	$(VE) pydocstyle --match-dir='^(?!venv|\\.|migrations|tests|scripts|storage).*' .

# Run tests
test: venv
	$(VE) python3 -m pytest --ignore ./tests
	$(VE) python3 -m pytest ./tests

# Run tests with coverage
cover: venv
	$(VE) python3 -m pytest --ignore ./tests --cov=. --cov-report term --cov-report html --cov-report xml
	$(VE) python3 -m pytest ./tests --cov=. --cov-report term --cov-report html --cov-report xml --cov-append

# Build Docker image
build: Dockerfile
	docker build --tag stencila/hub-director .

# Run the Docker image passing through
# environment variables required for `Prod` settings
# but using development database
# Add `-e DJANGO_CONFIGURATION="Dev"` to run in Dev mode instead.
run-docker: build
	$(EV) \
	docker run \
		-e DJANGO_SECURE_SSL_REDIRECT="False" \
		-e DJANGO_SECRET_KEY \
		-e DJANGO_JWT_SECRET \
		-e DJANGO_BETA_TOKEN \
		-e DJANGO_SENDGRID_API_KEY \
		-v $$PWD/db.sqlite3:/home/director/db.sqlite3:rw \
		-v $$PWD/storage:/home/director/storage:rw \
		-v $$PWD/secrets:/home/director/secrets:ro \<commit_msg>chore(Makefile): Refer to venv/bin instead of using activate script<commit_after># Shortcut to refer to programs in the virtual environment during development
VE := venv/bin

# Shortcut to set required environment variables during development
# Uses a custom `env.sh` or falls back to `env-example.sh`
EV := test -f ./env.sh && . ./env.sh || . ./env-example.sh ;

# Shortcut to run a Django manage.py task in the virtual environment
DJ ?= $(EV) $(VE)/python3 manage.py

all: setup run

# Setup
# This exists just for consistency across projects;
# aliases to setting up the dev environment.
setup: venv-dev

# Setup virtual environment
venv: requirements.txt
	python3 -m venv venv
	$(VE)/pip3 install -r requirements.txt
	touch venv

# Setup DEV virtual environment
venv-dev: requirements.txt requirements-dev.txt
	python3 -m venv venv
	$(VE)/pip3 install -r requirements.txt
	$(VE)/pip3 install -r requirements-dev.txt
	touch venv

# Build any static files
# Needs `venv` to setup virtualenv for Django collectstatic
# Uses Prod to avoid collecting static assets from packages not used in production e.g debug-toolbar
static: venv
	export DJANGO_CONFIGURATION="Prod"; $(DJ) collectstatic --noinput
.PHONY: static

# Create migrations
migrations: venv
	$(DJ) makemigrations

# Build a development database
create-devdb: venv
	rm -f db.sqlite3
	$(DJ) migrate
	$(DJ) runscript create_dev_users
	$(DJ) runscript create_dev_accounts
	$(DJ) runscript create_dev_account_roles
	$(DJ) runscript create_dev_projects
	$(DJ) runscript create_dev_project_roles

# Migrate the development database
migrate-devdb: venv
	$(DJ) migrate

# Migrate the production database
# Setting the DJANGO_CONFIGURATION to prod is necessary
# to avoid attempting to import apps that are not available in prod e.g. debug toolbar
migrate-proddb:
    DJANGO_CONFIGURATION="Prod" python3 manage.py migrate

# Run development server
run: venv
	$(DJ) runserver

# Lint everything
lint: lint-code lint-types lint-docs
	
# Lint code
lint-code:
	$(VE)/flake8 --exclude=venv,migrations,storage --max-line-length=120 .

# Lint types
lint-types:
	$(VE)/mypy --config-file mypy.ini .

# Lint docs
lint-docs:
	$(VE)/pydocstyle --match-dir='^(?!venv|\\.|migrations|tests|scripts|storage).*' .

# Run tests
test: venv
	$(VE)/python3 -m pytest --ignore ./tests
	$(VE)/python3 -m pytest ./tests

# Run tests with coverage
cover: venv
	$(VE)/python3 -m pytest --ignore ./tests --cov=. --cov-report term --cov-report html --cov-report xml
	$(VE)/python3 -m pytest ./tests --cov=. --cov-report term --cov-report html --cov-report xml --cov-append

# Build Docker image
build: Dockerfile
	docker build --tag stencila/hub-director .

# Run the Docker image passing through
# environment variables required for `Prod` settings
# but using development database
# Add `-e DJANGO_CONFIGURATION="Dev"` to run in Dev mode instead.
run-docker: build
	$(EV) \
	docker run \
		-e DJANGO_SECURE_SSL_REDIRECT="False" \
		-e DJANGO_SECRET_KEY \
		-e DJANGO_JWT_SECRET \
		-e DJANGO_BETA_TOKEN \
		-e DJANGO_SENDGRID_API_KEY \
		-v $$PWD/db.sqlite3:/home/director/db.sqlite3:rw \
		-v $$PWD/storage:/home/director/storage:rw \
		-v $$PWD/secrets:/home/director/secrets:ro \
{'fraction_non_alphanumeric': 0.11126826968411127, 'fraction_numerical': 0.005657708628005658, 'mean_word_length': 4.007081038552321, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '760016', 'n_tokens_mistral': 2233, 'n_tokens_neox': 2145, 'n_words': 702}