Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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 gitMinimal, 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 pyyaml, 24 responses, 25 setuptools-scm, 26 snap-helpers, 27 freezegun, 28 cacert, 29 writableTmpDirAsHomeHook, 30}: 31 32buildPythonPackage rec { 33 pname = "craft-application"; 34 version = "5.6.0"; 35 pyproject = true; 36 37 src = fetchFromGitHub { 38 owner = "canonical"; 39 repo = "craft-application"; 40 tag = version; 41 hash = "sha256-d1uptYLndXvJrnA42vXoZTVkX1WxgKGfZX6SXYSffSo="; 42 }; 43 44 postPatch = '' 45 substituteInPlace pyproject.toml \ 46 --replace-fail "setuptools==75.9.1" "setuptools" 47 48 substituteInPlace craft_application/git/_utils.py \ 49 --replace-fail "/snap/core22/current/etc/ssl/certs" "${cacert}/etc/ssl/certs" 50 ''; 51 52 build-system = [ setuptools-scm ]; 53 54 pythonRelaxDeps = [ 55 "pygit2" 56 "requests" 57 ]; 58 59 dependencies = [ 60 craft-archives 61 craft-cli 62 craft-grammar 63 craft-parts 64 craft-platforms 65 craft-providers 66 jinja2 67 license-expression 68 pygit2 69 pyyaml 70 snap-helpers 71 ]; 72 73 nativeCheckInputs = [ 74 freezegun 75 gitMinimal 76 hypothesis 77 pyfakefs 78 pytest-check 79 pytest-mock 80 pytest-subprocess 81 pytestCheckHook 82 responses 83 writableTmpDirAsHomeHook 84 ]; 85 86 preCheck = '' 87 # Tests require access to /etc/os-release, which isn't accessible in 88 # the test environment, so create a fake file, and modify the code 89 # to look for it. 90 echo 'ID=nixos' > $HOME/os-release 91 echo 'NAME=NixOS' >> $HOME/os-release 92 echo 'VERSION_ID="24.05"' >> $HOME/os-release 93 94 substituteInPlace craft_application/util/platforms.py \ 95 --replace-fail "os_utils.OsRelease()" "os_utils.OsRelease(os_release_file='$HOME/os-release')" 96 97 # Not using `--replace-fail` here only because it simplifies overriding this package in the charmcraft 98 # derivation. Once charmcraft has moved to craft-application >= 5, `--replace-fail` can be added. 99 substituteInPlace tests/conftest.py \ 100 --replace "include_lsb=False, include_uname=False, include_oslevel=False" "include_lsb=False, include_uname=False, include_oslevel=False, os_release_file='$HOME/os-release'" 101 102 # The project attempts to write into the user's runtime directory, usually 103 # '/run/user/<uid>', which fails in the build environment. By setting this 104 # variable, we redirect the runtime directory lookup to the temp directory 105 # created by the 'writableTmpDirAsHomeHook'. 106 export XDG_RUNTIME_DIR="$HOME" 107 ''; 108 109 pythonImportsCheck = [ "craft_application" ]; 110 111 enabledTestPaths = [ "tests/unit" ]; 112 113 disabledTests = [ 114 "test_to_yaml_file" 115 # Tests expecting pytest-time 116 "test_monitor_builds_success" 117 # Temporary fix until new release to support Python 3.13 118 "test_grammar_aware_part_error" 119 "test_grammar_aware_part_error[part2]" 120 "test_grammar_aware_project_error[project0]" 121 # Temp fix - asserts fail against error messages which have changed 122 # slightly in a later revision of craft-platforms. No functional error. 123 "test_platform_invalid_arch" 124 "test_platform_invalid_build_arch" 125 # Asserts against string output which fails when not on Ubuntu. 126 "test_run_error_with_docs_url" 127 # Asserts a fallback path for SSL certs that we override in a patch. 128 "test_import_fallback_wrong_metadata" 129 ] 130 ++ lib.optionals stdenv.hostPlatform.isAarch64 [ 131 # These tests have hardcoded "amd64" strings which fail on aarch64 132 "test_process_grammar_build_for" 133 "test_process_grammar_platform" 134 "test_process_grammar_default" 135 "test_create_craft_manifest" 136 "test_create_project_manifest" 137 "test_from_packed_artifact" 138 "test_teardown_session_create_manifest" 139 ]; 140 141 disabledTestPaths = [ 142 # These tests assert outputs of commands that assume Ubuntu-related output. 143 "tests/unit/services/test_lifecycle.py" 144 ] 145 ++ lib.optionals stdenv.hostPlatform.isAarch64 [ 146 # Hard-coded assumptions around use of "amd64" arch strings. 147 "tests/unit/services/test_project.py" 148 ]; 149 150 passthru.updateScript = nix-update-script { }; 151 152 meta = { 153 description = "Basis for Canonical craft applications"; 154 homepage = "https://github.com/canonical/craft-application"; 155 changelog = "https://github.com/canonical/craft-application/blob/${src.tag}/docs/reference/changelog.rst"; 156 license = lib.licenses.lgpl3Only; 157 maintainers = with lib.maintainers; [ jnsgruk ]; 158 platforms = lib.platforms.linux; 159 }; 160}