summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/co/compare50/package.nix
blob: 685018707c52f0d606af630f64dac193233d4fb2 (plain)
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
{
  lib,
  python3Packages,
  fetchFromGitHub,
  versionCheckHook,
}:

python3Packages.buildPythonApplication (finalAttrs: {
  pname = "compare50";
  version = "1.2.13";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "cs50";
    repo = "compare50";
    tag = "v${finalAttrs.version}";
    hash = "sha256-qRESVE9242Leo6js+YrRrLff7C3IjWFKSN2/GsC/8VA=";
  };

  postPatch = ''
    substituteInPlace setup.py --replace-fail \
      'scripts=["bin/compare50"]' 'entry_points={"console_scripts": ["compare50=compare50.__main__:main"]}'

    # Fix "AttributeError: module 'importlib' has no attribute 'resources'"
    substituteInPlace compare50/passes.py \
      --replace-fail "import importlib" "import importlib, importlib.resources"
  '';

  build-system = [
    python3Packages.setuptools
  ];

  dependencies = with python3Packages; [
    attrs
    intervaltree
    jinja2
    lib50
    numpy
    packaging
    pygments
    termcolor
    tqdm
  ];

  pythonRelaxDeps = [
    "attrs"
    "numpy"
    "termcolor"
  ];

  # Safely strip out the obsolete `importlib` PyPI package
  pythonRemoveDeps = [
    "importlib"
  ];

  pythonImportsCheck = [ "compare50" ];

  nativeCheckInputs = [ versionCheckHook ];

  # repo does not use pytest
  checkPhase = ''
    runHook preCheck

    ${python3Packages.python.interpreter} -m tests

    runHook postCheck
  '';

  meta = {
    description = "Tool for detecting similarity in code supporting over 300 languages";
    homepage = "https://cs50.readthedocs.io/projects/compare50/en/latest/";
    downloadPage = "https://github.com/cs50/compare50";
    changelog = "https://github.com/cs50/compare50/releases/tag/${finalAttrs.src.tag}";
    license = lib.licenses.gpl3Only;
    platforms = lib.platforms.unix;
    maintainers = with lib.maintainers; [ ethancedwards8 ];
    mainProgram = "compare50";
  };
})