1{
2 lib,
3 stdenv,
4 darwin,
5 python3Packages,
6 fetchFromGitHub,
7 installShellFiles,
8 testers,
9 openapi-python-client,
10}:
11
12python3Packages.buildPythonApplication rec {
13 pname = "openapi-python-client";
14 version = "0.26.1";
15 pyproject = true;
16
17 src = fetchFromGitHub {
18 inherit version;
19 owner = "openapi-generators";
20 repo = "openapi-python-client";
21 tag = "v${version}";
22 hash = "sha256-+9Tm4othdBtSubffrzK6ufjq69woSytiOEi+S+tqAxw=";
23 };
24
25 nativeBuildInputs = [
26 installShellFiles
27 ]
28 ++ lib.optionals stdenv.hostPlatform.isDarwin [
29 darwin.ps
30 ];
31
32 build-system = with python3Packages; [
33 hatchling
34 ];
35
36 dependencies = (
37 with python3Packages;
38 [
39 attrs
40 httpx
41 jinja2
42 pydantic
43 python-dateutil
44 ruamel-yaml
45 ruff
46 shellingham
47 typer
48 typing-extensions
49 ]
50 );
51 # openapi-python-client defines upper bounds to the dependencies, ruff python library is
52 # just a simple wrapper to locate the binary. We'll remove the upper bound
53 pythonRelaxDeps = [ "ruff" ];
54
55 postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
56 # see: https://github.com/fastapi/typer/blob/5889cf82f4ed925f92e6b0750bf1b1ed9ee672f3/typer/completion.py#L54
57 # otherwise shellingham throws exception on darwin
58 export _TYPER_COMPLETE_TEST_DISABLE_SHELL_DETECTION=1
59 installShellCompletion --cmd openapi-python-client \
60 --bash <($out/bin/openapi-python-client --show-completion bash) \
61 --fish <($out/bin/openapi-python-client --show-completion fish) \
62 --zsh <($out/bin/openapi-python-client --show-completion zsh)
63 '';
64
65 passthru = {
66 tests.version = testers.testVersion {
67 package = openapi-python-client;
68 };
69 };
70
71 meta = {
72 description = "Generate modern Python clients from OpenAPI";
73 homepage = "https://github.com/openapi-generators/openapi-python-client";
74 changelog = "https://github.com/openapi-generators/openapi-python-client/releases/tag/${src.tag}";
75 license = lib.licenses.mit;
76 mainProgram = "openapi-python-client";
77 maintainers = with lib.maintainers; [ konradmalik ];
78 };
79}