Skip to content

Commit 7d2b828

Browse files
authored
Merge pull request #12683 from quarto-dev/use-ruff-2
configure ruff for project
2 parents 9b5fc6f + ca8eaf9 commit 7d2b828

File tree

18 files changed

+1271
-1114
lines changed

18 files changed

+1271
-1114
lines changed

.air.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ indent-style = "space"
55
line-ending = "auto"
66
persistent-line-breaks = true
77
exclude = []
8-
default-exclude = true
8+
default-exclude = true

.ruff.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extend-exclude = [
2+
"**/renv",
3+
"**/.venv",
4+
".github",
5+
".vscode",
6+
"**/node_modules",
7+
"**/__pycache__",
8+
"**/build",
9+
# file with cell magic not parsed by ruff
10+
"src/resources/jupyter/lang/python/cleanup.py",
11+
"src/resources/jupyter/lang/python/setup.py",
12+
]
13+
# don't format .ipynb files as quarto cell comment
14+
include = ["**/*.py"]

.vscode/extensions.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"esbenp.prettier-vscode",
55
"sumneko.lua",
66
"nvarner.typst-lsp",
7-
"Posit.air-vscode"
7+
"Posit.air-vscode",
8+
"charliermarsh.ruff",
9+
"tamasfe.even-better-toml"
810
]
911
}

.vscode/settings.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
"[typescript]": {
33
"editor.defaultFormatter": "denoland.vscode-deno"
44
},
5+
"notebook.formatOnSave.enabled": false,
6+
"notebook.codeActionsOnSave": {
7+
"notebook.source.organizeImports": "explicit"
8+
},
9+
"pylint.enabled": false,
10+
"[python]": {
11+
"editor.formatOnSave": true,
12+
"editor.defaultFormatter": "charliermarsh.ruff",
13+
"editor.codeActionsOnSave": {
14+
"source.organizeImports": "explicit"
15+
}
16+
},
517
"[r]": {
618
"editor.formatOnSave": true,
719
"editor.defaultFormatter": "Posit.air-vscode"
@@ -13,6 +25,10 @@
1325
"[html]": {
1426
"editor.formatOnSave": false
1527
},
28+
"[toml]": {
29+
"editor.formatOnSave": true,
30+
"editor.defaultFormatter": "tamasfe.even-better-toml"
31+
},
1632
"editor.defaultFormatter": "esbenp.prettier-vscode",
1733
"editor.formatOnSave": true,
1834
"editor.tabSize": 2,

dev-docs/feature-format-matrix/create_table.py

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import json
33
import pathlib
44

5-
class Trie:
65

6+
class Trie:
77
def __init__(self):
88
self.children = {}
99
self.values = []
@@ -37,13 +37,12 @@ def tabulator(self):
3737
children = v.tabulator()
3838
feature = k
3939
if v.entry != "":
40-
link = "<a href='%s' target='_blank'><i class='fa-solid fa-link' aria-label='link'></i></a>" % v.entry
40+
link = (
41+
"<a href='%s' target='_blank'><i class='fa-solid fa-link' aria-label='link'></i></a>"
42+
% v.entry
43+
)
4144
feature = "%s %s" % (link, k)
42-
d = {
43-
"sort_key": k,
44-
"feature": feature,
45-
**v.tabulator_leaf()
46-
}
45+
d = {"sort_key": k, "feature": feature, **v.tabulator_leaf()}
4746
if children:
4847
d["_children"] = children
4948
result.append(d)
@@ -60,13 +59,14 @@ def size(self):
6059
return 1
6160
return sum([v.size() for v in self.children.values()])
6261

63-
def walk(self, visitor, path = None):
62+
def walk(self, visitor, path=None):
6463
if path is None:
6564
path = []
6665
visitor(self, path)
6766
for k, v in self.children.items():
6867
v.walk(visitor, path + [k])
6968

69+
7070
def extract_metadata_from_file(file):
7171
with open(file, "r") as f:
7272
lines = f.readlines()
@@ -78,10 +78,13 @@ def extract_metadata_from_file(file):
7878
start = i
7979
else:
8080
end = i
81-
metadata = yaml.load("".join(lines[start+1:end]), Loader=yaml.SafeLoader)
81+
metadata = yaml.load(
82+
"".join(lines[start + 1 : end]), Loader=yaml.SafeLoader
83+
)
8284
return metadata
8385
raise ValueError("No metadata found in file %s" % file)
8486

87+
8588
def table_cell(entry, _feature, _format_name, format_config):
8689
if type(format_config) == str:
8790
format_config = {}
@@ -90,8 +93,22 @@ def table_cell(entry, _feature, _format_name, format_config):
9093
if quality is not None:
9194
if type(quality) == str:
9295
quality = quality.lower()
93-
qualities = {-1: "&#x1F6AB;", 0: "&#x26A0;", 1: "&#x2713;", 2: "&#x2713;&#x2713;", "unknown": "&#x2753;", "na": "NA"}
94-
colors = {-1: "bad", 0: "ok", 1: "good", 2: "good", "unknown": "unknown", "na": "na"}
96+
qualities = {
97+
-1: "&#x1F6AB;",
98+
0: "&#x26A0;",
99+
1: "&#x2713;",
100+
2: "&#x2713;&#x2713;",
101+
"unknown": "&#x2753;",
102+
"na": "NA",
103+
}
104+
colors = {
105+
-1: "bad",
106+
0: "ok",
107+
1: "good",
108+
2: "good",
109+
"unknown": "unknown",
110+
"na": "na",
111+
}
95112
color = colors[quality]
96113
quality_icon = qualities.get(quality, "&#x2753;")
97114
result.append(f"<span class='{color}'>{quality_icon}</span>")
@@ -101,7 +118,8 @@ def table_cell(entry, _feature, _format_name, format_config):
101118
result.append(f"<span title='{comment}'>&#x1F4AC;</span>")
102119
return "".join(result)
103120

104-
def compute_trie(detailed = False):
121+
122+
def compute_trie(detailed=False):
105123
trie = Trie()
106124
pattern = "qmd-files/**/*.qmd" if detailed else "qmd-files/**/document.qmd"
107125
for entry in pathlib.Path(".").glob(pattern):
@@ -115,26 +133,37 @@ def compute_trie(detailed = False):
115133
except KeyError:
116134
raise Exception("No format found in %s" % entry)
117135
for format_name, format_config in format.items():
118-
trie.insert(feature, {
119-
"feature": "/".join(feature),
120-
"format": format_name,
121-
"entry": entry,
122-
"format_config": format_config,
123-
"table_cell": table_cell(entry, feature, format_name, format_config)
124-
})
136+
trie.insert(
137+
feature,
138+
{
139+
"feature": "/".join(feature),
140+
"format": format_name,
141+
"entry": entry,
142+
"format_config": format_config,
143+
"table_cell": table_cell(
144+
entry, feature, format_name, format_config
145+
),
146+
},
147+
)
125148
return trie
126149

127-
def render_features_formats_data(trie = None):
150+
151+
def render_features_formats_data(trie=None):
128152
if trie is None:
129153
trie = compute_trie()
130154
entries = trie.tabulator()
131-
return "```{=html}\n<script type='text/javascript'>\nvar tableData = %s;\n</script>\n```\n" % json.dumps(entries, indent=2)
155+
return (
156+
"```{=html}\n<script type='text/javascript'>\nvar tableData = %s;\n</script>\n```\n"
157+
% json.dumps(entries, indent=2)
158+
)
159+
132160

133-
def compute_quality_summary(trie = None):
161+
def compute_quality_summary(trie=None):
134162
if trie is None:
135163
trie = compute_trie()
136164
quality_summary = {"unknown": 0, -1: 0, 0: 0, 1: 0, 2: 0, "na": 0}
137165
n_rows = 0
166+
138167
def visit(node, _path):
139168
nonlocal n_rows
140169
if not node.children or len(node.values):
@@ -149,5 +178,6 @@ def visit(node, _path):
149178
if quality_summary.get(quality) is None:
150179
raise ValueError("Invalid quality value %s" % quality)
151180
quality_summary[quality] += 1
181+
152182
trie.walk(visit)
153-
return {"n_rows": n_rows, "quality": quality_summary}
183+
return {"n_rows": n_rows, "quality": quality_summary}

quarto-cli.code-workspace

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@
3737
"deno.inlayHints.variableTypes.enabled": false,
3838
"deno.inlayHints.variableTypes.suppressWhenTypeMatchesName": false
3939
},
40-
"typst-lsp.exportPdf": "never"
40+
"typst-lsp.exportPdf": "never",
41+
"notebook.formatOnSave.enabled": false
4142
}

quarto_cli/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55
import sys
66

7+
78
def find_version():
89
g = str((Path(__file__).parent / "quarto-*").resolve())
910
g = str((Path(glob.glob(g)[0]) / "bin" / "quarto").resolve())
@@ -12,8 +13,10 @@ def find_version():
1213
g += ".exe"
1314
return g
1415

16+
1517
def call_quarto(*args, **kwargs):
1618
return subprocess.run([find_version(), *sys.argv[1:], *args], **kwargs)
1719

20+
1821
def run_quarto(*args, **kwargs):
19-
call_quarto(*args, **kwargs)
22+
call_quarto(*args, **kwargs)

setup.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
shutil.rmtree("build", ignore_errors=True)
1717
shutil.rmtree("quarto_cli.egg-info", ignore_errors=True)
1818

19+
1920
def get_platform_suffix():
2021
if sys.platform == "darwin":
2122
return "macos.tar.gz"
@@ -31,6 +32,7 @@ def get_platform_suffix():
3132
else:
3233
raise Exception("Platform not supported")
3334

35+
3436
def download_quarto(vers):
3537
global output_location
3638
global quarto_data
@@ -43,8 +45,28 @@ def download_quarto(vers):
4345
name, resp = urlretrieve(quarto_url)
4446
except Exception as e:
4547
print("Error downloading Quarto:", e)
46-
commit=subprocess.run(["git","log","-1","--skip=1","--pretty=format:'%h'","--","version.txt"], check=True, text=True, capture_output=True, shell=True).stdout
47-
version = subprocess.run(["git","show", commit.replace("'", "")+":version.txt"], check=True, capture_output=True, text=True, shell=True).stdout.replace("\n", "")
48+
commit = subprocess.run(
49+
[
50+
"git",
51+
"log",
52+
"-1",
53+
"--skip=1",
54+
"--pretty=format:'%h'",
55+
"--",
56+
"version.txt",
57+
],
58+
check=True,
59+
text=True,
60+
capture_output=True,
61+
shell=True,
62+
).stdout
63+
version = subprocess.run(
64+
["git", "show", commit.replace("'", "") + ":version.txt"],
65+
check=True,
66+
capture_output=True,
67+
text=True,
68+
shell=True,
69+
).stdout.replace("\n", "")
4870
quarto_url = f"https://github.com/quarto-dev/quarto-cli/releases/download/v{version}/quarto-{version}-{suffix}"
4971
name, resp = urlretrieve(quarto_url)
5072

@@ -53,43 +75,48 @@ def download_quarto(vers):
5375

5476
if suffix.endswith(".zip"):
5577
import zipfile
56-
with zipfile.ZipFile(name, 'r') as zip_ref:
78+
79+
with zipfile.ZipFile(name, "r") as zip_ref:
5780
zip_ref.extractall(output_location)
5881
elif suffix.startswith("linux"):
5982
import tarfile
83+
6084
with tarfile.open(name) as tf:
6185
tf.extractall(Path(output_location).parent.resolve())
6286
else:
6387
import tarfile
88+
6489
with tarfile.open(name) as tf:
6590
tf.extractall(output_location)
6691

6792
for path in glob.glob(str(Path(output_location, "**")), recursive=True):
6893
quarto_data.append(path.replace("quarto_cli" + os.path.sep, ""))
6994

95+
7096
def cleanup_quarto():
7197
shutil.rmtree(output_location)
7298

99+
73100
global version
74101

75102
version = open("version.txt").read().strip()
76103
download_quarto(version)
77104
setup(
78105
version=version,
79-
name='quarto_cli',
106+
name="quarto_cli",
80107
install_requires=[
81-
'jupyter',
82-
'nbclient',
83-
'wheel',
108+
"jupyter",
109+
"nbclient",
110+
"wheel",
84111
],
85-
packages=find_packages(include=['quarto_cli', 'quarto_cli.*']),
112+
packages=find_packages(include=["quarto_cli", "quarto_cli.*"]),
86113
entry_points={
87-
'console_scripts': [
88-
'quarto = quarto_cli:run_quarto',
114+
"console_scripts": [
115+
"quarto = quarto_cli:run_quarto",
89116
]
90117
},
91118
package_data={
92-
'quarto_cli': quarto_data,
119+
"quarto_cli": quarto_data,
93120
},
94121
include_package_data=True,
95122
)

0 commit comments

Comments
 (0)