about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/embedded/fpga/apio/default.nix
blob: 47ff562958ecf74350fd5cd8894eb822ebbcd06c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{ lib
, buildPythonApplication
, fetchFromGitHub
, click
, semantic-version
, requests
, colorama
, pyserial
, wheel
, scons
, setuptools
, tinyprog
, flit-core
, pytestCheckHook
}:

buildPythonApplication rec {
  pname = "apio";
  version = "0.8.1";
  format = "pyproject";

  src = fetchFromGitHub {
    owner = "FPGAwars";
    repo = "apio";
    rev = "v${version}";
    sha256 = "sha256-04qAGTzusMT3GsaRxDoXNJK1Mslzxu+ugQclBJx8xzE=";
  };

  postPatch = ''
    substituteInPlace pyproject.toml \
      --replace 'scons==4.2.0' 'scons' \
      --replace '==' '>='

    substituteInPlace apio/managers/scons.py --replace \
      'return "tinyprog --libusb --program"' \
      'return "${tinyprog}/bin/tinyprog --libusb --program"'
    substituteInPlace apio/util.py --replace \
      '_command = join(get_bin_dir(), "tinyprog")' \
      '_command = "${tinyprog}/bin/tinyprog"'

    # semantic-version seems to not support version numbers like the one of tinyprog in Nixpkgs (1.0.24.dev114+gxxxxxxx).
    # See https://github.com/rbarrois/python-semanticversion/issues/47.
    # This leads to an error like "Error: Invalid version string: '1.0.24.dev114+g97f6353'"
    # when executing "apio upload" for a TinyFPGA.
    # Replace the dot with a dash to work around this problem.
    substituteInPlace apio/managers/scons.py --replace \
        'version = semantic_version.Version(pkg_version)' \
        'version = semantic_version.Version(pkg_version.replace(".dev", "-dev"))'
  '';

  nativeBuildInputs = [
    flit-core
  ];

  propagatedBuildInputs = [
    click
    semantic-version
    requests
    colorama
    pyserial
    wheel
    scons
    setuptools # needs pkg_resources at runtime (technically not needed when tinyprog is also in this list because of the propagatedBuildInputs of tinyprog)

    tinyprog # needed for upload to TinyFPGA
  ];

  nativeCheckInputs = [
    pytestCheckHook
  ];

  pytestFlagsArray = [ "--offline" ];

  meta = with lib; {
    description = "Open source ecosystem for open FPGA boards";
    mainProgram = "apio";
    homepage = "https://github.com/FPGAwars/apio";
    license = licenses.gpl2Only;
    maintainers = with maintainers; [ Luflosi ];
  };
}