Skip to content

Commit

Permalink
Merge pull request #132 from django-commons/develop
Browse files Browse the repository at this point in the history
Merge v2.3.0
  • Loading branch information
bckohan authored Oct 13, 2024
2 parents 6758c33 + e0e213a commit 4f1bedb
Show file tree
Hide file tree
Showing 75 changed files with 1,409 additions and 376 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: lint
name: Lint

on:
push:
Expand All @@ -18,26 +18,21 @@ jobs:
strategy:
matrix:
# run static analysis on bleeding and trailing edges
python-version: [ '3.8', '3.10', '3.12' ]
python-version: [ '3.9', '3.10', '3.13' ]
django-version:
- '3.2' # LTS April 2024
- '4.2' # LTS April 2026
- '5.0' # April 2025
- '5.1' # December 2025
exclude:
- python-version: '3.8'
- python-version: '3.9'
django-version: '4.2'
- python-version: '3.12'
- python-version: '3.13'
django-version: '4.2'
- python-version: '3.12'
- python-version: '3.13'
django-version: '3.2'
- python-version: '3.10'
django-version: '3.2'
- python-version: '3.8'
django-version: '5.0'
- python-version: '3.10'
django-version: '5.0'
- python-version: '3.8'
- python-version: '3.9'
django-version: '5.1'
- python-version: '3.10'
django-version: '5.1'
Expand Down
153 changes: 153 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
##
# Derived from:
# https://github.com/django-commons/django-commons-playground/blob/main/.github/workflows/release.yml
#

name: Publish Release

on:
push:
tags:
- 'v*' # only publish on version tags (e.g. v1.0.0)
workflow_dispatch:
inputs:
pypi:
description: 'Publish to PyPi'
required: true
default: false
type: boolean
github:
description: 'Publish a GitHub Release'
required: true
default: false
type: boolean
testpypi:
description: 'Publish to TestPyPi'
required: true
default: true
type: boolean

env:
PYPI_URL: https://pypi.org/p/django-typer
PYPI_TEST_URL: https://test.pypi.org/project/django-typer

jobs:

build:
name: Build Package
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run:
python3 -m pip install build --user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: Publish to PyPI
if: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.pypi == 'true') || github.event_name != 'workflow_dispatch' }}
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: ${{ env.PYPI_URL }}
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1.10

github-release:
name: Publish GitHub Release
if: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.github == 'true') || github.event_name != 'workflow_dispatch' }}
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v3
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--generate-notes
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
publish-to-testpypi:
name: Publish to TestPyPI
if: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.testpypi == 'true') || github.event_name != 'workflow_dispatch' }}
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: ${{ env.PYPI_TEST_URL }}

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1.10
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true

notify-django-packages:
name: Notify Django Packages
runs-on: ubuntu-latest
needs:
- publish-to-pypi
steps:
- name: Notify Django Packages
run:
curl -X GET "https://djangopackages.org/packages/django-typer/fetch-data/"
38 changes: 14 additions & 24 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test
name: Test

on:
push:
Expand All @@ -19,30 +19,26 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13.0-rc.2']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
django-version:
- '3.2' # LTS April 2024
- '4.2' # LTS April 2026
- '5.0' # April 2025
- '5.1' # December 2025
exclude:
- python-version: '3.8'
django-version: '5.0'
- python-version: '3.9'
django-version: '5.0'
- python-version: '3.11'
django-version: '3.2'
- python-version: '3.12'
django-version: '3.2'
- python-version: '3.8'
django-version: '5.1'
- python-version: '3.9'
django-version: '5.1'
- python-version: '3.13.0-rc.2'
- python-version: '3.13'
django-version: '3.2'
- python-version: '3.13.0-rc.2'
- python-version: '3.13'
django-version: '4.2'
- python-version: '3.13.0-rc.2'
- python-version: '3.13'
django-version: '5.0'

steps:
Expand All @@ -57,9 +53,6 @@ jobs:
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install libopenblas-dev
if: matrix.python-version == '3.13.0-rc.2'
run: sudo apt-get install libopenblas-dev
- name: Install Release Dependencies
run: |
poetry config virtualenvs.in-project true
Expand Down Expand Up @@ -96,14 +89,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.12']
python-version: ['3.9', '3.13']
django-version:
- '3.2' # LTS April 2024
- '5.1' # December 2025
exclude:
- python-version: '3.8'
- python-version: '3.9'
django-version: '5.1'
- python-version: '3.12'
- python-version: '3.13'
django-version: '3.2'

steps:
Expand Down Expand Up @@ -153,14 +146,14 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
python-version: ['3.8', '3.12']
python-version: ['3.9', '3.13']
django-version:
- '3.2' # LTS April 2024
- '5.1' # December 2025
exclude:
- python-version: '3.8'
- python-version: '3.9'
django-version: '5.1'
- python-version: '3.12'
- python-version: '3.13'
django-version: '3.2'

steps:
Expand Down Expand Up @@ -237,14 +230,14 @@ jobs:
# runs-on: windows-latest
# strategy:
# matrix:
# python-version: ['3.8', '3.12']
# python-version: ['3.9', '3.13']
# django-version:
# - '3.2' # LTS April 2024
# - '5.0' # April 2025
# exclude:
# - python-version: '3.8'
# - python-version: '3.9'
# django-version: '5.0'
# - python-version: '3.12'
# - python-version: '3.13'
# django-version: '3.2'

# steps:
Expand Down Expand Up @@ -297,9 +290,6 @@ jobs:
timeout-minutes: 60
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Poetry
uses: snok/install-poetry@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,4 @@ poetry.lock
.vscode
django_typer/tests/dj_params.json
**/.DS_Store
.ruff_cache
2 changes: 1 addition & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Architecture

The principal design challenge of [django-typer](https://pypi.python.org/pypi/django-typer) is to manage the [Typer](https://typer.tiangolo.com/) app trees associated with each Django management command class and to keep these trees separate when classes are inherited and allow them to be edited directly when commands are extended through the plugin pattern. There are also incurred complexities with adding default django options where appropriate and supporting command callbacks as methods or static functions. Supporting dynamic command/group access through attributes on command instances also requires careful usage of advanced Python features.
The principal design challenge of [django-typer](https://pypi.python.org/pypi/django-typer) is to manage the [Typer](https://typer.tiangolo.com/) app trees associated with each Django management command class and to keep these trees separate when classes are inherited and allow them to be edited directly when commands are extended through the plugin pattern. There are also incurred complexities with adding default django options where appropriate and supporting command callbacks as methods or static functions. Supporting dynamic command/group access through attributes on command instances also requires careful usage of esoteric Python features.

The [Typer](https://typer.tiangolo.com/) app tree defines the layers of groups and commands that define the CLI. Each [TyperCommand](https://django-typer.readthedocs.io/en/latest/reference.html#django_typer.TyperCommand) maintains its own app tree defined by a root [Typer](https://django-typer.readthedocs.io/en/latest/reference.html#django_typer.management.Typer) node. When other classes inherit from a base command class, that app tree is copied and the new class can modify it without affecting the base class's tree. We extend [Typer](https://typer.tiangolo.com/)'s Typer type with our own [Typer](https://django-typer.readthedocs.io/en/latest/reference.html#django_typer.management.Typer) class that adds additional bookkeeping and attribute resolution features we need.

Expand Down
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
[![PyPI djversions](https://img.shields.io/pypi/djversions/django-typer.svg)](https://pypi.org/project/django-typer/)
[![PyPI status](https://img.shields.io/pypi/status/django-typer.svg)](https://pypi.python.org/pypi/django-typer)
[![Documentation Status](https://readthedocs.org/projects/django-typer/badge/?version=latest)](http://django-typer.readthedocs.io/?badge=latest/)
[![Code Cov](https://codecov.io/gh/bckohan/django-typer/branch/main/graph/badge.svg?token=0IZOKN2DYL)](https://codecov.io/gh/bckohan/django-typer)
[![Test Status](https://github.com/bckohan/django-typer/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/bckohan/django-typer/actions/workflows/test.yml?query=branch:main)
[![Lint Status](https://github.com/bckohan/django-typer/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/bckohan/django-typer/actions/workflows/lint.yml?query=branch:main)
[![Code Cov](https://codecov.io/gh/django-commons/django-typer/branch/main/graph/badge.svg?token=0IZOKN2DYL)](https://codecov.io/gh/django-commons/django-typer)
[![Test Status](https://github.com/django-commons/django-typer/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/django-commons/django-typer/actions/workflows/test.yml?query=branch:main)
[![Lint Status](https://github.com/django-commons/django-typer/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/django-commons/django-typer/actions/workflows/lint.yml?query=branch:main)
[![Published on Django Packages](https://img.shields.io/badge/Published%20on-Django%20Packages-0c3c26)](https://djangopackages.org/packages/p/django-typer/)

Use static typing to define the CLI for your [Django](https://www.djangoproject.com/) management commands with [Typer](https://typer.tiangolo.com/). Optionally use the provided [TyperCommand](https://django-typer.readthedocs.io/en/latest/reference.html#django_typer.TyperCommand) class that inherits from [BaseCommand](https://docs.djangoproject.com/en/stable/howto/custom-management-commands/#django.core.management.BaseCommand). This class maps the [Typer](https://typer.tiangolo.com/) interface onto a class based interface that Django developers will be familiar with. All of the [BaseCommand](https://docs.djangoproject.com/en/stable/howto/custom-management-commands/#django.core.management.BaseCommand) functionality is preserved, so that [TyperCommand](https://django-typer.readthedocs.io/en/latest/reference.html#django_typer.TyperCommand) can be a drop in replacement.

Expand All @@ -29,7 +30,7 @@ Use static typing to define the CLI for your [Django](https://www.djangoproject.

Please refer to the [full documentation](https://django-typer.readthedocs.io/) for more information.

![django-typer example](https://raw.githubusercontent.com/bckohan/django-typer/main/doc/source/_static/img/closepoll_example.gif)
![django-typer example](https://raw.githubusercontent.com/django-commons/django-typer/main/doc/source/_static/img/closepoll_example.gif)

## 🚨 Deprecation Notice

Expand Down Expand Up @@ -70,7 +71,7 @@ Please refer to the [full documentation](https://django-typer.readthedocs.io/) f

## Basic Example

[TyperCommand](https://django-typer.readthedocs.io/en/latest/reference.html#django_typer.TyperCommand) is a very simple drop in replacement for [BaseCommand](https://docs.djangoproject.com/en/stable/howto/custom-management-commands/#django.core.management.BaseCommand). All of the documented features of [BaseCommand](https://docs.djangoproject.com/en/stable/howto/custom-management-commands/#django.core.management.BaseCommand) work the same way!
[TyperCommand](https://django-typer.readthedocs.io/en/latest/reference.html#django_typer.TyperCommand) is a drop in extension to [BaseCommand](https://docs.djangoproject.com/en/stable/howto/custom-management-commands/#django.core.management.BaseCommand). All of the documented features of [BaseCommand](https://docs.djangoproject.com/en/stable/howto/custom-management-commands/#django.core.management.BaseCommand) work the same way!

```python
from django_typer.management import TyperCommand
Expand All @@ -96,7 +97,7 @@ def main(arg1: str, arg2: str, arg3: float = 0.5, arg4: int = 1):
"""
```

![Basic Example](https://raw.githubusercontent.com/bckohan/django-typer/main/examples/helps/basic.svg)
![Basic Example](https://raw.githubusercontent.com/django-commons/django-typer/main/examples/helps/basic.svg)

## Multiple Subcommands Example

Expand Down Expand Up @@ -165,9 +166,9 @@ def delete(
"""
```

![Multiple Subcommands Example](https://raw.githubusercontent.com/bckohan/django-typer/main/examples/helps/multi.svg)
![Multiple Subcommands Example - create](https://raw.githubusercontent.com/bckohan/django-typer/main/examples/helps/multi_create.svg)
![Multiple Subcommands Example - delete](https://raw.githubusercontent.com/bckohan/django-typer/main/examples/helps/multi_delete.svg)
![Multiple Subcommands Example](https://raw.githubusercontent.com/django-commons/django-typer/main/examples/helps/multi.svg)
![Multiple Subcommands Example - create](https://raw.githubusercontent.com/django-commons/django-typer/main/examples/helps/multi_create.svg)
![Multiple Subcommands Example - delete](https://raw.githubusercontent.com/django-commons/django-typer/main/examples/helps/multi_delete.svg)


## Grouping and Hierarchies Example
Expand Down Expand Up @@ -288,7 +289,7 @@ def divide(
return f"{numerator / denominator:.{self.precision}f}"
```

![Grouping and Hierarchies Example](https://raw.githubusercontent.com/bckohan/django-typer/main/examples/helps/hierarchy.svg)
![Grouping and Hierarchies Example - math](https://raw.githubusercontent.com/bckohan/django-typer/main/examples/helps/hierarchy_math.svg)
![Grouping and Hierarchies Example - math multiply](https://raw.githubusercontent.com/bckohan/django-typer/main/examples/helps/hierarchy_math_multiply.svg)
![Grouping and Hierarchies Example - math divide](https://raw.githubusercontent.com/bckohan/django-typer/main/examples/helps/hierarchy_math_divide.svg)
![Grouping and Hierarchies Example](https://raw.githubusercontent.com/django-commons/django-typer/main/examples/helps/hierarchy.svg)
![Grouping and Hierarchies Example - math](https://raw.githubusercontent.com/django-commons/django-typer/main/examples/helps/hierarchy_math.svg)
![Grouping and Hierarchies Example - math multiply](https://raw.githubusercontent.com/django-commons/django-typer/main/examples/helps/hierarchy_math_multiply.svg)
![Grouping and Hierarchies Example - math divide](https://raw.githubusercontent.com/django-commons/django-typer/main/examples/helps/hierarchy_math_divide.svg)
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Only the latest version of django-typer [![PyPI version](https://badge.fury.io/p

## Reporting a Vulnerability

If you think you have found a vulnerability, and even if you are not sure, please [report it to us in private](https://github.com/bckohan/django-typer/security/advisories/new). We will review it and get back to you. Please refrain from public discussions of the issue.
If you think you have found a vulnerability, and even if you are not sure, please [report it to us in private](https://github.com/django-commons/django-typer/security/advisories/new). We will review it and get back to you. Please refrain from public discussions of the issue.
Loading

0 comments on commit 4f1bedb

Please sign in to comment.