1{ lib
2, vscode-utils
3, icu
4, python3
5 # When `true`, the python default setting will be fixed to specified.
6 # Use version from `PATH` for default setting otherwise.
7 # Defaults to `false` as we expect it to be project specific most of the time.
8, pythonUseFixed ? false
9 # For updateScript
10, writeScript
11, bash
12, curl
13, coreutils
14, gnused
15, jq
16, nix
17}:
18
19vscode-utils.buildVscodeMarketplaceExtension rec {
20 mktplcRef = {
21 name = "python";
22 publisher = "ms-python";
23 version = "2023.1.10091012";
24 sha256 = "sha256-JosFv6ngJmw1XRILwTZMVxlGIdWFLFQjj4olfnVwAIM=";
25 };
26
27 buildInputs = [ icu ];
28
29 nativeBuildInputs = [ python3.pkgs.wrapPython ];
30
31 propagatedBuildInputs = with python3.pkgs; [
32 debugpy
33 jedi-language-server
34 ];
35
36 postPatch = ''
37 # remove bundled python deps and use libs from nixpkgs
38 rm -r pythonFiles/lib
39 mkdir -p pythonFiles/lib/python/
40 ln -s ${python3.pkgs.debugpy}/lib/*/site-packages/debugpy pythonFiles/lib/python/
41 buildPythonPath "$propagatedBuildInputs"
42 for i in pythonFiles/*.py; do
43 patchPythonScript "$i"
44 done
45 '' + lib.optionalString pythonUseFixed ''
46 # Patch `packages.json` so that nix's *python* is used as default value for `python.pythonPath`.
47 substituteInPlace "./package.json" \
48 --replace "\"default\": \"python\"" "\"default\": \"${python3.interpreter}\""
49 '';
50
51 passthru.updateScript = writeScript "update" ''
52 #! ${bash}/bin/bash
53
54 set -eu -o pipefail
55
56 export PATH=${lib.makeBinPath [
57 curl
58 coreutils
59 gnused
60 jq
61 nix
62 ]}
63
64 api=$(curl -s 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery' \
65 -H 'accept: application/json;api-version=3.0-preview.1' \
66 -H 'content-type: application/json' \
67 --data-raw '{"filters":[{"criteria":[{"filterType":7,"value":"${mktplcRef.publisher}.${mktplcRef.name}"}]}],"flags":16}')
68 # Find the latest version compatible with stable vscode version
69 version=$(echo $api | jq -r '.results[0].extensions[0].versions | map(select(has("properties"))) | map(select(.properties | map(select(.key == "Microsoft.VisualStudio.Code.Engine")) | .[0].value | test("\\^[0-9.]+$"))) | .[0].version')
70
71 if [[ $version != ${mktplcRef.version} ]]; then
72 tmp=$(mktemp)
73 curl -sLo $tmp $(echo ${(import ../mktplcExtRefToFetchArgs.nix mktplcRef).url} | sed "s|${mktplcRef.version}|$version|")
74 hash=$(nix hash file --type sha256 --base32 --sri $tmp)
75 sed -i -e "s|${mktplcRef.sha256}|$hash|" -e "s|${mktplcRef.version}|$version|" pkgs/applications/editors/vscode/extensions/python/default.nix
76 fi
77 '';
78
79 meta = {
80 description = "A Visual Studio Code extension with rich support for the Python language";
81 downloadPage = "https://marketplace.visualstudio.com/items?itemName=ms-python.python";
82 homepage = "https://github.com/Microsoft/vscode-python";
83 changelog = "https://github.com/microsoft/vscode-python/releases";
84 license = lib.licenses.mit;
85 platforms = [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ];
86 maintainers = [ lib.maintainers.jraygauthier lib.maintainers.jfchevrette ];
87 };
88}