-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
111 lines (90 loc) · 3.26 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import glob
import os
import platform
import shutil
import sys
from pathlib import Path
from setuptools import setup
from setuptools.command.build_py import build_py
from setuptools.command.install import install
from urllib.request import urlretrieve
# The version number for this installation
print("Current working directory:", os.getcwd())
quarto_data = []
here = os.path.abspath(os.path.dirname(__file__))
version_file = os.path.join(here, 'version.txt')
version = open(version_file).read().strip()
target_directory = "quarto_cli"
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(version, suffix):
quarto_url = f"https://github.com/quarto-dev/quarto-cli/releases/download/v{version}/quarto-{version}-{suffix}"
print("Downloading", quarto_url)
try:
name, resp = urlretrieve(quarto_url)
return name
except Exception as e:
print("Error downloading Quarto:", e)
def move_pkg_subdir(name, fromDir, toDir):
global quarto_data
mvFrom = os.path.join(fromDir, name)
mvto = os.path.join(toDir, name)
shutil.move(mvFrom, mvto)
for path in glob.glob(str(Path(mvto, "**")), recursive=True):
quarto_data.append(path.replace("quarto_cli" + os.path.sep, ""))
class CustomBuild(build_py):
def run(self):
print("Downloading and installing quarto-cli binaries...")
suffix = get_platform_suffix()
name = download_quarto(version, suffix)
output_location = f"{target_directory}/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)
# Move the bin/share directory up a level
move_pkg_subdir("bin", output_location, target_directory)
move_pkg_subdir("share", output_location, target_directory)
# Remove the old directory
shutil.rmtree(output_location)
super().run()
def byte_compile(self, files):
pass
def no_compile(self, file_path):
# Define your exclusion logic here
# Example: Exclude files in a 'tests' directory
return target_directory in file_path
this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text()
setup(
version=version,
package_data={
'': ['version.txt'],
'quarto_cli': quarto_data
},
include_package_data=True,
cmdclass={
'build_py': CustomBuild,
},
)