Skip to content

Commit 2beeeee

Browse files
authored
24.12 Release (#3021)
* Cleanup some typing * Add custom CLI commands * Add unit tests * Create v24.12 release * Add release notes
1 parent 60ca033 commit 2beeeee

File tree

13 files changed

+321
-350
lines changed

13 files changed

+321
-350
lines changed

guide/config/en/sidebar.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ root:
4343
path: guide/advanced/versioning.html
4444
- label: Signals
4545
path: guide/advanced/signals.html
46+
- label: Custom CLI Commands
47+
path: guide/advanced/commands.html
4648
- label: Best Practices
4749
items:
4850
- label: Blueprints
@@ -145,6 +147,8 @@ root:
145147
items:
146148
- label: "2024"
147149
items:
150+
- label: Sanic 24.12
151+
path: release-notes/2024/v24.12.html
148152
- label: Sanic 24.6
149153
path: release-notes/2024/v24.6.html
150154
- label: "2023"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Custom CLI Commands
2+
3+
.. new:: New in v24.12
4+
5+
This feature was added in version 24.12
6+
7+
Sanic ships with a [CLI](../running/running.html#running-via-command) for running the Sanic server. Sometimes, you may have the need to enhance that CLI to run your own custom commands. Commands are invoked using the following basic pattern:
8+
9+
```sh
10+
sanic path.to:app exec <command> [--arg=value]
11+
```
12+
13+
.. column::
14+
15+
To enable this, you can use your `Sanic` app instance to wrap functions that can be callable from the CLI using the `@app.command` decorator.
16+
17+
.. column::
18+
19+
```python
20+
@app.command
21+
async def hello(name="world"):
22+
print(f"Hello, {name}.")
23+
```
24+
25+
.. column::
26+
27+
Now, you can easily invoke this command using the `exec` action.
28+
29+
.. column::
30+
31+
```sh
32+
sanic path.to:app exec hello --name=Adam
33+
```
34+
35+
Command handlers can be either synchronous or asynchronous. The handler can accept any number of keyword arguments, which will be passed in from the CLI.
36+
37+
.. column::
38+
39+
By default, the name of the function will be the command name. You can override this by passing the `name` argument to the decorator.
40+
41+
.. column::
42+
43+
```python
44+
@app.command(name="greet")
45+
async def hello(name="world"):
46+
print(f"Hello, {name}.")
47+
```
48+
49+
```sh
50+
sanic path.to:app exec greet --name=Adam
51+
```
52+
53+
.. warning::
54+
55+
This feature is still in **BETA** and may change in future versions. There is no type coercion or validation on the arguments passed in from the CLI, and the CLI will ignore any return values from the command handler. Future enhancements and changes are likely.
56+
57+
*Added in v24.12*

guide/content/en/organization/policies.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ Sanic releases a long term support release (aka "LTS") once a year in December.
3737

3838
| Version | Release | LTS | Supported |
3939
|---------|------------|---------------|-----------------|
40-
| 23.12 | 2023-12-31 | until 2025-12 ||
40+
| 24.12 | 2024-12-31 | until 2026-12 ||
41+
| 24.6 | 2024-06-30 | ||
42+
| 23.12 | 2023-12-31 | until 2025-12 | ☑️ |
4143
| 23.6 | 2023-07-25 | ||
4244
| 23.3 | 2023-03-26 | ||
43-
| 22.12 | 2022-12-27 | until 2024-12 | ☑️ |
45+
| 22.12 | 2022-12-27 | | ☑️ |
4446
| 22.9 | 2022-09-29 | ||
4547
| 22.6 | 2022-06-30 | ||
4648
| 22.3 | 2022-03-31 | ||
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: Version 24.12
3+
---
4+
5+
# Version 24.12
6+
7+
.. toc::
8+
9+
10+
## Introduction
11+
12+
This is the first release of the version 24 [release cycle](../../organization/policies.md#release-schedule). The release cadence for v24 may be slightly altered from years past. Make sure to stay up to date in the Discord server for latest updates. If you run into any issues, please raise a concern on [GitHub](https://github.com/sanic-org/sanic/issues/new/choose).
13+
14+
## What to know
15+
16+
More details in the [Changelog](../changelog.html). Notable new or breaking features, and what to upgrade:
17+
18+
### 👶 _BETA_ Custom CLI commands
19+
20+
The `sanic` CLI utility now allows for custom commands to be invoked. Commands can be added using the decorator syntax below.
21+
22+
```python
23+
@app.command
24+
async def foo(one, two: str, three: str = "..."):
25+
logger.info(f"FOO {one=} {two=} {three=}")
26+
27+
28+
@app.command
29+
def bar():
30+
logger.info("BAR")
31+
32+
33+
@app.command(name="qqq")
34+
async def baz():
35+
logger.info("BAZ")
36+
```
37+
38+
These are invoked using the `exec` command as follows.
39+
40+
```sh
41+
sanic server:app exec <command> [--arg=value]
42+
```
43+
44+
Any arguments in the function's signature will be added as arguments. For example:
45+
46+
```sh
47+
sanic server:app exec command --one=1 --two=2 --three=3
48+
```
49+
50+
.. warning::
51+
52+
This is in **BETA** and the functionality is subject to change in upcoming versions.
53+
54+
### Add Python 3.13 support
55+
56+
We have added Python 3.13 to the supported versions.
57+
58+
### Remove Python 3.8 support
59+
60+
Python 3.8 reached end-of-life. Sanic is now dropping support for Python 3.8, and requires Python 3.9 or newer.
61+
62+
### Old response cookie accessors removed
63+
64+
Prior to v23, cookies on `Response` objects were set and accessed as dictionary objects. That was deprecated in v23.3 when the new [convenience methods](../2023/v23.3.html#more-convenient-methods-for-setting-and-deleting-cookies) were added. The old patterns have been removed.
65+
66+
## Thank you
67+
68+
Thank you to everyone that participated in this release: :clap:
69+
70+
[@ahopkins](https://github.com/ahopkins)
71+
[@C5H12O5](https://github.com/C5H12O5)
72+
[@ChihweiLHBird](https://github.com/ChihweiLHBird)
73+
[@HyperKiko](https://github.com/HyperKiko)
74+
[@imnotjames](https://github.com/imnotjames)
75+
[@pygeek](https://github.com/pygeek)
76+
77+
---
78+
79+
If you enjoy the project, please consider contributing. Of course we love code contributions, but we also love contributions in any form. Consider writing some documentation, showing off use cases, joining conversations and making your voice known, and if you are able: [financial contributions](https://opencollective.com/sanic-org/).

guide/content/en/release-notes/changelog.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,32 @@ content_class: changelog
77
🔶 Current release
88
🔷 In support LTS release
99

10-
11-
## Version 24.6.0 🔶
10+
## Version 24.12.0 🔶🔷
1211

1312
_Current version_
1413

14+
### Features
15+
- [#3019](https://github.com/sanic-org/sanic/pull/3019) Add custom commands to `sanic` CLI
16+
17+
### Bugfixes
18+
- [#2992](https://github.com/sanic-org/sanic/pull/2992) Fix `mixins.startup.serve` UnboundLocalError
19+
- [#3000](https://github.com/sanic-org/sanic/pull/3000) Fix type annocation for `JSONResponse` method for return type `bytes` allowed for `dumps` callable
20+
- [#3009](https://github.com/sanic-org/sanic/pull/3009) Fix `SanicException.quiet` attribute handling when set to `False`
21+
- [#3014](https://github.com/sanic-org/sanic/pull/3014) Cleanup some typing
22+
- [#3015](https://github.com/sanic-org/sanic/pull/3015) Kill the entire process group if applicable
23+
- [#3016](https://github.com/sanic-org/sanic/pull/3016) Fix incompatible type annotation of get method in the HTTPMethodView class
24+
25+
### Deprecations and Removals
26+
- [#3020](https://github.com/sanic-org/sanic/pull/3020) Remove Python 3.8 support
27+
28+
### Developer infrastructure
29+
- [#3017](https://github.com/sanic-org/sanic/pull/3017) Cleanup setup.cfg
30+
31+
### Improved Documentation
32+
- [#3007](https://github.com/sanic-org/sanic/pull/3007) Fix typo in documentation for `sanic-ext`
33+
34+
## Version 24.6.0
35+
1536
### Features
1637
- [#2838](https://github.com/sanic-org/sanic/pull/2838) Simplify request cookies `getlist`
1738
- [#2850](https://github.com/sanic-org/sanic/pull/2850) Unix sockets can now use `pathlib.Path`
@@ -193,7 +214,7 @@ From that list, the items to highlight in the release notes:
193214
- [#2712](https://github.com/sanic-org/sanic/pull/2712) Improved example using ``'https'`` to create the redirect
194215
195216
196-
## Version 22.12.0 🔷
217+
## Version 22.12.0
197218
198219
_Current LTS version_
199220

sanic/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "24.6.0"
1+
__version__ = "24.12.0"

sanic/cookies/request.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import Any, Optional
44

55
from sanic.cookies.response import Cookie
6-
from sanic.log import deprecation
76
from sanic.request.parameters import RequestParameters
87

98

@@ -126,21 +125,11 @@ class CookieRequestParameters(RequestParameters):
126125
""" # noqa: E501
127126

128127
def __getitem__(self, key: str) -> Optional[str]:
129-
deprecation(
130-
f"You are accessing cookie key '{key}', which is currently in "
131-
"compat mode returning a single cookie value. Starting in v24.9 "
132-
"accessing a cookie value like this will return a list of values. "
133-
"To avoid this behavior and continue accessing a single value, "
134-
f"please upgrade from request.cookies['{key}'] to "
135-
f"request.cookies.get('{key}'). See more details: "
136-
"https://sanic.dev/en/guide/release-notes/v23.3.html#request-cookies", # noqa
137-
24.9,
138-
)
139128
try:
140129
value = self._get_prefixed_cookie(key)
141130
except KeyError:
142131
value = super().__getitem__(key)
143-
return value[0]
132+
return value
144133

145134
def __getattr__(self, key: str) -> str:
146135
if key.startswith("_"):

0 commit comments

Comments
 (0)