forked from quarto-dev/quarto-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
96 lines (85 loc) · 3.01 KB
/
setup.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from setuptools import setup, find_packages
import glob
import sys
import platform
from urllib.request import urlretrieve
from pathlib import Path
import os
import shutil
import subprocess
output_location = ""
quarto_data = []
# Clean up the build because caching appears to
# completely not work with dynamic package_data and version
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"
elif sys.platform == "win32":
return "win.zip"
elif sys.platform == "linux":
m = platform.machine()
if m == "x86_64":
return "linux-amd64.tar.gz"
elif m == "aarch64":
return "linux-arm64.tar.gz"
# TODO: detect RHEL7 since we have a special download for it
else:
raise Exception("Platform not supported")
def download_quarto(vers):
global output_location
global quarto_data
global version
suffix = get_platform_suffix()
quarto_url = f"https://github.com/quarto-dev/quarto-cli/releases/download/v{vers}/quarto-{vers}-{suffix}"
print("Downloading", quarto_url)
try:
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", "")
quarto_url = f"https://github.com/quarto-dev/quarto-cli/releases/download/v{version}/quarto-{version}-{suffix}"
name, resp = urlretrieve(quarto_url)
output_location = f"quarto_cli/quarto-{version}"
os.makedirs(output_location, exist_ok=True)
if suffix.endswith(".zip"):
import zipfile
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',
install_requires=[
'jupyter',
'nbclient',
'wheel',
],
packages=find_packages(include=['quarto_cli', 'quarto_cli.*']),
entry_points={
'console_scripts': [
'quarto = quarto_cli:run_quarto',
]
},
package_data={
'quarto_cli': quarto_data,
},
include_package_data=True,
)
cleanup_quarto()