-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.qmd
More file actions
80 lines (57 loc) · 1.61 KB
/
example.qmd
File metadata and controls
80 lines (57 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
title: "Ruff-formatter Example"
format:
html:
code-tools: true
jupyter: python3
filters:
- ruff-formatter
embed-resources: true
---
> Note: View the source of this document along with the original unformatted Python code by clicking `</> Code` on top-right corner to compare.
## Example 1
```{python}
#| label: hello_world
print ( 'hello, world' )
```
## Example 2
```{python}
#| label: is_unique
def is_unique(
s
):
s = list(s
)
s.sort()
for i in range(len(s) - 1):
if s[i] == s[i + 1]:
return 0
else:
return 1
```
[Ruff defaults to 88 character per line](https://docs.astral.sh/ruff/settings/#line-length). But you can change this default behavior
by specifying `line-length` in the `pyproject.toml` file.
```{.toml filename='pyproject.toml'}
[tool.ruff]
line-length = 40
```
## Example 3
This extension works on non executable code blocks (e.g. `{.python}`) too.
```{.python}
def example_function(arg_1: str, arg_2: bool, arg_3: int = 0, arg_4: int = 1, arg_5: float = 0.0):
pass
```
## Example 4
```{.python #test_function}
def function(name, default=None, *args, variable="1123", a, b, c, employee, office, d, e, f, **kwargs):
"""This is function is created to demonstrate reformatting with Ruff"""
pass
```
## Example 5: IPython
IPython syntax like a question mark for help or magic functions will break the Ruff parser:
```{python}
print?
```
This emits an error message and causes this code cell not to be formatted but
doesn't otherwise cause a problem for other cells or the whole rendering
process.