Skip to content

Commit 8ffe6d0

Browse files
authored
Merge pull request #208 from django-commons/install_permission
Install permission
2 parents fe0ed31 + 99ad44c commit 8ffe6d0

File tree

47 files changed

+1807
-681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1807
-681
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
django-version:
2828
- '3.2' # LTS April 2024
2929
- '4.2' # LTS April 2026
30-
- '5.1' # December 2025
30+
- '5.2' # December 2025
3131
exclude:
3232
- python-version: '3.9'
3333
django-version: '4.2'
@@ -38,9 +38,9 @@ jobs:
3838
- python-version: '3.10'
3939
django-version: '3.2'
4040
- python-version: '3.9'
41-
django-version: '5.1'
41+
django-version: '5.2'
4242
- python-version: '3.10'
43-
django-version: '5.1'
43+
django-version: '5.2'
4444

4545
env:
4646
TEST_PYTHON_VERSION: ${{ matrix.python-version }}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- name: Set up Python
4646
uses: actions/setup-python@v5
4747
with:
48-
python-version: ">=3.11" # for tomlib
48+
python-version: "3.12" # for tomlib
4949
- name: Install uv
5050
uses: astral-sh/setup-uv@v5
5151
with:

.github/workflows/test.yml

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- '4.2' # LTS April 2026
3737
- '5.0' # April 2025
3838
- '5.1' # December 2025
39-
- '5.2b1'
39+
- '5.2' # April 2028
4040
exclude:
4141
- python-version: '3.9'
4242
django-version: '5.0'
@@ -53,7 +53,7 @@ jobs:
5353
- python-version: '3.13'
5454
django-version: '5.0'
5555
- python-version: '3.9'
56-
django-version: '5.2b1'
56+
django-version: '5.2'
5757
env:
5858
COVERAGE_FILE: py${{ matrix.python-version }}-linux-dj${{ matrix.django-version }}.coverage
5959
TEST_PYTHON_VERSION: ${{ matrix.python-version }}
@@ -85,11 +85,7 @@ jobs:
8585
uses: extractions/setup-just@v3
8686
- name: Install Dependencies
8787
run: |
88-
if [ "${{ matrix.django-version }}" = "5.2b1" ]; then
89-
just test-lock "Django==${{ matrix.django-version }}"
90-
else
91-
just test-lock "Django~=${{ matrix.django-version }}.0"
92-
fi
88+
just test-lock "Django~=${{ matrix.django-version }}.0"
9389
- name: Run Unit Tests
9490
run: |
9591
just test ./tests/verify_environment.py
@@ -112,10 +108,10 @@ jobs:
112108
python-version: ['3.9', '3.13']
113109
django-version:
114110
- '3.2' # LTS April 2024
115-
- '5.1' # December 2025
111+
- '5.2' # April 2028
116112
exclude:
117113
- python-version: '3.9'
118-
django-version: '5.1'
114+
django-version: '5.2'
119115
- python-version: '3.13'
120116
django-version: '3.2'
121117

@@ -170,10 +166,10 @@ jobs:
170166
python-version: ['3.9', '3.13']
171167
django-version:
172168
- '3.2' # LTS April 2024
173-
- '5.1' # December 2025
169+
- '5.2' # LTS April 2028
174170
exclude:
175171
- python-version: '3.9'
176-
django-version: '5.1'
172+
django-version: '5.2'
177173
- python-version: '3.13'
178174
django-version: '3.2'
179175

@@ -240,7 +236,7 @@ jobs:
240236
python-version: ['3.13']
241237
postgres-version: ['latest']
242238
django-version:
243-
- '5.1' # December 2025
239+
- '5.2' # April 2028
244240

245241
# Service containers to run with `runner-job`
246242
services:
@@ -309,10 +305,10 @@ jobs:
309305
python-version: ['3.9', '3.13']
310306
django-version:
311307
- '3.2' # LTS April 2024
312-
- '5.1' # December 2025
308+
- '5.2' # April 2028
313309
exclude:
314310
- python-version: '3.9'
315-
django-version: '5.1'
311+
django-version: '5.2'
316312
- python-version: '3.13'
317313
django-version: '3.2'
318314
env:
@@ -371,10 +367,10 @@ jobs:
371367
python-version: ['3.9', '3.13']
372368
django-version:
373369
- '3.2' # LTS April 2024
374-
- '5.1' # December 2025
370+
- '5.2' # April 2028
375371
exclude:
376372
- python-version: '3.9'
377-
django-version: '5.1'
373+
django-version: '5.2'
378374
- python-version: '3.13'
379375
django-version: '3.2'
380376
env:
@@ -435,10 +431,10 @@ jobs:
435431
python-version: ['3.9', '3.13']
436432
django-version:
437433
- '3.2' # LTS April 2024
438-
- '5.1' # December 2025
434+
- '5.2' # April 2028
439435
exclude:
440436
- python-version: '3.9'
441-
django-version: '5.1'
437+
django-version: '5.2'
442438
- python-version: '3.13'
443439
django-version: '3.2'
444440

@@ -506,10 +502,10 @@ jobs:
506502
python-version: ['3.9', '3.13']
507503
django-version:
508504
- '3.2' # LTS April 2024
509-
- '5.1' # December 2025
505+
- '5.2' # April 2028
510506
exclude:
511507
- python-version: '3.9'
512-
django-version: '5.1'
508+
django-version: '5.2'
513509
- python-version: '3.13'
514510
django-version: '3.2'
515511

@@ -567,10 +563,10 @@ jobs:
567563
python-version: ['3.9', '3.13']
568564
django-version:
569565
- '3.2' # LTS April 2024
570-
- '5.1' # December 2025
566+
- '5.2' # April 2028
571567
exclude:
572568
- python-version: '3.9'
573-
django-version: '5.1'
569+
django-version: '5.2'
574570
- python-version: '3.13'
575571
django-version: '3.2'
576572

@@ -682,9 +678,13 @@ jobs:
682678
shell: powershell
683679
- name: Run Powershell Tab Completion Tests
684680
run: |
685-
just test ./tests/verify_environment.py; if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
686-
.venv\Scripts\activate.ps1; cmd /c "pytest --cov-append ./tests/shellcompletion/test_shell_resolution.py::TestShellResolution::test_powershell"; if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
687-
just test-powershell; if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
681+
just test ./tests/verify_environment.py
682+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
683+
. .venv\Scripts\activate.ps1
684+
cmd /c "pytest --cov-append ./tests/shellcompletion/test_shell_resolution.py::TestShellResolution::test_powershell"
685+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
686+
just test-powershell
687+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
688688
shell: powershell
689689
- name: Test CMD shell failure
690690
run: |
@@ -753,8 +753,12 @@ jobs:
753753
- name: Run Powershell Tab Completion Tests
754754
run: |
755755
just test ./tests/verify_environment.py
756-
.venv\Scripts\activate.ps1; cmd /c "pytest --cov-append ./tests/shellcompletion/test_shell_resolution.py::TestShellResolution::test_pwsh"; if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
757-
just test-pwsh; if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
756+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
757+
. .venv\Scripts\activate.ps1
758+
cmd /c "pytest --cov-append ./tests/shellcompletion/test_shell_resolution.py::TestShellResolution::test_pwsh"
759+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
760+
just test-pwsh
761+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
758762
shell: pwsh
759763
- name: Test CMD shell failure
760764
run: |

doc/source/changelog.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44
Change Log
55
==========
66

7-
v3.1.0 (2024-03-xx)
7+
v3.1.0 (2024-04-02)
88
===================
99

10+
* Fixed `Fish shell completion fails for any script named something other than "manage" <https://github.com/django-commons/django-typer/issues/207>`_
11+
* Fixed `shellcompletion install fails on fish when the command resolves to a script path <https://github.com/django-commons/django-typer/issues/206>`_
12+
* Implemented `Add completer for settings names. <https://github.com/django-commons/django-typer/issues/203>`_
1013
* Fixed `Shell completion tests let failures through in CI <https://github.com/django-commons/django-typer/issues/194>`_
1114
* Fixed `fish completion installs should respect XDG_CONFIG_HOME <https://github.com/django-commons/django-typer/issues/193>`_
1215
* Fixed `zsh completion installs should respect ZDOTDIR <https://github.com/django-commons/django-typer/issues/192>`_
16+
* Implemented `Prompt before writing to dotfiles when installing completions <https://github.com/django-commons/django-typer/issues/189>`_
1317
* Implemented `Support Django 5.2 <https://github.com/django-commons/django-typer/issues/188>`_
1418
* Implemented `Use intersphinx for external document references. <https://github.com/django-commons/django-typer/issues/187>`_
19+
* Implemented `Add completer for language codes. <https://github.com/django-commons/django-typer/issues/186>`_
1520
* Implemented `Switch poetry -> uv <https://github.com/django-commons/django-typer/issues/185>`_
21+
* Implemented `Model object completers should handle fields with choices appropriately <https://github.com/django-commons/django-typer/issues/182>`_
1622
* Implemented `Require tests to pass before release action runs. <https://github.com/django-commons/django-typer/issues/173>`_
1723

1824

doc/source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
from sphinx.ext.autodoc import between
66
import shutil
77
import django
8+
from django.conf import settings
89

910
sys.path.append(str(Path(__file__).parent.parent.parent))
1011
sys.path.append(str(Path(__file__).parent / 'ext'))
1112

1213
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings.base')
14+
#settings.configure()
1315
django.setup()
1416

1517
import django_typer

doc/source/reference/completers.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ Completers
2323

2424
.. automodule:: django_typer.completers.path
2525
:members:
26+
27+
.. automodule:: django_typer.completers.settings
28+
:members:

doc/source/reference/shells.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
Shells
77
======
88

9+
.. automodule:: django_typer.shells
10+
:members: DjangoTyperShellCompleter, register_completion_class
11+
912
.. autoclass:: django_typer.shells.bash.BashComplete
1013
:members: name, template, color, supports_scripts
1114

doc/source/shell_completion.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ project simply run the install command:
134134
135135
./manage.py shellcompletion install
136136
137+
**The install command will list the precise edits to dotfiles and shell configuration files that it
138+
will make and ask for permission before proceeding. To skip the prompt use** ``--no-prompt``.
139+
137140
.. note::
138141

139142
The manage script may be named differently in your project - this is fine. The only requirement
@@ -509,6 +512,38 @@ parameter and the :class:`~django_typer.parsers.model.ReturnType` enumeration:
509512
...
510513
511514
515+
Fields with Choices
516+
~~~~~~~~~~~~~~~~~~~
517+
518+
The above examples using :func:`~django_typer.utils.model_parser_completer` will work for fields
519+
with choices. You may however want to avoid the database lookup given that the choice list is
520+
readily available. To do this you could use :func:`~django_typer.completers.these_strings` in
521+
combination with the :class:`~django_typer.parsers.model.ModelObjectParser`:
522+
523+
.. code-block:: python
524+
525+
from django_typer.parsers.model import ModelObjectParser, ReturnType
526+
527+
class Command(TyperCommand):
528+
def handle(
529+
self,
530+
query: Annotated[
531+
QuerySet[ModelClass],
532+
typer.Option(
533+
parser=ModelObjectParser(
534+
ModelClass,
535+
"choice_field,
536+
return_type=ReturnType.QUERY_SET,
537+
),
538+
shell_complete=these_strings(
539+
ModelClass.FIELD_CHOICES,
540+
allow_duplicates=False,
541+
),
542+
help="Fetch objects by their choices for field choice_field.",
543+
),
544+
] = ModelClass.objects.none(),
545+
):
546+
...
512547
513548
Completer Chains
514549
----------------
@@ -539,6 +574,14 @@ be returned, or only the first completer that generates matches.
539574
]
540575
)
541576
577+
Settings
578+
--------
579+
580+
A number of completers are provided that complete values involving settings. These include:
581+
582+
* setting: :func:`~django_typer.completers.settings.setting`
583+
* languages: :func:`~django_typer.completers.settings.languages`
584+
542585

543586
Customizing/Adding Shells
544587
==========================

examples/plugins/my_app/management/plugins/backup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def environment(
3131

3232
typer.echo(f"Capturing python environment to {output_file}")
3333
with output_file.open("w") as f:
34-
subprocess.run(["pip", "freeze"], stdout=f)
34+
subprocess.run(["uv", "pip", "freeze"], stdout=f)
3535

3636

3737
@Backup.command()

examples/plugins/my_app/management/plugins/backup_typer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def environment(
3131

3232
typer.echo(f"Capturing python environment to {output_file}")
3333
with output_file.open("w") as f:
34-
subprocess.run(["pip", "freeze"], stdout=f)
34+
subprocess.run(["uv", "pip", "freeze"], stdout=f)
3535

3636

3737
@backup_typer.app.command()

0 commit comments

Comments
 (0)