1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 craft-archives,
6 craft-cli,
7 craft-grammar,
8 craft-parts,
9 craft-providers,
10 fetchFromGitHub,
11 git,
12 hypothesis,
13 nix-update-script,
14 pydantic-yaml,
15 pyfakefs,
16 pygit2,
17 pytest-check,
18 pytest-mock,
19 pytestCheckHook,
20 pythonOlder,
21 pyyaml,
22 responses,
23 setuptools-scm,
24 setuptools,
25 snap-helpers,
26}:
27
28buildPythonPackage rec {
29 pname = "craft-application";
30 version = "3.2.0";
31 pyproject = true;
32
33 disabled = pythonOlder "3.10";
34
35 src = fetchFromGitHub {
36 owner = "canonical";
37 repo = "craft-application";
38 rev = "refs/tags/${version}";
39 hash = "sha256-2JfCe7FJtuObC/4miA+OC/ctGy1fhdgI7DsowNYjQk8=";
40 };
41
42 postPatch = ''
43 substituteInPlace pyproject.toml \
44 --replace-fail "setuptools==70.1.0" "setuptools"
45 '';
46
47 build-system = [ setuptools-scm ];
48
49 pythonRelaxDeps = [ "requests" ];
50
51 dependencies = [
52 craft-archives
53 craft-cli
54 craft-grammar
55 craft-parts
56 craft-providers
57 pydantic-yaml
58 pygit2
59 pyyaml
60 snap-helpers
61 ];
62
63 nativeCheckInputs = [
64 git
65 hypothesis
66 pyfakefs
67 pytest-check
68 pytest-mock
69 pytestCheckHook
70 responses
71 ];
72
73 preCheck = ''
74 export HOME=$(mktemp -d)
75
76 # Tests require access to /etc/os-release, which isn't accessible in
77 # the test environment, so create a fake file, and modify the code
78 # to look for it.
79 echo 'ID=nixos' > $HOME/os-release
80 echo 'NAME=NixOS' >> $HOME/os-release
81 echo 'VERSION_ID="24.05"' >> $HOME/os-release
82
83 substituteInPlace craft_application/util/platforms.py \
84 --replace-fail "os_utils.OsRelease()" "os_utils.OsRelease(os_release_file='$HOME/os-release')"
85 '';
86
87 pythonImportsCheck = [ "craft_application" ];
88
89 pytestFlagsArray = [ "tests/unit" ];
90
91 disabledTests =
92 [
93 "test_to_yaml_file"
94 # Tests expecting pytest-time
95 "test_monitor_builds_success"
96 ]
97 ++ lib.optionals stdenv.isAarch64 [
98 # These tests have hardcoded "amd64" strings which fail on aarch64
99 "test_process_grammar_build_for"
100 "test_process_grammar_platform"
101 "test_process_grammar_default"
102 ];
103
104 passthru.updateScript = nix-update-script { };
105
106 meta = {
107 description = "Basis for Canonical craft applications";
108 homepage = "https://github.com/canonical/craft-application";
109 changelog = "https://github.com/canonical/craft-application/blob/${src.rev}/docs/reference/changelog.rst";
110 license = lib.licenses.lgpl3Only;
111 maintainers = with lib.maintainers; [ jnsgruk ];
112 platforms = lib.platforms.linux;
113 };
114}