1{
2 lib,
3 buildPythonPackage,
4 pythonOlder,
5 fetchPypi,
6 pythonRelaxDepsHook,
7 setuptools,
8 click,
9 urllib3,
10 requests,
11 packaging,
12 dparse,
13 ruamel-yaml,
14 jinja2,
15 marshmallow,
16 authlib,
17 jwt,
18 rich,
19 typer,
20 pydantic,
21 safety-schemas,
22 typing-extensions,
23 pytestCheckHook,
24}:
25
26buildPythonPackage rec {
27 pname = "safety";
28 version = "3.2.0";
29
30 disabled = pythonOlder "3.7";
31
32 pyproject = true;
33
34 src = fetchPypi {
35 inherit pname version;
36 hash = "sha256-i9XKtfPYphzg6m6Y8mfBAG0FYJfEXGRP7nr+/31ZScE=";
37 };
38
39 postPatch = ''
40 substituteInPlace safety/safety.py \
41 --replace-fail "telemetry=True" "telemetry=False"
42 substituteInPlace safety/util.py \
43 --replace-fail "telemetry = True" "telemetry = False"
44 substituteInPlace safety/cli.py \
45 --replace-fail "disable-optional-telemetry', default=False" \
46 "disable-optional-telemetry', default=True"
47 substituteInPlace safety/scan/finder/handlers.py \
48 --replace-fail "telemetry=True" "telemetry=False"
49 '';
50
51 nativeBuildInputs = [
52 pythonRelaxDepsHook
53 setuptools
54 ];
55
56 pythonRelaxDeps = [
57 "packaging"
58 "dparse"
59 "authlib"
60 "pydantic"
61 ];
62
63 propagatedBuildInputs = [
64 setuptools
65 click
66 urllib3
67 requests
68 packaging
69 dparse
70 ruamel-yaml
71 jinja2
72 marshmallow
73 authlib
74 jwt
75 rich
76 typer
77 pydantic
78 safety-schemas
79 typing-extensions
80 ];
81
82 nativeCheckInputs = [ pytestCheckHook ];
83
84 # Disable tests depending on online services
85 disabledTests = [
86 "test_announcements_if_is_not_tty"
87 "test_check_live"
88 "test_check_live_cached"
89 "test_get_packages_licenses_without_api_key"
90 "test_validate_with_policy_file_using_invalid_keyword"
91 "test_validate_with_basic_policy_file"
92 ];
93
94 # ImportError: cannot import name 'get_command_for' from partially initialized module 'safety.cli_util' (most likely due to a circular import)
95 disabledTestPaths = [ "tests/alerts/test_utils.py" ];
96
97 preCheck = ''
98 export HOME=$(mktemp -d)
99 '';
100
101 meta = with lib; {
102 description = "Checks installed dependencies for known vulnerabilities";
103 mainProgram = "safety";
104 homepage = "https://github.com/pyupio/safety";
105 changelog = "https://github.com/pyupio/safety/blob/${version}/CHANGELOG.md";
106 license = licenses.mit;
107 maintainers = with maintainers; [
108 thomasdesr
109 dotlambda
110 ];
111 };
112}