Skip to content

Commit ca8eaf9

Browse files
committed
Run ruff format
1 parent 4517713 commit ca8eaf9

File tree

13 files changed

+1235
-1111
lines changed

13 files changed

+1235
-1111
lines changed

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/__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
)

src/resources/capabilities/jupyter.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,36 @@
22
import os
33
import importlib
44

5-
sys.stdout.write('versionMajor: ' + str(sys.version_info.major))
6-
sys.stdout.write('\nversionMinor: ' + str(sys.version_info.minor))
7-
sys.stdout.write('\nversionPatch: ' + str(sys.version_info.micro))
8-
sys.stdout.write('\nversionStr: "' + str(sys.version).replace('\n', ' ') + '"')
9-
if os.path.exists(os.path.join(sys.prefix, 'conda-meta', 'history')):
10-
sys.stdout.write('\nconda: true')
5+
sys.stdout.write("versionMajor: " + str(sys.version_info.major))
6+
sys.stdout.write("\nversionMinor: " + str(sys.version_info.minor))
7+
sys.stdout.write("\nversionPatch: " + str(sys.version_info.micro))
8+
sys.stdout.write('\nversionStr: "' + str(sys.version).replace("\n", " ") + '"')
9+
if os.path.exists(os.path.join(sys.prefix, "conda-meta", "history")):
10+
sys.stdout.write("\nconda: true")
1111
else:
12-
sys.stdout.write('\nconda: false')
12+
sys.stdout.write("\nconda: false")
1313
sys.stdout.write('\nexecPrefix: "' + sys.exec_prefix.replace("\\", "/") + '"')
1414
sys.stdout.write('\nexecutable: "' + sys.executable.replace("\\", "/") + '"')
1515

16+
1617
def discover_package(pkg):
17-
sys.stdout.write('\n' + pkg + ': ')
18-
v = 'null'
19-
try:
18+
sys.stdout.write("\n" + pkg + ": ")
19+
v = "null"
2020
try:
21-
from importlib.metadata import version
22-
v = version(pkg)
23-
except ImportError:
24-
imp = importlib.import_module(pkg)
25-
v = str(imp.__version__)
26-
except Exception:
27-
pass
28-
sys.stdout.write(v)
29-
30-
discover_package('jupyter_core')
31-
discover_package('nbformat')
32-
discover_package('nbclient')
33-
discover_package('ipykernel')
34-
discover_package('shiny')
21+
try:
22+
from importlib.metadata import version
23+
24+
v = version(pkg)
25+
except ImportError:
26+
imp = importlib.import_module(pkg)
27+
v = str(imp.__version__)
28+
except Exception:
29+
pass
30+
sys.stdout.write(v)
3531

3632

33+
discover_package("jupyter_core")
34+
discover_package("nbformat")
35+
discover_package("nbclient")
36+
discover_package("ipykernel")
37+
discover_package("shiny")

0 commit comments

Comments
 (0)