package python {
	description = "the Python programming language interpreter";
	website = "https://www.python.org";
	anitya = 13254;

	version# = "3.14.6";
	source = remoteTar {
		url = "https://www.python.org/ftp/python/"+version+
			"/Python-"+version+".tgz";
		checksum = "yynwXnElUvlAweA_RkBKQY35P59Gu5YU6ickJs6Z-blIoHgw5KgKXROY1gq2w0ez";
		compress = gzip;
	};
	patches = [ "zipfile-no-default-strict_timestamps.patch" ];

	// test_synopsis_sourceless assumes this is writable and checks __pycache__
	writable = true;
	chmod = true;

	env = [
		"EXTRATESTOPTS=-j0 -x " + join {
			elems = [
				// 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",

				// patched out insane strict_timestamps default
				"test_zipfile",

				// requires gcc
				"test_ctypes",

				// breaks on llvm
				"test_dbm_gnu",
			];
			sep = " -x ";
		},

		// _ctypes appears to infer something from the linker name
		"LDFLAGS=-Wl,--dynamic-linker=/system/lib/" +
			"ld-musl-" + linuxArch + ".so.1",
	];

	exec = make {
		configure = { "enable-optimizations"; };
		check = [ "test" ];
		postInstall = "ln -s python3 /work/system/bin/python";
	};

	inputs = [
		zlib,
		bzip2,
		libffi,
		openssl,

		pkg-config,
		xz,

		kernel-headers,
	];

	runtime = [
		zlib,
		bzip2,
		libffi,
		openssl,
	];
}

package python-early {
	description = "minimal python interpreter exclusive to the bootstrap path";
	website = "https://www.python.org";
	exclude = true;
	anitya = 13254;
	block = "exclusive to the bootstrap path";

	version# = "3.14.6";
	source = remoteTar {
		url = "https://www.python.org/ftp/python/"+version+
			"/Python-"+version+".tgz";
		checksum = "yynwXnElUvlAweA_RkBKQY35P59Gu5YU6ickJs6Z-blIoHgw5KgKXROY1gq2w0ez";
		compress = gzip;
	};

	// test_synopsis_sourceless assumes this is writable and checks __pycache__
	writable = true;
	chmod = true;

	env = [
		"EXTRATESTOPTS=-j0 -x " + join {
			elems = [
				// 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",

				// insane strict_timestamps default
				"test_zipfile",

				// requires gcc
				"test_ctypes",

				// breaks on llvm
				"test_dbm_gnu",
			];
			sep = " -x ";
		},

		// _ctypes appears to infer something from the linker name
		"LDFLAGS=-Wl,--dynamic-linker=/system/lib/" +
			"ld-musl-" + linuxArch + ".so.1",
	];

	exec = make {
		check = [ "test" ];
		postInstall = "ln -s python3 /work/system/bin/python";
	};

	inputs = [
		zlib,
		bzip2,
		libffi,

		kernel-headers,
	];

	runtime = [
		zlib,
		bzip2,
		libffi,
	];
}

package python-setuptools {
	description = "the autotools of the Python ecosystem";
	website = "https://pypi.org/project/setuptools";
	anitya = 4021;

	version# = "83.0.0";
	source = remoteGitHub {
		suffix = "pypa/setuptools";
		tag = "v"+version;
		checksum = "WqYSqCAvwpcIG6yXV8vVzRMNWl2CrcPOUPwlYrLV70ykHSpKxW1-XYQ4Z4n0ebAt";
	};

	exec = pip {
		// error: invalid command 'dist_info'
		buildIsolation = true;
		// pytest circular dependency
		skipCheck = true;
	};

	runtime = [ python ];
}

package python-wheel {
	description = "the official binary distribution format for Python";
	website = "https://peps.python.org/pep-0427";
	anitya = 11428;

	version# = "0.47.0";
	source = remoteGitHub {
		suffix = "pypa/wheel";
		tag = version;
		checksum = "HZ-MvkUP8mbbx2YmsRNswj_bbOCIiXckuHqL5Qbvb5NxN5DYfWnqwkGNyS7OrId0";
	};

	exec = pip {
		install = true;
	};

	inputs = [
		python-flit-core,
		python-setuptools,
	];

	runtime = [ python ];
}

package python-vcs-versioning {
	description = "core VCS versioning functionality extracted as a standalone library";
	website = "https://setuptools-scm.readthedocs.io/en/latest";
	anitya = 389421;

	version# = "2.2.3";
	source = remoteGitHub {
		suffix = "pypa/setuptools-scm";
		tag = "vcs-versioning-v"+version;
		checksum = "8nxxeo7Dh51dQo31w2m_pgZgcv4fqwsZyXGs0KHxm4MnfKZJtlXfsU0OoBRUJiuq";
	};

	env = [
		"VCS_VERSIONING_PRETEND_VERSION=" + version,
	];

	exec = pip {
		// upstream is monorepo of two packages (setuptools-scm)
		append = [ "vcs-versioning" ];
		// pytest circular dependency
		skipCheck = true;
	};

	inputs = [
		python-setuptools,
		python-packaging,
	];

	runtime = [
		python-setuptools,
		python-packaging,
	];
}

package python-setuptools-scm {
	description = "extracts Python package versions from Git or Mercurial metadata";
	website = "https://setuptools-scm.readthedocs.io/en/latest";
	anitya = 7874;

	version# = "10.2.1";
	source = remoteGitHub {
		suffix = "pypa/setuptools-scm";
		tag = "setuptools-scm-v"+version;
		checksum = "XnfdKDHzgtY3imPPz1lA1H0QHnjXlN5ZI-er0I-kfUq4w_a6RzUq8FCOJNBOkpK1";
	};

	env = [
		"SETUPTOOLS_SCM_PRETEND_VERSION=" + version,
	];

	exec = pip {
		// upstream is monorepo of two packages
		append = [ "setuptools-scm" ];
		// pytest circular dependency
		skipCheck = true;
	};

	inputs = [
		python-setuptools,
		python-vcs-versioning,
	];

	runtime = [
		python-setuptools,
		python-vcs-versioning,
	];
}

package python-flit-core {
	description = "a PEP 517 build backend for packages using Flit";
	website = "https://flit.pypa.io";
	anitya = 44841;

	version# = "3.12.0";
	source = remoteGitHub {
		suffix = "pypa/flit";
		tag = version;
		checksum = "VcTsiGiDU1aPLbjSPe38f9OjJDCLcxFz9loObJqUI1ZxDHXAaQMxBpNyLz_G1Rff";
	};

	exec = pip {
		// upstream has other unused packages with many dependencies
		append = [ "flit_core" ];
		// pytest circular dependency
		skipCheck = true;
	};

	runtime = [ python ];
}

package python-packaging {
	description = "reusable core utilities for various Python Packaging interoperability specifications";
	website = "https://packaging.pypa.io";
	anitya = 60461;

	version# = "26.2";
	source = remoteGitHub {
		suffix = "pypa/packaging";
		tag = version;
		checksum = "rdpGa2EkPFbj1mFtLKLnSwIX9gPfELcuneiICjRVDNw6By49szTFVoW8gtMMZ6ZS";
	};

	exec = pip {
		// pytest circular dependency
		skipCheck = true;
	};

	inputs = [ python-flit-core ];
	runtime = [ python ];
}

package python-pathspec {
	description = "utility library for gitignore style pattern matching of file paths";
	website = "https://github.com/cpburnz/python-pathspec";
	anitya = 23424;

	version# = "1.1.1";
	source = remoteGitHub {
		suffix = "cpburnz/python-pathspec";
		tag = "v"+version;
		checksum = "1fVwoal6FoKXczoG3qRUi87TxSWESSGcgvnbEZDYuaOgsO25o36iF3SbAhwkr4Va";
	};

	exec = pip {
		// pytest circular dependency
		skipCheck = true;
	};

	inputs = [ python-flit-core ];
	runtime = [ python ];
}

package python-trove-classifiers {
	description = "canonical source for classifiers on PyPI";
	website = "https://pypi.org/p/trove-classifiers";
	anitya = 88298;

	version# = "2026.6.1.19";
	source = remoteGitHub {
		suffix = "pypa/trove-classifiers";
		tag = version;
		checksum = "zdDI6XTfzuFnlhdhilnhplItbLhZ9f2_vSHZP8u5Zvhu5_rhTB73SFEzxT5gb1bO";
	};

	exec = pip {
		// pytest circular dependency
		skipCheck = true;
	};

	inputs = [ python-setuptools ];
	runtime = [ python ];
}

package python-pluggy {
	description = "the core framework used by the pytest, tox, and devpi projects";
	website = "https://pluggy.readthedocs.io/en/latest";
	anitya = 7500;

	version# = "1.6.0";
	source = remoteGitHub {
		suffix = "pytest-dev/pluggy";
		tag = version;
		checksum = "GiUgDkKjF8Xn1cmq6iMhTGXzcPIYeaJrvQpHBSAJapNVx4UyuiTXqd5eVlxSClJu";
	};

	env = [
		"SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PLUGGY=" + version,
	];

	exec = pip {
		// pytest circular dependency
		skipCheck = true;
	};

	inputs = [ python-setuptools-scm ];
	runtime = [ python ];
}

package python-hatchling {
	description = "the extensible, standards compliant build backend used by Hatch";
	website = "https://hatch.pypa.io";
	anitya = 16137;

	version# = "1.17.1";
	source = remoteGitHub {
		suffix = "pypa/hatch";
		tag = "hatch-v"+version;
		checksum = "FK9PkGIkL3wyVFHOKrx9lSRqoevuQ_TFrN-pMqsoFKsh5eim4pfzx7MvL3ioif9o";
	};

	exec = pip {
		// upstream has other unused packages with many dependencies
		append = [ "backend" ];
		// pytest circular dependency
		skipCheck = true;
	};

	inputs = [
		python-packaging,
		python-pathspec,
		python-trove-classifiers,
		python-pluggy,
	];

	runtime = [
		python-packaging,
		python-pathspec,
		python-trove-classifiers,
		python-pluggy,
	];
}

package python-pygments {
	description = "a syntax highlighting package written in Python";
	website = "https://pygments.org";
	anitya = 3986;

	version# = "2.20.0";
	source = remoteGitHub {
		suffix = "pygments/pygments";
		tag = version;
		checksum = "L-2P6vn7c_CNZYliE5CJAWLxO1ziDQVVkf8bnZbHj8aSCQ43oWv11wC9KzU9MeCa";
	};

	exec = pip {
		// pytest circular dependency
		skipCheck = true;
	};

	inputs = [ python-hatchling ];
	runtime = [ python ];
}

package python-iniconfig {
	description = "a small and simple INI-file parser module";
	website = "https://github.com/pytest-dev/iniconfig";
	anitya = 114778;

	version# = "2.3.0";
	source = remoteGitHub {
		suffix = "pytest-dev/iniconfig";
		tag = "v"+version;
		checksum = "mH7VBZaXcYatBPE3RQQZvSzz_Ay8IPPek60NpPHZulPq4ReAFUUsA4EPWfiyMknZ";
	};

	env = [
		"SETUPTOOLS_SCM_PRETEND_VERSION_FOR_INICONFIG=" + version,
	];

	exec = pip {
		// pytest circular dependency
		skipCheck = true;
	};

	inputs = [ python-setuptools-scm ];
	runtime = [ python ];
}

package python-pytest {
	description = "the pytest framework";
	website = "https://pytest.org";
	anitya = 3765;

	version# = "9.1.1";
	source = remoteGitHub {
		suffix = "pytest-dev/pytest";
		tag = version;
		checksum = "PnsF2mxJDF1d1MeYfMmlrSa_OlI92F8OPlSVA-lqsh4ggRZiAHjbTdO_jfNox065";
	};

	env = [
		"SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYTEST=" + version,
	];

	exec = pip {
		// many dependencies
		skipCheck = true;
	};

	inputs = [
		python-iniconfig,
		python-packaging,
		python-pluggy,
		python-pygments,

		python-setuptools-scm,
	];

	runtime = [
		python-iniconfig,
		python-packaging,
		python-pluggy,
		python-pygments,
	];
}

package python-markupsafe {
	description = "implements a text object that escapes characters so it is safe to use in HTML and XML";
	website = "https://markupsafe.palletsprojects.com";
	anitya = 3918;

	version# = "3.0.3";
	source = remoteGitHub {
		suffix = "pallets/markupsafe";
		tag = version;
		checksum = "txRGYdWE3his1lHHRI-lZADw0-ILvUg2l5OGdFHtFXIb_QowGxwdxHCUSJIgmjQs";
	};

	exec = pip {
		// ModuleNotFoundError: No module named 'markupsafe'
		install = true;
	};

	inputs = [ python-setuptools ];
	runtime = [ python ];
}

package python-mako {
	description = "a template library written in Python";
	website = "https://www.makotemplates.org";
	anitya = 3915;

	version# = "1.3.12";
	source = remoteGitHub {
		suffix = "sqlalchemy/mako";
		tag = "rel_"+join {
			elems = split {
				s = version;
				sep = ".";
				n = 3;
			};
			sep = "_";
		};
		checksum = "OZbBsQe2MzRuAo5Mr4qRwWHGqU1EEZeBuSprDDIceAtMLIUJtO7SbERlxHIxNhLk";
	};

	exec = pip {};

	inputs = [
		python-markupsafe,

		python-setuptools,
	];

	runtime = [ python-markupsafe ];
}

package python-pyyaml {
	description = "a YAML parser and emitter for Python";
	website = "https://pyyaml.org";
	anitya = 4123;

	version# = "6.0.3";
	source = remoteGitHub {
		suffix = "yaml/pyyaml";
		tag = version;
		checksum = "7wDv0RW9chBdu9l5Q4Hun5F2HHdo105ZSIixwdFPKbEYbftW9YxmsegfL-zafnbJ";
	};

	exec = pip {
		// ModuleNotFoundError: No module named 'yaml'
		install = true;
	};

	inputs = [ python-setuptools ];
	runtime = [ python ];
}

package python-pycparser {
	description = "complete C99 parser in pure Python";
	website = "https://github.com/eliben/pycparser";
	anitya = 8175;

	version# = "3.00";
	source = remoteGitHub {
		suffix = "eliben/pycparser";
		tag = "release_v"+version;
		checksum = "4qfCMFKp0fLsRsloOAF780tXX_Ce_68RwinCmjNGObAX32WpF_iBafIKW1S1bYlA";
	};

	// test case hard codes gcc
	early = `
ln -s clang /system/bin/gcc
`;

	exec = pip {};

	inputs = [ python-setuptools ];
	runtime = [ python ];
}
