-
Notifications
You must be signed in to change notification settings - Fork 10
Refactor settings, tox config, and fix linting/type hint errors #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| --- | ||
| name: Checks | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} | ||
| cancel-in-progress: true | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| - stable-* | ||
| tags: | ||
| - "*" | ||
|
|
||
| jobs: | ||
| schema-check: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.13" | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| python -m pip install tox | ||
|
|
||
| - name: Run schema checks | ||
| run: tox -e check | ||
|
|
||
| type-check: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.13" | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| python -m pip install tox | ||
|
|
||
| - name: Run schema checks | ||
| run: tox -e type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,13 @@ Hi there! We're excited to have you as a contributor. | |
| - [pattern-service](#pattern-service) | ||
| - [Table of contents](#table-of-contents) | ||
| - [Things to know prior to submitting code](#things-to-know-prior-to-submitting-code) | ||
| - [Build and Run the Development Environment](#build-and-run-the-development-environment) | ||
| - [Clone the repo](#clone-the-repo) | ||
| - [Configure python environment](#configure-python-environment) | ||
| - [Configure and run the application](#configure-and-run-the-application) | ||
| - [Build and Run the Development Environment](#build-and-run-the-development-environment) | ||
| - [Clone the repo](#clone-the-repo) | ||
| - [Configure Python environment](#configure-python-environment) | ||
| - [Set env variables for development](#set-env-variables-for-development) | ||
| - [Configure and run the application](#configure-and-run-the-application) | ||
| - [Updating dependencies](#updating-dependencies) | ||
| - [Running tests, linters, and code checks](#running-tests-linters-and-code-checks) | ||
|
|
||
| ## Things to know prior to submitting code | ||
|
|
||
|
|
@@ -20,15 +23,17 @@ Hi there! We're excited to have you as a contributor. | |
| - 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]) | ||
| - This repository uses a`pre-commit`, configuration, so ensure that you install pre-commit globally for your user, or by using pipx. | ||
|
|
||
| ### Build and Run the Development Environment | ||
| ## Build and Run the Development Environment | ||
|
|
||
| #### Clone the repo | ||
| ### Clone the repo | ||
|
|
||
| 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). | ||
| For more on how to clone the repo, view [git clone help](https://git-scm.com/docs/git-clone). | ||
| Once you have a local copy, run the commands in the following sections from the root of the project tree. | ||
|
|
||
| #### Configure python environment | ||
| ### Configure Python environment | ||
|
|
||
| Ensure you are using a supported Python version, defined in the [pyproject.toml file](./pyproject.toml). | ||
|
|
||
| Create python virtual environment using one of the below commands: | ||
|
|
||
|
|
@@ -38,12 +43,37 @@ Set the virtual environment | |
|
|
||
| `source /path/to/virtualenv/bin/activate/` | ||
|
|
||
| Install required python modules | ||
| Install required python modules for development | ||
|
|
||
| `pip install -r requirements/requirements-dev.txt` | ||
|
|
||
| ### Set env variables for development | ||
|
|
||
| `pip install -r ./requirements-all.txt` | ||
| Either create a .env file in the project root containing the following env variables, or export them to your shell env: | ||
|
|
||
| #### Configure and run the application | ||
| ```bash | ||
| PATTERN_SERVICE_MODE=development | ||
| ``` | ||
|
|
||
| ### Configure and run the application | ||
|
|
||
| `python manage.py migrate && python manage.py runserver` | ||
|
|
||
| The application can be reached in your browser at `https://localhost:8000/` | ||
| 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/`. | ||
|
|
||
| ## Updating dependencies | ||
|
|
||
| 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. | ||
|
|
||
| To add a new dependency: | ||
|
|
||
| 1. Add the package to the appropriate project or optional dependencies section of the pyproject.toml file, using dependency specifiers to constrain versions. | ||
| 2. Update the requirements files with the command `make requirements`. This should update the relevant requirements.txt files in the project's requirements directory. | ||
|
|
||
| ## Running tests, linters, and code checks | ||
|
|
||
| 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`. | ||
|
|
||
| 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. | ||
| s | ||
| To run all tests and checks, simply run `tox` with no options. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,45 @@ | ||
| .PHONY: build build-multi run test clean install-deps lint push-quay login-quay push-quay-multi | ||
| .DEFAULT_GOAL := help | ||
|
|
||
| .PHONY: help | ||
| help: ## Show this help message | ||
| @grep -hE '^[a-zA-Z0-9._-]+:.*?##' $(MAKEFILE_LIST) | \ | ||
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-24s\033[0m %s\n", $$1, $$2}' | \ | ||
| sort -u | ||
|
|
||
|
|
||
| # ------------------------------------- | ||
| # Container image | ||
| # ------------------------------------- | ||
|
|
||
| # Image name and tag | ||
| CONTAINER_RUNTIME ?= podman | ||
| IMAGE_NAME ?= ansible-pattern-service | ||
| IMAGE_NAME ?= pattern-service | ||
| IMAGE_TAG ?= latest | ||
|
|
||
| # Build the Docker image | ||
| build: | ||
| ensure-namespace: | ||
| @test -n "$$QUAY_NAMESPACE" || (echo "Error: QUAY_NAMESPACE is required to push quay.io" && exit 1) | ||
|
|
||
| .PHONY: build | ||
| build: ## Build the container image | ||
| @echo "Building container image..." | ||
| $(CONTAINER_RUNTIME) build -t $(IMAGE_NAME):$(IMAGE_TAG) -f Dockerfile.dev --arch amd64 . | ||
|
|
||
| ensure-namespace: | ||
| ifndef QUAY_NAMESPACE | ||
| $(error QUAY_NAMESPACE is required to push quay.io) | ||
| endif | ||
|
|
||
| # Clean up | ||
| clean: | ||
| .PHONY: clean | ||
| clean: ## Remove container image | ||
| @echo "Cleaning up..." | ||
| $(CONTAINER_RUNTIME) rmi -f $(IMAGE_NAME):$(IMAGE_TAG) || true | ||
|
|
||
| # Tag and push to Quay.io | ||
| push: ensure-namespace build | ||
| @echo "Tagging and pushing to registry..." | ||
| .PHONY: push | ||
| push: ensure-namespace build ## Tag and push container image to Quay.io | ||
| @echo "Tagging and pushing to quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)..." | ||
| $(CONTAINER_RUNTIME) tag $(IMAGE_NAME):$(IMAGE_TAG) quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG) | ||
| $(CONTAINER_RUNTIME) push quay.io/$(QUAY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG) | ||
|
|
||
| # ------------------------------------- | ||
| # Dependencies | ||
| # ------------------------------------- | ||
|
|
||
| .PHONY: requirements | ||
| requirements: ## Generate requirements.txt files from pyproject.toml | ||
| pip-compile -o requirements/requirements.txt pyproject.toml | ||
| pip-compile --extra dev --extra test -o requirements/requirements-dev.txt pyproject.toml | ||
| pip-compile --extra test -o requirements/requirements-test.txt pyproject.toml | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.