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-0,
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 = "2.6.3";
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-ZhZoR8O5oxcF8+zzihiIbiC/j3AkDL7AjaJSlZ0N48s=";
40 };
41
42 postPatch = ''
43 substituteInPlace craft_application/__init__.py \
44 --replace-fail "dev" "${version}"
45
46 substituteInPlace pyproject.toml \
47 --replace-fail "setuptools==69.4.0" "setuptools"
48 '';
49
50 build-system = [
51 setuptools
52 setuptools-scm
53 ];
54
55 dependencies = [
56 craft-archives
57 craft-cli
58 craft-grammar
59 craft-parts
60 craft-providers
61 pydantic-yaml-0
62 pygit2
63 pyyaml
64 snap-helpers
65 ];
66
67 nativeCheckInputs = [
68 git
69 hypothesis
70 pyfakefs
71 pytest-check
72 pytest-mock
73 pytestCheckHook
74 responses
75 ];
76
77 preCheck = ''
78 export HOME=$(mktemp -d)
79
80 # Tests require access to /etc/os-release, which isn't accessible in
81 # the test environment, so create a fake file, and modify the code
82 # to look for it.
83 echo 'ID=nixos' > $HOME/os-release
84 echo 'NAME=NixOS' >> $HOME/os-release
85 echo 'VERSION_ID="24.05"' >> $HOME/os-release
86
87 substituteInPlace craft_application/util/platforms.py \
88 --replace-fail "os_utils.OsRelease()" "os_utils.OsRelease(os_release_file='$HOME/os-release')"
89 '';
90
91 pythonImportsCheck = [ "craft_application" ];
92
93 pytestFlagsArray = [ "tests/unit" ];
94
95 disabledTests =
96 [
97 "test_to_yaml_file"
98 # Tests expecting pytest-time
99 "test_monitor_builds_success"
100 ]
101 ++ lib.optionals stdenv.isAarch64 [
102 # These tests have hardcoded "amd64" strings which fail on aarch64
103 "test_process_grammar_build_for"
104 "test_process_grammar_platform"
105 "test_process_grammar_default"
106 ];
107
108 passthru.updateScript = nix-update-script { };
109
110 meta = {
111 description = "The basis for Canonical craft applications";
112 homepage = "https://github.com/canonical/craft-application";
113 changelog = "https://github.com/canonical/craft-application/releases/tag/${version}";
114 license = lib.licenses.lgpl3Only;
115 maintainers = with lib.maintainers; [ jnsgruk ];
116 platforms = lib.platforms.linux;
117 };
118}