From f0a3ec60e949ee181e09aa11965ed0e25403d4c2 Mon Sep 17 00:00:00 2001 From: David Fuentes Baldomir Date: Sat, 4 Jan 2025 09:37:17 +0100 Subject: [PATCH 1/5] Add --nostatic and --insecure args to runserver command. (#450) Fixes #449 --- daphne/management/commands/runserver.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/daphne/management/commands/runserver.py b/daphne/management/commands/runserver.py index b2fd2ee..7e67e07 100644 --- a/daphne/management/commands/runserver.py +++ b/daphne/management/commands/runserver.py @@ -73,6 +73,18 @@ class Command(RunserverCommand): "seconds (default: 5)" ), ) + parser.add_argument( + "--nostatic", + action="store_false", + dest="use_static_handler", + help="Tells Django to NOT automatically serve static files at STATIC_URL.", + ) + parser.add_argument( + "--insecure", + action="store_true", + dest="insecure_serving", + help="Allows serving static files even if DEBUG is False.", + ) def handle(self, *args, **options): self.http_timeout = options.get("http_timeout", None) From 786e4c120a6e0f4819570901ab848fb08522ea8b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 07:33:08 +0100 Subject: [PATCH 2/5] [pre-commit.ci] pre-commit autoupdate (#546) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4397d89..bdb453c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.19.0 + rev: v3.19.1 hooks: - id: pyupgrade args: [--py39-plus] From 630caed9153f8eb62aecfade3e349d3cc6ee1bb0 Mon Sep 17 00:00:00 2001 From: Andrew Sears Date: Wed, 22 Jan 2025 11:34:39 -0500 Subject: [PATCH 3/5] Upgrade project metadata (#542) --- .flake8 | 11 ++++++ .github/workflows/tests.yml | 4 ++ .gitignore | 1 + daphne/testing.py | 2 +- pyproject.toml | 78 +++++++++++++++++++++++++++++++++++++ setup.cfg | 59 ---------------------------- 6 files changed, 95 insertions(+), 60 deletions(-) create mode 100644 .flake8 delete mode 100644 setup.cfg diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..d60ef28 --- /dev/null +++ b/.flake8 @@ -0,0 +1,11 @@ +[flake8] +exclude = + .venv, + .tox, + docs, + testproject, + js_client, + .eggs + +extend-ignore = E123, E128, E266, E402, W503, E731, W601, B036 +max-line-length = 120 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c68ac58..68b91f7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,6 +5,10 @@ on: branches: - main pull_request: + workflow_dispatch: + +permissions: + contents: read jobs: tests: diff --git a/.gitignore b/.gitignore index 20cb4bd..0616f8a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ test_consumer* .python-version .pytest_cache/ .vscode +.coverage diff --git a/daphne/testing.py b/daphne/testing.py index 785edf9..46787bb 100644 --- a/daphne/testing.py +++ b/daphne/testing.py @@ -158,7 +158,7 @@ class DaphneProcess(multiprocessing.Process): application=application, endpoints=endpoints, signal_handlers=False, - **self.kwargs + **self.kwargs, ) # Set up a poller to look for the port reactor.callLater(0.1, self.resolve_port) diff --git a/pyproject.toml b/pyproject.toml index fed528d..7a2e796 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,81 @@ +[project] +name = "daphne" +dynamic = ["version"] +description = "Django ASGI (HTTP/WebSocket) server" +requires-python = ">=3.9" +authors = [ + { name = "Django Software Foundation", email = "foundation@djangoproject.com" }, +] + +license = { text = "BSD" } +classifiers = [ + "Development Status :: 4 - Beta", + "Environment :: Web Environment", + "Intended Audience :: Developers", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Topic :: Internet :: WWW/HTTP", +] + +dependencies = ["asgiref>=3.5.2,<4", "autobahn>=22.4.2", "twisted[tls]>=22.4"] + +[project.optional-dependencies] +tests = [ + "django", + "hypothesis", + "pytest", + "pytest-asyncio", + "pytest-cov", + "black", + "tox", + "flake8", + "flake8-bugbear", + "mypy", +] + +[project.urls] +homepage = "https://github.com/django/daphne" +documentation = "https://channels.readthedocs.io" +repository = "https://github.com/django/daphne.git" +changelog = "https://github.com/django/daphne/blob/main/CHANGELOG.txt" +issues = "https://github.com/django/daphne/issues" + +[project.scripts] +daphne = "daphne.cli:CommandLineInterface.entrypoint" + [build-system] requires = ["setuptools"] build-backend = "setuptools.build_meta" + +[tool.setuptools] +packages = ["daphne"] + +[tool.setuptools.dynamic] +version = { attr = "daphne.__version__" } +readme = { file = "README.rst", content-type = "text/x-rst" } + +[tool.isort] +profile = "black" + +[tool.pytest] +testpaths = ["tests"] +asyncio_mode = "strict" +filterwarnings = ["ignore::pytest.PytestDeprecationWarning"] + +[tool.coverage.run] +omit = ["tests/*"] +concurrency = ["multiprocessing"] + +[tool.coverage.report] +show_missing = "true" +skip_covered = "true" + +[tool.coverage.html] +directory = "reports/coverage_html_report" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 8d2b2e7..0000000 --- a/setup.cfg +++ /dev/null @@ -1,59 +0,0 @@ -[metadata] -name = daphne -version = attr: daphne.__version__ -url = https://github.com/django/daphne -author = Django Software Foundation -author_email = foundation@djangoproject.com -description = Django ASGI (HTTP/WebSocket) server -long_description = file: README.rst -long_description_content_type = text/x-rst -license = BSD -classifiers = - Development Status :: 4 - Beta - Environment :: Web Environment - Intended Audience :: Developers - License :: OSI Approved :: BSD License - Operating System :: OS Independent - Programming Language :: Python - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.11 - Programming Language :: Python :: 3.12 - Programming Language :: Python :: 3.13 - Topic :: Internet :: WWW/HTTP - -[options] -package_dir = - daphne=daphne - twisted=daphne/twisted -include_package_data = True -install_requires = - asgiref>=3.5.2,<4 - autobahn>=22.4.2 - twisted[tls]>=22.4 -python_requires = >=3.9 -zip_safe = False - -[options.entry_points] -console_scripts = - daphne = daphne.cli:CommandLineInterface.entrypoint - -[options.extras_require] -tests = - django - hypothesis - pytest - pytest-asyncio - -[flake8] -exclude = venv/*,tox/*,docs/*,testproject/*,js_client/*,.eggs/* -extend-ignore = E123, E128, E266, E402, W503, E731, W601, B036 -max-line-length = 120 - -[isort] -profile = black - -[tool:pytest] -testpaths = tests -asyncio_mode = strict From 7c9334952d2b0282543f04bc63b77d77616a92df Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 18 Apr 2025 06:58:38 -0700 Subject: [PATCH 4/5] [pre-commit.ci] pre-commit autoupdate (#551) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 24.10.0 → 25.1.0](https://github.com/psf/black/compare/24.10.0...25.1.0) - [github.com/pycqa/isort: 5.13.2 → 6.0.1](https://github.com/pycqa/isort/compare/5.13.2...6.0.1) - [github.com/PyCQA/flake8: 7.1.1 → 7.2.0](https://github.com/PyCQA/flake8/compare/7.1.1...7.2.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bdb453c..c315a04 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,16 +5,16 @@ repos: - id: pyupgrade args: [--py39-plus] - repo: https://github.com/psf/black - rev: 24.10.0 + rev: 25.1.0 hooks: - id: black language_version: python3 - repo: https://github.com/pycqa/isort - rev: 5.13.2 + rev: 6.0.1 hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 + rev: 7.2.0 hooks: - id: flake8 additional_dependencies: From beef1c15142250ed145bea1d968d0276f7892f63 Mon Sep 17 00:00:00 2001 From: Mohammed <74480856+MohammedSaleh2001@users.noreply.github.com> Date: Wed, 7 May 2025 08:33:22 -0600 Subject: [PATCH 5/5] Allowed assigning a port in DaphneProcess test helper. (#550) --- daphne/testing.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/daphne/testing.py b/daphne/testing.py index 46787bb..9120327 100644 --- a/daphne/testing.py +++ b/daphne/testing.py @@ -126,14 +126,16 @@ class DaphneProcess(multiprocessing.Process): port it ends up listening on back to the parent process. """ - def __init__(self, host, get_application, kwargs=None, setup=None, teardown=None): + def __init__( + self, host, get_application, kwargs=None, setup=None, teardown=None, port=None + ): super().__init__() self.host = host self.get_application = get_application self.kwargs = kwargs or {} self.setup = setup self.teardown = teardown - self.port = multiprocessing.Value("i") + self.port = multiprocessing.Value("i", port if port is not None else 0) self.ready = multiprocessing.Event() self.errors = multiprocessing.Queue() @@ -153,7 +155,9 @@ class DaphneProcess(multiprocessing.Process): try: # Create the server class - endpoints = build_endpoint_description_strings(host=self.host, port=0) + endpoints = build_endpoint_description_strings( + host=self.host, port=self.port.value + ) self.server = Server( application=application, endpoints=endpoints,