milahu / nixpkgs

Nix Packages collection
MIT License
1 stars 0 forks source link

python3.pkgs.scancode-toolkit: PermissionError: [Errno 13] Permission denied: /lib/python3.11/site-packages/licensedcode/data/cache #49

Closed milahu closed 5 months ago

milahu commented 5 months ago

the scancode binary is not working

$ nix-shell -p python3.pkgs.scancode-toolkit

$ python3 -c "import scancode; print('ok')"
ok

$ scancode
Traceback (most recent call last):
  File "/nix/store/y3ja4pkiwvjzwm7dx25qqrsk13qr7s4d-python3.11-scancode-toolkit-32.1.0/bin/.scancode-wrapped", line 6, in <module>
    from scancode.cli import scancode
  File "/nix/store/y3ja4pkiwvjzwm7dx25qqrsk13qr7s4d-python3.11-scancode-toolkit-32.1.0/lib/python3.11/site-packages/scancode/__init__.py", line 16, in <module>
    from commoncode import fileutils
  File "/nix/store/4phgyrm3wq4z6i0x0ppq485w7xl4cnlr-python3.11-commoncode-31.0.3/lib/python3.11/site-packages/commoncode/fileutils.py", line 21, in <module>
    from scancode_config import scancode_temp_dir as _base_temp_dir
  File "/nix/store/y3ja4pkiwvjzwm7dx25qqrsk13qr7s4d-python3.11-scancode-toolkit-32.1.0/lib/python3.11/site-packages/scancode_config.py", line 185, in <module>
    _create_dir(licensedcode_cache_dir)
  File "/nix/store/y3ja4pkiwvjzwm7dx25qqrsk13qr7s4d-python3.11-scancode-toolkit-32.1.0/lib/python3.11/site-packages/scancode_config.py", line 52, in _create_dir
    os.makedirs(location)
  File "<frozen os>", line 225, in makedirs
PermissionError: [Errno 13] Permission denied: '/nix/store/y3ja4pkiwvjzwm7dx25qqrsk13qr7s4d-python3.11-scancode-toolkit-32.1.0/lib/python3.11/site-packages/licensedcode/data/cache'

fix: pkgs/development/python-modules/scancode-toolkit/default.nix

  postPatch = ''
    substituteInPlace src/scancode_config.py \
      --replace-fail \
        "std_license_cache_dir = join(scancode_src_dir, 'licensedcode', 'data', 'cache')" \
        "std_license_cache_dir = join(os.environ['HOME'], '.cache', 'scancode-toolkit', 'licensedcode', 'data', 'cache')" \
  '';

this will not work because $HOME would be taken literally, and not be expanded

  makeWrapperArgs = [
    "--set-default" "SCANCODE_LICENSE_INDEX_CACHE" "$HOME/.cache/scancode-toolkit/licensedcode/data"
  ];

ping @fabaff @NickCao via https://github.com/NixOS/nixpkgs/pull/299314

milahu commented 5 months ago

nope, this only happens when i build scancode-toolkit from git source and i dont build the index in scancode-toolkit-32.1.0/lib/python3.11/site-packages/licensedcode/data/cache/

scancode-toolkit/src/scancode_config.py

# we pre-build the index and bundle this with the the deployed release
# therefore we use package data
# .... but we accept this to be overriden with and env variable
std_license_cache_dir = join(scancode_src_dir, 'licensedcode', 'data', 'cache')
__env_license_cache_dir = os.getenv('SCANCODE_LICENSE_INDEX_CACHE')
licensedcode_cache_dir = (__env_license_cache_dir or std_license_cache_dir)