9
9
import urllib .request
10
10
from multiprocessing import Process
11
11
from pathlib import Path
12
- from typing import Annotated , List , Optional , Union
12
+ from typing import List , Optional , Union
13
13
14
14
import certifi
15
+ import typer
15
16
from django .conf import settings
16
17
from django .core .management .base import CommandError
17
18
from django .template .utils import get_app_template_dirs
18
19
from django_typer import TyperCommand , command , initialize
19
- from typer import Argument , Option
20
20
21
21
from django_tailwind_cli .utils import Config
22
22
@@ -104,15 +104,15 @@ def list_templates(self):
104
104
@command (help = "Start the Django development server and the Tailwind CLI in watch mode." )
105
105
def runserver (
106
106
self ,
107
- addrport : Annotated [ Optional [str ], Argument (help = "Optional port number, or ipaddr:port" )] = None ,
107
+ addrport : Optional [str ] = typer . Argument (None , help = "Optional port number, or ipaddr:port" ),
108
108
* ,
109
- use_ipv6 : Annotated [ bool , Option ("--ipv6" , "-6" , help = "Tells Django to use an IPv6 address." )] = False ,
110
- no_threading : Annotated [ bool , Option ("--nothreading" , help = "Tells Django to NOT use threading." )] = False ,
111
- no_static : Annotated [
112
- bool , Option ( "--nostatic" , help = "Tells Django to NOT automatically serve static files at STATIC_URL." )
113
- ] = False ,
114
- no_reloader : Annotated [ bool , Option ("--noreload" , help = "Tells Django to NOT use the auto-reloader." )] = False ,
115
- skip_checks : Annotated [ bool , Option ("--skip-checks" , help = "Skip system checks." )] = False ,
109
+ use_ipv6 : bool = typer . Option (False , "--ipv6" , "-6" , help = "Tells Django to use an IPv6 address." ),
110
+ no_threading : bool = typer . Option (False , "--nothreading" , help = "Tells Django to NOT use threading." ),
111
+ no_static : bool = typer . Option (
112
+ False , "--nostatic" , help = "Tells Django to NOT automatically serve static files at STATIC_URL."
113
+ ) ,
114
+ no_reloader : bool = typer . Option (False , "--noreload" , help = "Tells Django to NOT use the auto-reloader." ),
115
+ skip_checks : bool = typer . Option (False , "--skip-checks" , help = "Skip system checks." ),
116
116
):
117
117
debug_server_cmd = [sys .executable , "manage.py" , "runserver" ]
118
118
@@ -137,40 +137,36 @@ def runserver(
137
137
)
138
138
def runserver_plus (
139
139
self ,
140
- addrport : Annotated [ Optional [str ], Argument (help = "Optional port number, or ipaddr:port" )] = None ,
140
+ addrport : Optional [str ] = typer . Argument (None , help = "Optional port number, or ipaddr:port" ),
141
141
* ,
142
- use_ipv6 : Annotated [bool , Option ("--ipv6" , "-6" , help = "Tells Django to use an IPv6 address." )] = False ,
143
- no_threading : Annotated [bool , Option ("--nothreading" , help = "Tells Django to NOT use threading." )] = False ,
144
- no_static : Annotated [
145
- bool , Option ("--nostatic" , help = "Tells Django to NOT automatically serve static files at STATIC_URL." )
146
- ] = False ,
147
- no_reloader : Annotated [bool , Option ("--noreload" , help = "Tells Django to NOT use the auto-reloader." )] = False ,
148
- skip_checks : Annotated [bool , Option ("--skip-checks" , help = "Skip system checks." )] = False ,
149
- pdb : Annotated [bool , Option ("--pdb" , help = "Drop into pdb shell at the start of any view." )] = False ,
150
- ipdb : Annotated [bool , Option ("--ipdb" , help = "Drop into ipdb shell at the start of any view." )] = False ,
151
- pm : Annotated [bool , Option ("--pm" , help = "Drop into (i)pdb shell if an exception is raised in a view." )] = False ,
152
- print_sql : Annotated [bool , Option ("--print-sql" , help = "Print SQL queries as they're executed." )] = False ,
153
- print_sql_location : Annotated [
154
- bool , Option ("--print-sql-location" , help = "Show location in code where SQL query generated from." )
155
- ] = False ,
156
- cert_file : Annotated [
157
- Optional [str ],
158
- Option (
159
- help = (
160
- "SSL .crt file path. If not provided path from --key-file will be selected. Either --cert-file or "
161
- "--key-file must be provided to use SSL."
162
- )
142
+ use_ipv6 : bool = typer .Option (False , "--ipv6" , "-6" , help = "Tells Django to use an IPv6 address." ),
143
+ no_threading : bool = typer .Option (False , "--nothreading" , help = "Tells Django to NOT use threading." ),
144
+ no_static : bool = typer .Option (
145
+ False , "--nostatic" , help = "Tells Django to NOT automatically serve static files at STATIC_URL."
146
+ ),
147
+ no_reloader : bool = typer .Option (False , "--noreload" , help = "Tells Django to NOT use the auto-reloader." ),
148
+ skip_checks : bool = typer .Option (False , "--skip-checks" , help = "Skip system checks." ),
149
+ pdb : bool = typer .Option (False , "--pdb" , help = "Drop into pdb shell at the start of any view." ),
150
+ ipdb : bool = typer .Option (False , "--ipdb" , help = "Drop into ipdb shell at the start of any view." ),
151
+ pm : bool = typer .Option (False , "--pm" , help = "Drop into (i)pdb shell if an exception is raised in a view." ),
152
+ print_sql : bool = typer .Option (False , "--print-sql" , help = "Print SQL queries as they're executed." ),
153
+ print_sql_location : bool = typer .Option (
154
+ False , "--print-sql-location" , help = "Show location in code where SQL query generated from."
155
+ ),
156
+ cert_file : Optional [str ] = typer .Option (
157
+ None ,
158
+ help = (
159
+ "SSL .crt file path. If not provided path from --key-file will be selected. Either --cert-file or "
160
+ "--key-file must be provided to use SSL."
163
161
),
164
- ] = None ,
165
- key_file : Annotated [
166
- Optional [str ],
167
- Option (
168
- help = (
169
- "SSL .key file path. If not provided path from --cert-file will be "
170
- "selected. Either --cert-file or --key-file must be provided to use SSL."
171
- )
162
+ ),
163
+ key_file : Optional [str ] = typer .Option (
164
+ None ,
165
+ help = (
166
+ "SSL .key file path. If not provided path from --cert-file will be "
167
+ "selected. Either --cert-file or --key-file must be provided to use SSL."
172
168
),
173
- ] = None ,
169
+ ) ,
174
170
):
175
171
if not importlib .util .find_spec ("django_extensions" ) and not importlib .util .find_spec ("werkzeug" ):
176
172
msg = (
@@ -254,11 +250,9 @@ def download_cli(self) -> None:
254
250
self ._write_success (f"Downloading Tailwind CSS CLI from '{ download_url } '" )
255
251
dest_file .parent .mkdir (parents = True , exist_ok = True )
256
252
certifi_context = ssl .create_default_context (cafile = certifi .where ())
257
- with (
258
- urllib .request .urlopen (download_url , context = certifi_context ) as source ,
259
- dest_file .open (mode = "wb" ) as dest , # noqa: S310
260
- ):
261
- shutil .copyfileobj (source , dest )
253
+ with urllib .request .urlopen (download_url , context = certifi_context ) as source :
254
+ with dest_file .open (mode = "wb" ) as dest :
255
+ shutil .copyfileobj (source , dest )
262
256
# make cli executable
263
257
dest_file .chmod (0o755 )
264
258
self ._write_success (f"Downloaded Tailwind CSS CLI to '{ dest_file } '" )
0 commit comments