Skip to content

Commit 9af6be2

Browse files
committed
Update project settings and tox config
1 parent 07cc837 commit 9af6be2

File tree

15 files changed

+543
-244
lines changed

15 files changed

+543
-244
lines changed

.gitignore

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pre-commit-user
1616
/.eggs
1717
.python-version
1818

19-
2019
# Testing
2120
.cache
2221
.coverage
@@ -49,3 +48,22 @@ tower-backup-*
4948

5049
# DB
5150
db.sqlite3
51+
*.db
52+
53+
# Environment variables
54+
.env
55+
.env.*
56+
*.env
57+
58+
# Linting
59+
.mypy_cache/
60+
61+
# Logs and temporary files
62+
*.log
63+
tmp/
64+
temp/
65+
66+
# Virtual environments
67+
.venv/
68+
venv/
69+
env/

CONTRIBUTING.md

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ Hi there! We're excited to have you as a contributor.
77
- [pattern-service](#pattern-service)
88
- [Table of contents](#table-of-contents)
99
- [Things to know prior to submitting code](#things-to-know-prior-to-submitting-code)
10-
- [Build and Run the Development Environment](#build-and-run-the-development-environment)
11-
- [Clone the repo](#clone-the-repo)
12-
- [Configure python environment](#configure-python-environment)
13-
- [Configure and run the application](#configure-and-run-the-application)
10+
- [Build and Run the Development Environment](#build-and-run-the-development-environment)
11+
- [Clone the repo](#clone-the-repo)
12+
- [Configure Python environment](#configure-python-environment)
13+
- [Set env variables for development](#set-env-variables-for-development)
14+
- [Configure and run the application](#configure-and-run-the-application)
15+
- [Updating dependencies](#updating-dependencies)
16+
- [Running tests, linters, and code checks](#running-tests-linters-and-code-checks)
1417

1518
## Things to know prior to submitting code
1619

@@ -19,15 +22,17 @@ Hi there! We're excited to have you as a contributor.
1922
- If collaborating with someone else on the same branch, consider using `--force-with-lease` instead of `--force`. This will prevent you from accidentally overwriting commits pushed by someone else. For more information, see [git push docs](https://git-scm.com/docs/git-push#git-push---force-with-leaseltrefnamegt).
2023
- We ask all of our community members and contributors to adhere to the [Ansible code of conduct](http://docs.ansible.com/ansible/latest/community/code_of_conduct.html). If you have questions, or need assistance, please reach out to our community team at [[email protected]](mailto:[email protected])
2124

22-
### Build and Run the Development Environment
25+
## Build and Run the Development Environment
2326

24-
#### Clone the repo
27+
### Clone the repo
2528

2629
If you have not already done so, you will need to clone, or create a local copy, of the [pattern-service repository](https://github.com/ansible/pattern-service).
2730
For more on how to clone the repo, view [git clone help](https://git-scm.com/docs/git-clone).
2831
Once you have a local copy, run the commands in the following sections from the root of the project tree.
2932

30-
#### Configure python environment
33+
### Configure Python environment
34+
35+
Ensure you are using a supported Python version, defined in the [pyproject.toml file](./pyproject.toml).
3136

3237
Create python virtual environment using one of the below commands:
3338

@@ -37,12 +42,37 @@ Set the virtual environment
3742

3843
`source /path/to/virtualenv/bin/activate/`
3944

40-
Install required python modules
45+
Install required python modules for development
46+
47+
`pip install -r requirements/requirements-dev.txt`
48+
49+
### Set env variables for development
4150

42-
`pip install -r ./requirements-all.txt`
51+
Either create a .env file in the project root containing the following env variables, or export them to your shell env:
4352

44-
#### Configure and run the application
53+
```bash
54+
PATTERN_SERVICE_MODE=development
55+
```
56+
57+
### Configure and run the application
4558

4659
`python manage.py migrate && python manage.py runserver`
4760

48-
The application can be reached in your browser at `https://localhost:8000/`
61+
The application can be reached in your browser at `https://localhost:8000/`. The Django admin UI is accessible at `https://localhost:8000/admin` and the available API endpoints will be listed in the 404 information at `http://localhost:8000/api/pattern-service/v1/`.
62+
63+
## Updating dependencies
64+
65+
Project dependencies for all environments are specified in the [pyproject.toml file](./pyproject.toml). A requirements.txt file is generated for each environment using pip-compile, to simplify dependency installation with pip.
66+
67+
To add a new dependency:
68+
69+
1. Add the package to the appropriate project or optional dependencies section of the pyproject.toml file, using dependency specifiers to constrain versions.
70+
2. Update the requirements files with the command `make requirements`. This should update the relevant requirements.txt files in the project's requirements directory.
71+
72+
## Running tests, linters, and code checks
73+
74+
Unit tests, linters, type checks, and other checks can all be run via `tox`. To see the available `tox` commands for this project, run `tox list`.
75+
76+
To run an individual tox command use the `-e` flag to specify the environment, for example: `tox -e test` to run tests with all supported python versions.
77+
s
78+
To run all tests and checks, simply run `tox` with no options.

Makefile

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
1-
.PHONY: build build-multi run test clean install-deps lint push-quay login-quay push-quay-multi
1+
.DEFAULT_GOAL := help
2+
3+
.PHONY: help
4+
help: ## Show this help message
5+
@grep -hE '^[a-zA-Z0-9._-]+:.*?##' $(MAKEFILE_LIST) | \
6+
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-24s\033[0m %s\n", $$1, $$2}' | \
7+
sort -u
8+
9+
10+
# -------------------------------------
11+
# Container image
12+
# -------------------------------------
213

3-
# Image name and tag
414
CONTAINER_RUNTIME ?= podman
5-
IMAGE_NAME ?= ansible-pattern-service
15+
IMAGE_NAME ?= pattern-service
616
IMAGE_TAG ?= latest
17+
QUAY_NAMESPACE ?= ansible
718

8-
# Build the Docker image
9-
build:
19+
.PHONY: build
20+
build: ## Build the container image
1021
@echo "Building container image..."
1122
$(CONTAINER_RUNTIME) build -t $(IMAGE_NAME):$(IMAGE_TAG) -f Dockerfile.dev --arch amd64 .
1223

13-
ensure-namespace:
14-
ifndef QUAY_NAMESPACE
15-
$(error QUAY_NAMESPACE is required to push quay.io)
16-
endif
17-
18-
# Clean up
19-
clean:
24+
.PHONY: clean
25+
clean: ## Remove container image
2026
@echo "Cleaning up..."
2127
$(CONTAINER_RUNTIME) rmi -f $(IMAGE_NAME):$(IMAGE_TAG) || true
2228

23-
# Tag and push to Quay.io
24-
push: ensure-namespace build
25-
@echo "Tagging and pushing to registry..."
29+
.PHONY: push
30+
push: ensure-namespace build ## Tag and push container image to Quay.io
31+
@echo "Tagging and pushing to quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)..."
2632
$(CONTAINER_RUNTIME) tag $(IMAGE_NAME):$(IMAGE_TAG) quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)
2733
$(CONTAINER_RUNTIME) push quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)
34+
35+
# -------------------------------------
36+
# Dependencies
37+
# -------------------------------------
38+
39+
.PHONY: requirements
40+
requirements: ## Generate requirements.txt files from pyproject.toml
41+
pip-compile -o requirements/requirements.txt pyproject.toml
42+
pip-compile --extra dev --extra test -o requirements/requirements-dev.txt pyproject.toml
43+
pip-compile --extra test -o requirements/requirements-test.txt pyproject.toml
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1+
import os
2+
13
from ansible_base.lib.dynamic_config import export
24
from ansible_base.lib.dynamic_config import factory
5+
from ansible_base.lib.dynamic_config import load_envvars
6+
from ansible_base.lib.dynamic_config import load_standard_settings_files
7+
8+
try:
9+
from dotenv import load_dotenv
10+
11+
load_dotenv()
12+
except ImportError:
13+
pass
14+
os.environ["PATTERN_SERVICE_MODE"] = os.environ.get(
15+
"PATTERN_SERVICE_MODE", "production"
16+
)
317

418
# Django Ansible Base Dynaconf settings
5-
DYNACONF = factory(__name__, "PATTERN_SERVICE", settings_files=["defaults.py"])
6-
# manipulate DYNACONF as needed
19+
DYNACONF = factory(
20+
__name__,
21+
"PATTERN_SERVICE",
22+
environments=("development", "production", "testing"),
23+
settings_files=["defaults.py"],
24+
)
25+
load_standard_settings_files(DYNACONF)
26+
load_envvars(DYNACONF)
727
export(__name__, DYNACONF)

pattern_service/settings/defaults.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,10 @@
1111
"""
1212

1313
from pathlib import Path
14-
from typing import List
1514

1615
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1716
BASE_DIR = Path(__file__).resolve().parent.parent
18-
19-
20-
# Quick-start development settings - unsuitable for production
21-
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
22-
23-
# SECURITY WARNING: keep the secret key used in production secret!
24-
SECRET_KEY = "django-insecure-_f^+pc=x%dd&p8ht4qv7rqr8&a%@j#lda6v!x9353m+)fm8&gk"
25-
26-
# SECURITY WARNING: don't run with debug turned on in production!
27-
DEBUG = True
28-
29-
ALLOWED_HOSTS: List[str] = ["localhost", "pattern-service", "127.0.0.1"]
30-
17+
DEBUG = False
3118

3219
# Application definition
3320

@@ -72,23 +59,14 @@
7259
WSGI_APPLICATION = "pattern_service.wsgi.application"
7360

7461

75-
# Database
76-
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
77-
78-
DATABASES = {
79-
"default": {
80-
"ENGINE": "django.db.backends.sqlite3",
81-
"NAME": BASE_DIR / "db.sqlite3",
82-
}
83-
}
84-
85-
8662
# Password validation
8763
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
8864

8965
AUTH_PASSWORD_VALIDATORS = [
9066
{
91-
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
67+
"NAME": (
68+
"django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
69+
),
9270
},
9371
{
9472
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from pathlib import Path
2+
3+
ALLOWED_HOSTS = ["localhost", "pattern-service", "127.0.0.1"]
4+
BASE_DIR = Path(__file__).resolve().parent.parent
5+
DEBUG = True
6+
SECRET_KEY = (
7+
"django-insecure-_f^+pc=x%dd&p8ht4qv7rqr8&a%@j#lda6v!x9353m+)fm8&gk" # notsecret
8+
)
9+
10+
DATABASES = {
11+
"default": {
12+
"ENGINE": "django.db.backends.sqlite3",
13+
"NAME": BASE_DIR / "db.sqlite3",
14+
}
15+
}
16+
17+
# Logging
18+
LOGGING = {
19+
"version": 1,
20+
"disable_existing_loggers": False,
21+
"formatters": {
22+
"simple": {
23+
"format": "{levelname} {name} {lineno} {message}",
24+
"style": "{",
25+
},
26+
},
27+
"handlers": {
28+
"console": {
29+
"level": DEBUG,
30+
"class": "logging.StreamHandler",
31+
"formatter": "simple",
32+
},
33+
},
34+
"filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
35+
"loggers": {
36+
"ansible_base": {
37+
"handlers": ["console"],
38+
"level": "DEBUG",
39+
},
40+
"core": {
41+
"handlers": ["console"],
42+
"level": "DEBUG",
43+
},
44+
"django": {
45+
"handlers": ["console"],
46+
"level": "INFO",
47+
},
48+
},
49+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pathlib import Path
2+
3+
ALLOWED_HOSTS = ["localhost", "pattern-service", "127.0.0.1"]
4+
BASE_DIR = Path(__file__).resolve().parent.parent
5+
SECRET_KEY = (
6+
"django-insecure-_f^+pc=x%dd&p8ht4qv7rqr8&a%@j#lda6v!x9353m+)fm8&gk" # notsecret
7+
)
8+
9+
DATABASES = {
10+
"default": {
11+
"ENGINE": "django.db.backends.sqlite3",
12+
"NAME": BASE_DIR / "db.sqlite3",
13+
}
14+
}

0 commit comments

Comments
 (0)