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