Skip to content
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

- Refactored the runserver_plus out of the runserver command. #154

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ The goal of this library is to provided the simplest possible Tailwind integrati
Enjoy!

Checkout the detailed [installation guide](https://django-tailwind-cli.rtfd.io/latest/installation/)
if you want to activate browser reload or the `runserver_plus` management command known from
`django-extensions`.
if you want to activate browser reload.

## Features

Expand Down
5 changes: 1 addition & 4 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ Usage: manage.py tailwind runserver

Run the development server with Tailwind CSS CLI in watch mode.

If django-extensions is installed along with this library, this command runs
the runserver_plus command from django-extensions. Otherwise it runs the
default runserver command.

Arguments:
[ADDRPORT] Optional port number, or ipaddr:port
Expand Down Expand Up @@ -89,7 +86,7 @@ Options:

### watch

Run `python manage.py tailwind watch` to just start a tailwind watcher process if you prefer to start your debug server in a seperate shell or prefer a different solution than runserver or runserver_plus.
Run `python manage.py tailwind watch` to just start a tailwind watcher process if you prefer to start your debug server in a seperate shell or prefer a different solution than runserver.

## Use with Docker Compose

Expand Down
58 changes: 12 additions & 46 deletions src/django_tailwind_cli/management/commands/tailwind.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from multiprocessing import Process
from pathlib import Path
from typing import Optional, Union
from warnings import warn

import requests
import typer
Expand Down Expand Up @@ -184,37 +185,16 @@ def runserver(
If django-extensions is installed along with this library, this command runs the runserver_plus
command from django-extensions. Otherwise it runs the default runserver command.
"""
if (
importlib.util.find_spec("django_extensions")
and importlib.util.find_spec("werkzeug")
and not force_default_runserver
):
server_command = "runserver_plus"
runserver_options = get_runserver_options(
addrport=addrport,
use_ipv6=use_ipv6,
no_threading=no_threading,
no_static=no_static,
no_reloader=no_reloader,
skip_checks=skip_checks,
pdb=pdb,
ipdb=ipdb,
pm=pm,
print_sql=print_sql,
print_sql_location=print_sql_location,
cert_file=cert_file,
key_file=key_file,
)
else:
server_command = "runserver"
runserver_options = get_runserver_options(
addrport=addrport,
use_ipv6=use_ipv6,
no_threading=no_threading,
no_static=no_static,
no_reloader=no_reloader,
skip_checks=skip_checks,
)


runserver_options = get_runserver_options(
addrport=addrport,
use_ipv6=use_ipv6,
no_threading=no_threading,
no_static=no_static,
no_reloader=no_reloader,
skip_checks=skip_checks,
)

watch_cmd = [sys.executable, "manage.py", "tailwind", "watch"]
watch_process = Process(
Expand All @@ -229,7 +209,7 @@ def runserver(
debug_server_cmd = [
sys.executable,
"manage.py",
server_command,
"runserver",
] + runserver_options

debugserver_process = Process(
Expand Down Expand Up @@ -361,20 +341,6 @@ def get_runserver_options(
options.append("--noreload")
if skip_checks:
options.append("--skip-checks")
if pdb:
options.append("--pdb")
if ipdb:
options.append("--ipdb")
if pm:
options.append("--pm")
if print_sql:
options.append("--print-sql")
if print_sql_location:
options.append("--print-sql-location")
if cert_file:
options.append(f"--cert-file={cert_file}")
if key_file:
options.append(f"--key-file={key_file}")
if addrport:
options.append(addrport)

Expand Down
3 changes: 0 additions & 3 deletions tests/test_management_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,3 @@ def test_runserver():
call_command("tailwind", "runserver")


def test_runserver_plus_without_django_extensions_installed(mocker: MockerFixture):
mocker.patch.dict(sys.modules, {"django_extensions": None, "werkzeug": None})
call_command("tailwind", "runserver")