1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 nix-update-script,
6 packaging,
7 platformdirs,
8 pydantic_1,
9 pyyaml,
10 requests-unixsocket,
11 setuptools,
12 setuptools-scm,
13 urllib3,
14 pytest-check,
15 pytest-mock,
16 pytestCheckHook,
17 responses,
18 freezegun,
19 pytest-subprocess,
20 pytest-logdog,
21}:
22
23buildPythonPackage rec {
24 pname = "craft-providers";
25 version = "1.23.1";
26
27 pyproject = true;
28
29 src = fetchFromGitHub {
30 owner = "canonical";
31 repo = "craft-providers";
32 rev = "refs/tags/${version}";
33 hash = "sha256-opVgOtbwZD+uQJ10Q8QlgQaS9KjRFnQ4h98Ak7Ze5qQ=";
34 };
35
36 patches = [
37 # This lib will try to inject snaps *from the host system* into the build
38 # system. This patch short-circuits that logic and ensures that snaps are
39 # installed on the build system from the snap store - because there is no
40 # snapd on NixOS hosts that can be used for the injection. This patch will
41 # likely never be accepted upstream.
42 ./inject-snaps.patch
43 ];
44
45 postPatch = ''
46 substituteInPlace craft_providers/lxd/installer.py \
47 --replace-fail "/var/snap/lxd/common/lxd/unix.socket" "/var/lib/lxd/unix.socket"
48
49 substituteInPlace craft_providers/__init__.py \
50 --replace-fail "dev" "${version}"
51
52 # The urllib3 incompat: https://github.com/msabramo/requests-unixsocket/pull/69
53 # This is already patched in nixpkgs.
54 substituteInPlace pyproject.toml \
55 --replace-fail "setuptools==69.1.1" "setuptools" \
56 --replace-fail "urllib3<2" "urllib3"
57 '';
58
59 nativeBuildInputs = [
60 setuptools
61 setuptools-scm
62 ];
63
64 propagatedBuildInputs = [
65 packaging
66 platformdirs
67 pydantic_1
68 pyyaml
69 requests-unixsocket
70 urllib3
71 ];
72
73 pythonImportsCheck = [ "craft_providers" ];
74
75 nativeCheckInputs = [
76 freezegun
77 pytest-check
78 pytest-mock
79 pytest-subprocess
80 pytest-logdog
81 pytestCheckHook
82 responses
83 ];
84
85 preCheck = ''
86 mkdir -p check-phase
87 export HOME="$(pwd)/check-phase"
88 '';
89
90 pytestFlagsArray = [ "tests/unit" ];
91
92 disabledTestPaths = [
93 # Relies upon "logassert" python package which isn't in nixpkgs
94 "tests/unit/bases/test_ubuntu_buildd.py"
95 "tests/unit/bases/test_centos_7.py"
96 "tests/unit/bases/test_almalinux.py"
97 "tests/unit/actions/test_snap_installer.py"
98 # Relies upon "pytest-time" python package which isn't in nixpkgs
99 "tests/unit/multipass"
100 "tests/unit/lxd"
101 "tests/unit/test_base.py"
102 "tests/unit/util/test_retry.py"
103 ];
104
105 passthru.updateScript = nix-update-script { };
106
107 meta = {
108 description = "Interfaces for instantiating and controlling a variety of build environments";
109 homepage = "https://github.com/canonical/craft-providers";
110 changelog = "https://github.com/canonical/craft-providers/releases/tag/${version}";
111 license = lib.licenses.lgpl3Only;
112 maintainers = with lib.maintainers; [ jnsgruk ];
113 platforms = lib.platforms.linux;
114 };
115}