Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/setup.py
3500 views
1
from setuptools import setup, find_packages
2
import glob
3
import sys
4
import platform
5
from urllib.request import urlretrieve
6
from pathlib import Path
7
import os
8
import shutil
9
import subprocess
10
11
output_location = ""
12
quarto_data = []
13
14
# Clean up the build because caching appears to
15
# completely not work with dynamic package_data and version
16
shutil.rmtree("build", ignore_errors=True)
17
shutil.rmtree("quarto_cli.egg-info", ignore_errors=True)
18
19
20
def get_platform_suffix():
21
if sys.platform == "darwin":
22
return "macos.tar.gz"
23
elif sys.platform == "win32":
24
return "win.zip"
25
elif sys.platform == "linux":
26
m = platform.machine()
27
if m == "x86_64":
28
return "linux-amd64.tar.gz"
29
elif m == "aarch64":
30
return "linux-arm64.tar.gz"
31
# TODO: detect RHEL7 since we have a special download for it
32
else:
33
raise Exception("Platform not supported")
34
35
36
def download_quarto(vers):
37
global output_location
38
global quarto_data
39
global version
40
41
suffix = get_platform_suffix()
42
quarto_url = f"https://github.com/quarto-dev/quarto-cli/releases/download/v{vers}/quarto-{vers}-{suffix}"
43
print("Downloading", quarto_url)
44
try:
45
name, resp = urlretrieve(quarto_url)
46
except Exception as e:
47
print("Error downloading Quarto:", e)
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", "")
70
quarto_url = f"https://github.com/quarto-dev/quarto-cli/releases/download/v{version}/quarto-{version}-{suffix}"
71
name, resp = urlretrieve(quarto_url)
72
73
output_location = f"quarto_cli/quarto-{version}"
74
os.makedirs(output_location, exist_ok=True)
75
76
if suffix.endswith(".zip"):
77
import zipfile
78
79
with zipfile.ZipFile(name, "r") as zip_ref:
80
zip_ref.extractall(output_location)
81
elif suffix.startswith("linux"):
82
import tarfile
83
84
with tarfile.open(name) as tf:
85
tf.extractall(Path(output_location).parent.resolve())
86
else:
87
import tarfile
88
89
with tarfile.open(name) as tf:
90
tf.extractall(output_location)
91
92
for path in glob.glob(str(Path(output_location, "**")), recursive=True):
93
quarto_data.append(path.replace("quarto_cli" + os.path.sep, ""))
94
95
96
def cleanup_quarto():
97
shutil.rmtree(output_location)
98
99
100
global version
101
102
version = open("version.txt").read().strip()
103
download_quarto(version)
104
setup(
105
version=version,
106
name="quarto_cli",
107
install_requires=[
108
"jupyter",
109
"nbclient",
110
"wheel",
111
],
112
packages=find_packages(include=["quarto_cli", "quarto_cli.*"]),
113
entry_points={
114
"console_scripts": [
115
"quarto = quarto_cli:run_quarto",
116
]
117
},
118
package_data={
119
"quarto_cli": quarto_data,
120
},
121
include_package_data=True,
122
)
123
cleanup_quarto()
124
125