aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/python.go
blob: 9b55ffadb88c58cd84944a53ff7a4d6313b0e79c (plain)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package rosa

import (
	"slices"
	"strings"

	"hakurei.app/internal/pkg"
)

func (t Toolchain) newPython() (pkg.Artifact, string) {
	const (
		version  = "3.14.3"
		checksum = "ajEC32WPmn9Jvll0n4gGvlTvhMPUHb2H_j5_h9jf_esHmkZBRfAumDcKY7nTTsCH"
	)
	return t.NewPackage("python", version, pkg.NewHTTPGetTar(
		nil, "https://www.python.org/ftp/python/"+version+
			"/Python-"+version+".tgz",
		mustDecode(checksum),
		pkg.TarGzip,
	), &PackageAttr{
		// test_synopsis_sourceless assumes this is writable and checks __pycache__
		Writable: true,
		Chmod:    true,

		Env: []string{
			"EXTRATESTOPTS=-j0 -x " + strings.Join([]string{
				// requires internet access (http://www.pythontest.net/)
				"test_asyncio",
				"test_socket",
				"test_urllib2",
				"test_urllibnet",
				"test_urllib2net",

				// makes assumptions about uid_map/gid_map
				"test_os",
				"test_subprocess",

				// somehow picks up mtime of source code
				"test_zipfile",

				// requires gcc
				"test_ctypes",

				// breaks on llvm
				"test_dbm_gnu",
			}, " -x "),

			// _ctypes appears to infer something from the linker name
			"LDFLAGS=-Wl,--dynamic-linker=/system/lib/" +
				"ld-musl-" + linuxArch() + ".so.1",
		},
	}, &MakeHelper{
		Check: []string{"test"},
	},
		Zlib,
		Bzip2,
		Libffi,
		OpenSSL,

		PkgConfig,
		XZ,
	), version
}
func init() {
	artifactsM[Python] = Metadata{
		f: Toolchain.newPython,

		Name:        "python",
		Description: "the Python programming language interpreter",
		Website:     "https://www.python.org/",

		Dependencies: P{
			Zlib,
			Bzip2,
			Libffi,
			OpenSSL,
		},

		ID: 13254,
	}
}

// newViaPip is a helper for installing python dependencies via pip.
func newViaPip(
	name, description, version, interpreter, abi, platform, checksum, prefix string,
	extra ...PArtifact,
) Metadata {
	wname := name + "-" + version + "-" + interpreter + "-" + abi + "-" + platform + ".whl"
	return Metadata{
		f: func(t Toolchain) (pkg.Artifact, string) {
			return t.New(name+"-"+version, 0, t.AppendPresets(nil,
				slices.Concat(P{Python}, extra)...,
			), nil, nil, `
pip3 install \
	--no-index \
	--prefix=/system \
	--root=/work \
	/usr/src/`+wname+`
`, pkg.Path(AbsUsrSrc.Append(wname), false, pkg.NewHTTPGet(
				nil, prefix+wname,
				mustDecode(checksum),
			))), version
		},

		Name:        "python-" + name,
		Description: description,
		Website:     "https://pypi.org/project/" + name + "/",

		Dependencies: slices.Concat(P{Python}, extra),
	}
}

func (t Toolchain) newSetuptools() (pkg.Artifact, string) {
	const (
		version  = "82.0.1"
		checksum = "nznP46Tj539yqswtOrIM4nQgwLA1h-ApKX7z7ghazROCpyF5swtQGwsZoI93wkhc"
	)
	return t.New("setuptools-"+version, 0, t.AppendPresets(nil,
		Python,
	), nil, nil, `
pip3 install \
	--no-index \
	--prefix=/system \
	--root=/work \
	/usr/src/setuptools
`, pkg.Path(AbsUsrSrc.Append("setuptools"), true, pkg.NewHTTPGetTar(
		nil, "https://github.com/pypa/setuptools/archive/refs/tags/"+
			"v"+version+".tar.gz",
		mustDecode(checksum),
		pkg.TarGzip,
	))), version
}
func init() {
	artifactsM[Setuptools] = Metadata{
		f: Toolchain.newSetuptools,

		Name:        "python-setuptools",
		Description: "the autotools of the Python ecosystem",
		Website:     "https://pypi.org/project/setuptools/",

		Dependencies: P{
			Python,
		},

		ID: 4021,
	}
}

func init() {
	artifactsM[PythonPygments] = newViaPip(
		"pygments",
		" a syntax highlighting package written in Python",
		"2.19.2", "py3", "none", "any",
		"ak_lwTalmSr7W4Mjy2XBZPG9I6a0gwSy2pS87N8x4QEuZYif0ie9z0OcfRfi9msd",
		"https://files.pythonhosted.org/packages/"+
			"c7/21/705964c7812476f378728bdf590ca4b771ec72385c533964653c68e86bdc/",
	)

	artifactsM[PythonPluggy] = newViaPip(
		"pluggy",
		"the core framework used by the pytest, tox, and devpi projects",
		"1.6.0", "py3", "none", "any",
		"2HWYBaEwM66-y1hSUcWI1MyE7dVVuNNRW24XD6iJBey4YaUdAK8WeXdtFMQGC-4J",
		"https://files.pythonhosted.org/packages/"+
			"54/20/4d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf/",
	)

	artifactsM[PythonPackaging] = newViaPip(
		"packaging",
		"reusable core utilities for various Python Packaging interoperability specifications",
		"26.0", "py3", "none", "any",
		"iVVXcqdwHDskPKoCFUlh2x8J0Gyq-bhO4ns9DvUJ7oJjeOegRYtSIvLV33Bki-pP",
		"https://files.pythonhosted.org/packages/"+
			"b7/b9/c538f279a4e237a006a2c98387d081e9eb060d203d8ed34467cc0f0b9b53/",
	)

	artifactsM[PythonIniConfig] = newViaPip(
		"iniconfig",
		"a small and simple INI-file parser module",
		"2.3.0", "py3", "none", "any",
		"SDgs4S5bXi77aVOeKTPv2TUrS3M9rduiK4DpU0hCmDsSBWqnZcWInq9lsx6INxut",
		"https://files.pythonhosted.org/packages/"+
			"cb/b1/3846dd7f199d53cb17f49cba7e651e9ce294d8497c8c150530ed11865bb8/",
	)

	artifactsM[PythonPyTest] = newViaPip(
		"pytest",
		"the pytest framework",
		"9.0.2", "py3", "none", "any",
		"IM2wDbLke1EtZhF92zvAjUl_Hms1uKDtM7U8Dt4acOaChMnDg1pW7ib8U0wYGDLH",
		"https://files.pythonhosted.org/packages/"+
			"3b/ab/b3226f0bd7cdcf710fbede2b3548584366da3b19b5021e74f5bde2a8fa3f/",
		PythonIniConfig,
		PythonPackaging,
		PythonPluggy,
		PythonPygments,
	)
}