Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ indent-style = "space"
line-ending = "auto"
persistent-line-breaks = true
exclude = []
default-exclude = true
default-exclude = true
14 changes: 14 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extend-exclude = [
"**/renv",
"**/.venv",
".github",
".vscode",
"**/node_modules",
"**/__pycache__",
"**/build",
# file with cell magic not parsed by ruff
"src/resources/jupyter/lang/python/cleanup.py",
"src/resources/jupyter/lang/python/setup.py",
Comment on lines +9 to +11
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cscheid we already don't process those files as they don't play well with ruff as you guessed. This why they are not formatted in this PR.

]
# don't format .ipynb files as quarto cell comment
include = ["**/*.py"]
4 changes: 3 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"esbenp.prettier-vscode",
"sumneko.lua",
"nvarner.typst-lsp",
"Posit.air-vscode"
"Posit.air-vscode",
"charliermarsh.ruff",
"tamasfe.even-better-toml"
]
}
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
},
"notebook.formatOnSave.enabled": false,
"notebook.codeActionsOnSave": {
"notebook.source.organizeImports": "explicit"
},
"pylint.enabled": false,
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
},
"[r]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "Posit.air-vscode"
Expand All @@ -13,6 +25,10 @@
"[html]": {
"editor.formatOnSave": false
},
"[toml]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "tamasfe.even-better-toml"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.tabSize": 2,
Expand Down
76 changes: 53 additions & 23 deletions dev-docs/feature-format-matrix/create_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import json
import pathlib

class Trie:

class Trie:
def __init__(self):
self.children = {}
self.values = []
Expand Down Expand Up @@ -37,13 +37,12 @@ def tabulator(self):
children = v.tabulator()
feature = k
if v.entry != "":
link = "<a href='%s' target='_blank'><i class='fa-solid fa-link' aria-label='link'></i></a>" % v.entry
link = (
"<a href='%s' target='_blank'><i class='fa-solid fa-link' aria-label='link'></i></a>"
% v.entry
)
feature = "%s %s" % (link, k)
d = {
"sort_key": k,
"feature": feature,
**v.tabulator_leaf()
}
d = {"sort_key": k, "feature": feature, **v.tabulator_leaf()}
if children:
d["_children"] = children
result.append(d)
Expand All @@ -60,13 +59,14 @@ def size(self):
return 1
return sum([v.size() for v in self.children.values()])

def walk(self, visitor, path = None):
def walk(self, visitor, path=None):
if path is None:
path = []
visitor(self, path)
for k, v in self.children.items():
v.walk(visitor, path + [k])


def extract_metadata_from_file(file):
with open(file, "r") as f:
lines = f.readlines()
Expand All @@ -78,10 +78,13 @@ def extract_metadata_from_file(file):
start = i
else:
end = i
metadata = yaml.load("".join(lines[start+1:end]), Loader=yaml.SafeLoader)
metadata = yaml.load(
"".join(lines[start + 1 : end]), Loader=yaml.SafeLoader
)
return metadata
raise ValueError("No metadata found in file %s" % file)


def table_cell(entry, _feature, _format_name, format_config):
if type(format_config) == str:
format_config = {}
Expand All @@ -90,8 +93,22 @@ def table_cell(entry, _feature, _format_name, format_config):
if quality is not None:
if type(quality) == str:
quality = quality.lower()
qualities = {-1: "&#x1F6AB;", 0: "&#x26A0;", 1: "&#x2713;", 2: "&#x2713;&#x2713;", "unknown": "&#x2753;", "na": "NA"}
colors = {-1: "bad", 0: "ok", 1: "good", 2: "good", "unknown": "unknown", "na": "na"}
qualities = {
-1: "&#x1F6AB;",
0: "&#x26A0;",
1: "&#x2713;",
2: "&#x2713;&#x2713;",
"unknown": "&#x2753;",
"na": "NA",
}
colors = {
-1: "bad",
0: "ok",
1: "good",
2: "good",
"unknown": "unknown",
"na": "na",
}
color = colors[quality]
quality_icon = qualities.get(quality, "&#x2753;")
result.append(f"<span class='{color}'>{quality_icon}</span>")
Expand All @@ -101,7 +118,8 @@ def table_cell(entry, _feature, _format_name, format_config):
result.append(f"<span title='{comment}'>&#x1F4AC;</span>")
return "".join(result)

def compute_trie(detailed = False):

def compute_trie(detailed=False):
trie = Trie()
pattern = "qmd-files/**/*.qmd" if detailed else "qmd-files/**/document.qmd"
for entry in pathlib.Path(".").glob(pattern):
Expand All @@ -115,26 +133,37 @@ def compute_trie(detailed = False):
except KeyError:
raise Exception("No format found in %s" % entry)
for format_name, format_config in format.items():
trie.insert(feature, {
"feature": "/".join(feature),
"format": format_name,
"entry": entry,
"format_config": format_config,
"table_cell": table_cell(entry, feature, format_name, format_config)
})
trie.insert(
feature,
{
"feature": "/".join(feature),
"format": format_name,
"entry": entry,
"format_config": format_config,
"table_cell": table_cell(
entry, feature, format_name, format_config
),
},
)
return trie

def render_features_formats_data(trie = None):

def render_features_formats_data(trie=None):
if trie is None:
trie = compute_trie()
entries = trie.tabulator()
return "```{=html}\n<script type='text/javascript'>\nvar tableData = %s;\n</script>\n```\n" % json.dumps(entries, indent=2)
return (
"```{=html}\n<script type='text/javascript'>\nvar tableData = %s;\n</script>\n```\n"
% json.dumps(entries, indent=2)
)


def compute_quality_summary(trie = None):
def compute_quality_summary(trie=None):
if trie is None:
trie = compute_trie()
quality_summary = {"unknown": 0, -1: 0, 0: 0, 1: 0, 2: 0, "na": 0}
n_rows = 0

def visit(node, _path):
nonlocal n_rows
if not node.children or len(node.values):
Expand All @@ -149,5 +178,6 @@ def visit(node, _path):
if quality_summary.get(quality) is None:
raise ValueError("Invalid quality value %s" % quality)
quality_summary[quality] += 1

trie.walk(visit)
return {"n_rows": n_rows, "quality": quality_summary}
return {"n_rows": n_rows, "quality": quality_summary}
3 changes: 2 additions & 1 deletion quarto-cli.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"deno.inlayHints.variableTypes.enabled": false,
"deno.inlayHints.variableTypes.suppressWhenTypeMatchesName": false
},
"typst-lsp.exportPdf": "never"
"typst-lsp.exportPdf": "never",
"notebook.formatOnSave.enabled": false
}
5 changes: 4 additions & 1 deletion quarto_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
import sys


def find_version():
g = str((Path(__file__).parent / "quarto-*").resolve())
g = str((Path(glob.glob(g)[0]) / "bin" / "quarto").resolve())
Expand All @@ -12,8 +13,10 @@ def find_version():
g += ".exe"
return g


def call_quarto(*args, **kwargs):
return subprocess.run([find_version(), *sys.argv[1:], *args], **kwargs)


def run_quarto(*args, **kwargs):
call_quarto(*args, **kwargs)
call_quarto(*args, **kwargs)
49 changes: 38 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
shutil.rmtree("build", ignore_errors=True)
shutil.rmtree("quarto_cli.egg-info", ignore_errors=True)


def get_platform_suffix():
if sys.platform == "darwin":
return "macos.tar.gz"
Expand All @@ -31,6 +32,7 @@ def get_platform_suffix():
else:
raise Exception("Platform not supported")


def download_quarto(vers):
global output_location
global quarto_data
Expand All @@ -43,8 +45,28 @@ def download_quarto(vers):
name, resp = urlretrieve(quarto_url)
except Exception as e:
print("Error downloading Quarto:", e)
commit=subprocess.run(["git","log","-1","--skip=1","--pretty=format:'%h'","--","version.txt"], check=True, text=True, capture_output=True, shell=True).stdout
version = subprocess.run(["git","show", commit.replace("'", "")+":version.txt"], check=True, capture_output=True, text=True, shell=True).stdout.replace("\n", "")
commit = subprocess.run(
[
"git",
"log",
"-1",
"--skip=1",
"--pretty=format:'%h'",
"--",
"version.txt",
],
check=True,
text=True,
capture_output=True,
shell=True,
).stdout
version = subprocess.run(
["git", "show", commit.replace("'", "") + ":version.txt"],
check=True,
capture_output=True,
text=True,
shell=True,
).stdout.replace("\n", "")
quarto_url = f"https://github.com/quarto-dev/quarto-cli/releases/download/v{version}/quarto-{version}-{suffix}"
name, resp = urlretrieve(quarto_url)

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

if suffix.endswith(".zip"):
import zipfile
with zipfile.ZipFile(name, 'r') as zip_ref:

with zipfile.ZipFile(name, "r") as zip_ref:
zip_ref.extractall(output_location)
elif suffix.startswith("linux"):
import tarfile

with tarfile.open(name) as tf:
tf.extractall(Path(output_location).parent.resolve())
else:
import tarfile

with tarfile.open(name) as tf:
tf.extractall(output_location)

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


def cleanup_quarto():
shutil.rmtree(output_location)


global version

version = open("version.txt").read().strip()
download_quarto(version)
setup(
version=version,
name='quarto_cli',
name="quarto_cli",
install_requires=[
'jupyter',
'nbclient',
'wheel',
"jupyter",
"nbclient",
"wheel",
],
packages=find_packages(include=['quarto_cli', 'quarto_cli.*']),
packages=find_packages(include=["quarto_cli", "quarto_cli.*"]),
entry_points={
'console_scripts': [
'quarto = quarto_cli:run_quarto',
"console_scripts": [
"quarto = quarto_cli:run_quarto",
]
},
package_data={
'quarto_cli': quarto_data,
"quarto_cli": quarto_data,
},
include_package_data=True,
)
Expand Down
Loading
Loading