Skip to content

Commit

Permalink
Update the migration guide for 0.8.0 and 0.10.0 (#397)
Browse files Browse the repository at this point in the history
Closes: #368
  • Loading branch information
fohrloop authored Sep 20, 2024
1 parent 55cce46 commit 51d5722
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions docs/source/migration.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
# Migration Guide
## Migration Guide: 0.10.0

### on_fail action

As the previous default `on_fail` value of {func}`keep.running <wakepy.keep.running>` and {func}`keep.presenting <wakepy.keep.presenting>` was "error" (=raise Exception if activation fails) and the new default is "warn", *if you still wish to raise Exceptions*, use the following:


```{code-block} python
from wakepy import keep
with keep.running(on_fail="error"):
do_something()
```


## Migration Guide: 0.8.0

### Decision when keepawake fails

The old way (wakepy <= 0.8.0) was:

```{code-block} python
from wakepy import keep
with keep.running() as m:
if not m.success:
# optional: signal to user?
do_something()
```

On wakepy 0.8.0 one should use the `on_fail` parameter for controlling what to do if activation fails. See the [Controlling the on_fail action](#on-fail-action) in the [User Guide](#user-guide). A minimum example would be:


```{code-block} python
from wakepy import keep
with keep.running(on_fail=react_on_failure) as m:
do_something()
def react_on_failure(result: ActivationResult):
print(f'Failed to keep system awake using {result.mode_name} mode')
```

See the {class}`ActivationResult <wakepy.ActivationResult>` docs for more details on what's available on the `result` object. The `m.success` does not exist anymore, as the type of `m` is now an instance of {class}`Mode <wakepy.Mode>`. It has {attr}`Mode.active <wakepy.Mode.active>`. and {attr}`Mode.activation_result <wakepy.Mode.activation_result>`. as well as {attr}`Mode.active_method <wakepy.Mode.active_method>` and {attr}`Mode.used_method <wakepy.Mode.used_method>`.

## Migration Guide: 0.7.0

- When migrating from wakepy <=0.6.0 to >=0.7.0
- When migrating from wakepy <=0.6.0 to 0.7.0
- `set_keepawake` and `unset_keepawake` and `keepawake`: Replace with `keep.running` or `keep.presenting`, whichever makes sense in the application.

### Python API
Expand All @@ -23,7 +68,7 @@ do_something()
unset_keepawake()
```

#### wakepy >=0.7.0
#### wakepy 0.7.0
```{code-block} python
from wakepy import keep
Expand Down Expand Up @@ -52,7 +97,7 @@ with keep.presenting() as m:
```
wakepy -s
```
### wakepy >= 0.7.0
### wakepy 0.7.0
```
wakepy -p
```

0 comments on commit 51d5722

Please sign in to comment.