-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Cleanup some typing * Add custom CLI commands * Add unit tests * Create v24.12 release * Add release notes
- Loading branch information
Showing
13 changed files
with
321 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Custom CLI Commands | ||
|
||
.. new:: New in v24.12 | ||
|
||
This feature was added in version 24.12 | ||
|
||
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: | ||
|
||
```sh | ||
sanic path.to:app exec <command> [--arg=value] | ||
``` | ||
|
||
.. column:: | ||
|
||
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. | ||
|
||
.. column:: | ||
|
||
```python | ||
@app.command | ||
async def hello(name="world"): | ||
print(f"Hello, {name}.") | ||
``` | ||
|
||
.. column:: | ||
|
||
Now, you can easily invoke this command using the `exec` action. | ||
|
||
.. column:: | ||
|
||
```sh | ||
sanic path.to:app exec hello --name=Adam | ||
``` | ||
|
||
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. | ||
|
||
.. column:: | ||
|
||
By default, the name of the function will be the command name. You can override this by passing the `name` argument to the decorator. | ||
|
||
.. column:: | ||
|
||
```python | ||
@app.command(name="greet") | ||
async def hello(name="world"): | ||
print(f"Hello, {name}.") | ||
``` | ||
|
||
```sh | ||
sanic path.to:app exec greet --name=Adam | ||
``` | ||
|
||
.. warning:: | ||
|
||
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. | ||
|
||
*Added in v24.12* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
title: Version 24.12 | ||
--- | ||
|
||
# Version 24.12 | ||
|
||
.. toc:: | ||
|
||
|
||
## Introduction | ||
|
||
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). | ||
|
||
## What to know | ||
|
||
More details in the [Changelog](../changelog.html). Notable new or breaking features, and what to upgrade: | ||
|
||
### 👶 _BETA_ Custom CLI commands | ||
|
||
The `sanic` CLI utility now allows for custom commands to be invoked. Commands can be added using the decorator syntax below. | ||
|
||
```python | ||
@app.command | ||
async def foo(one, two: str, three: str = "..."): | ||
logger.info(f"FOO {one=} {two=} {three=}") | ||
|
||
|
||
@app.command | ||
def bar(): | ||
logger.info("BAR") | ||
|
||
|
||
@app.command(name="qqq") | ||
async def baz(): | ||
logger.info("BAZ") | ||
``` | ||
|
||
These are invoked using the `exec` command as follows. | ||
|
||
```sh | ||
sanic server:app exec <command> [--arg=value] | ||
``` | ||
|
||
Any arguments in the function's signature will be added as arguments. For example: | ||
|
||
```sh | ||
sanic server:app exec command --one=1 --two=2 --three=3 | ||
``` | ||
|
||
.. warning:: | ||
|
||
This is in **BETA** and the functionality is subject to change in upcoming versions. | ||
|
||
### Add Python 3.13 support | ||
|
||
We have added Python 3.13 to the supported versions. | ||
|
||
### Remove Python 3.8 support | ||
|
||
Python 3.8 reached end-of-life. Sanic is now dropping support for Python 3.8, and requires Python 3.9 or newer. | ||
|
||
### Old response cookie accessors removed | ||
|
||
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. | ||
|
||
## Thank you | ||
|
||
Thank you to everyone that participated in this release: :clap: | ||
|
||
[@ahopkins](https://github.com/ahopkins) | ||
[@C5H12O5](https://github.com/C5H12O5) | ||
[@ChihweiLHBird](https://github.com/ChihweiLHBird) | ||
[@HyperKiko](https://github.com/HyperKiko) | ||
[@imnotjames](https://github.com/imnotjames) | ||
[@pygeek](https://github.com/pygeek) | ||
|
||
--- | ||
|
||
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/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "24.6.0" | ||
__version__ = "24.12.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.