Skip to content

Commit 163e1c2

Browse files
authored
Merge pull request #25 from hakbailey/refactor-settings
Refactor settings, tox config, and fix linting/type hint errors
2 parents adc9fe2 + caae175 commit 163e1c2

31 files changed

+1138
-508
lines changed

.github/workflows/checks.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
name: Checks
3+
4+
concurrency:
5+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
6+
cancel-in-progress: true
7+
8+
on:
9+
pull_request:
10+
branches:
11+
- main
12+
- stable-*
13+
tags:
14+
- "*"
15+
16+
jobs:
17+
schema-check:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.13"
28+
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
python -m pip install tox
33+
34+
- name: Run schema checks
35+
run: tox -e check
36+
37+
type-check:
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@v4
43+
44+
- name: Set up Python
45+
uses: actions/setup-python@v5
46+
with:
47+
python-version: "3.13"
48+
49+
- name: Install dependencies
50+
run: |
51+
python -m pip install --upgrade pip
52+
python -m pip install tox
53+
54+
- name: Run schema checks
55+
run: tox -e type

.github/workflows/linters.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ concurrency:
55
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
66
cancel-in-progress: true
77

8-
on: # yamllint disable-line rule:truthy
8+
on:
99
pull_request:
1010
branches:
1111
- main
@@ -14,8 +14,22 @@ on: # yamllint disable-line rule:truthy
1414
- "*"
1515

1616
jobs:
17-
linters:
18-
name: Linters
19-
uses: ansible-network/github_actions/.github/workflows/tox.yml@main
20-
with:
21-
envname: linters
17+
lint:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.13"
28+
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
python -m pip install tox
33+
34+
- name: Run unit tests
35+
run: tox -e lint

.github/workflows/units.yml renamed to .github/workflows/tests.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Unit Tests
1+
name: Tests
22

33
on:
44
pull_request:
@@ -25,15 +25,12 @@ jobs:
2525
- name: Set up Python
2626
uses: actions/setup-python@v5
2727
with:
28-
python-version: '3.11'
28+
python-version: "3.13"
2929

3030
- name: Install dependencies
3131
run: |
3232
python -m pip install --upgrade pip
33-
pip install -r requirements/requirements-dev.txt
33+
python -m pip install tox
3434
35-
- name: Run migrations
36-
run: python manage.py migrate
37-
38-
- name: Run core tests
39-
run: python manage.py test core
35+
- name: Run unit tests
36+
run: tox -e test

.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/

.pre-commit-config.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ repos:
2323
args: [--indent=4, --no-sort-keys]
2424
- id: trailing-whitespace
2525

26-
- repo: https://github.com/psf/black
26+
- repo: https://github.com/psf/black-pre-commit-mirror
2727
rev: 25.1.0
2828
hooks:
2929
- id: black
30+
args: [--config, pyproject.toml]
3031

3132
- repo: https://github.com/PyCQA/flake8
3233
rev: 7.3.0
3334
hooks:
3435
- id: flake8
36+
args: [--max-line-length, "90"]
3537

3638
- repo: https://github.com/ikamensh/flynt/
3739
rev: 1.0.1
@@ -42,9 +44,11 @@ repos:
4244
rev: 6.0.1
4345
hooks:
4446
- id: isort
45-
name: isort (python)
47+
args: [--settings-path, pyproject.toml]
4648

4749
- repo: https://github.com/pre-commit/mirrors-mypy
4850
rev: v1.17.0
4951
hooks:
5052
- id: mypy
53+
pass_filenames: false
54+
args: [--config-file=pyproject.toml, --ignore-missing-imports, "."]

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

@@ -20,15 +23,17 @@ Hi there! We're excited to have you as a contributor.
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
- This repository uses a`pre-commit`, configuration, so ensure that you install pre-commit globally for your user, or by using pipx.
2225

23-
### Build and Run the Development Environment
26+
## Build and Run the Development Environment
2427

25-
#### Clone the repo
28+
### Clone the repo
2629

2730
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).
2831
For more on how to clone the repo, view [git clone help](https://git-scm.com/docs/git-clone).
2932
Once you have a local copy, run the commands in the following sections from the root of the project tree.
3033

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

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

@@ -38,12 +43,37 @@ Set the virtual environment
3843

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

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

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

45-
#### Configure and run the application
54+
```bash
55+
PATTERN_SERVICE_MODE=development
56+
```
57+
58+
### Configure and run the application
4659

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

49-
The application can be reached in your browser at `https://localhost:8000/`
62+
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/`.
63+
64+
## Updating dependencies
65+
66+
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.
67+
68+
To add a new dependency:
69+
70+
1. Add the package to the appropriate project or optional dependencies section of the pyproject.toml file, using dependency specifiers to constrain versions.
71+
2. Update the requirements files with the command `make requirements`. This should update the relevant requirements.txt files in the project's requirements directory.
72+
73+
## Running tests, linters, and code checks
74+
75+
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`.
76+
77+
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.
78+
s
79+
To run all tests and checks, simply run `tox` with no options.

Makefile

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,45 @@
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
717

8-
# Build the Docker image
9-
build:
18+
ensure-namespace:
19+
@test -n "$$QUAY_NAMESPACE" || (echo "Error: QUAY_NAMESPACE is required to push quay.io" && exit 1)
20+
21+
.PHONY: build
22+
build: ## Build the container image
1023
@echo "Building container image..."
1124
$(CONTAINER_RUNTIME) build -t $(IMAGE_NAME):$(IMAGE_TAG) -f Dockerfile.dev --arch amd64 .
1225

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:
26+
.PHONY: clean
27+
clean: ## Remove container image
2028
@echo "Cleaning up..."
2129
$(CONTAINER_RUNTIME) rmi -f $(IMAGE_NAME):$(IMAGE_TAG) || true
2230

23-
# Tag and push to Quay.io
24-
push: ensure-namespace build
25-
@echo "Tagging and pushing to registry..."
31+
.PHONY: push
32+
push: ensure-namespace build ## Tag and push container image to Quay.io
33+
@echo "Tagging and pushing to quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)..."
2634
$(CONTAINER_RUNTIME) tag $(IMAGE_NAME):$(IMAGE_TAG) quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)
2735
$(CONTAINER_RUNTIME) push quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)
36+
37+
# -------------------------------------
38+
# Dependencies
39+
# -------------------------------------
40+
41+
.PHONY: requirements
42+
requirements: ## Generate requirements.txt files from pyproject.toml
43+
pip-compile -o requirements/requirements.txt pyproject.toml
44+
pip-compile --extra dev --extra test -o requirements/requirements-dev.txt pyproject.toml
45+
pip-compile --extra test -o requirements/requirements-test.txt pyproject.toml

0 commit comments

Comments
 (0)