!rWxyQqNqMUDLECdsIf:blad.is

Poetry2nix

305 Members
https://github.com/nix-community/poetry2nix55 Servers

Load older messages


SenderMessageTime
16 Feb 2022
@k900:0upti.meK900Because importlib will be slower than just reading the file off the disk 20:37:00
@k900:0upti.meK900Probably not by enough for it to mattrr20:37:10
@k900:0upti.meK900* Probably not by enough for it to matter20:37:13
@k900:0upti.meK900But it's generally good practice to load resources once and then keep them in memory 20:37:26
@k900:0upti.meK900Because your project could be installed as a wheel, or as an egg, or as whatever other weird format whatever other weird Python implementation uses 20:38:02
@worldofgeese:one.ems.hostworldofgeeseWow, this is really helpful, thank you for taking the time with me! I will try and implement your suggestions and see if I can marshal it into some form of life20:39:54
@worldofgeese:one.ems.hostworldofgeese * Wow, this is really helpful, thank you for taking the time with me! I will try and implement your suggestions and see if I can marshal my application into some form of life20:43:18
@asymmetric:matrix.dapp.org.ukasymmetric left the room.22:08:54
17 Feb 2022
@worldofgeese:one.ems.hostworldofgeese

I've changed the code of data.py to access the package resource data.json like so:

from importlib import resources

with resources.open_text("little_bits_of_buddha", "data.json") as json_file:
    data = json.load(json_file)


def random_sutta():
    attributed_quotes = []
    for collection in data["collection"].values():
        for quote in collection.values():
            attributed_quotes.append(quote)
    return random.choice(attributed_quotes)

which again works with poetry run lbob and nix build && ./result/bin/lbob but continues to give errors accessing the resource from inside dockerTools.streamLayeredImage produced image:

  File "/nix/store/y3i0wgxmwc9l2r5a167isx4bnpsm4fih-python3.9-little-bits-of-buddha-0.1.0/lib/python3.9/site-packages/little_bits_of_buddha/data.py", line 7, in <module>
    with resources.open_text(__package__, "data.json") as json_file:
  File "/nix/store/i6vabb4div9iy6lsl642d86k1q8riasn-python3-3.9.9/lib/python3.9/importlib/resources.py", line 121, in open_text
    open_binary(package, resource), encoding=encoding, errors=errors)
  File "/nix/store/i6vabb4div9iy6lsl642d86k1q8riasn-python3-3.9.9/lib/python3.9/importlib/resources.py", line 111, in open_binary
    raise FileNotFoundError(message)
FileNotFoundError: 'data.json' resource not found in 'little_bits_of_buddha'
07:39:15
@worldofgeese:one.ems.hostworldofgeese *

I've changed the code of data.py to access the package resource data.json like so:

from importlib import resources

with resources.open_text("little_bits_of_buddha", "data.json") as json_file:
    data = json.load(json_file)


def random_sutta():
    attributed_quotes = []
    for collection in data["collection"].values():
        for quote in collection.values():
            attributed_quotes.append(quote)
    return random.choice(attributed_quotes)

which again works with poetry run lbob and nix build && ./result/bin/lbob but continues to give errors accessing the resource from inside a dockerTools.streamLayeredImage produced image:

  File "/nix/store/y3i0wgxmwc9l2r5a167isx4bnpsm4fih-python3.9-little-bits-of-buddha-0.1.0/lib/python3.9/site-packages/little_bits_of_buddha/data.py", line 7, in <module>
    with resources.open_text(__package__, "data.json") as json_file:
  File "/nix/store/i6vabb4div9iy6lsl642d86k1q8riasn-python3-3.9.9/lib/python3.9/importlib/resources.py", line 121, in open_text
    open_binary(package, resource), encoding=encoding, errors=errors)
  File "/nix/store/i6vabb4div9iy6lsl642d86k1q8riasn-python3-3.9.9/lib/python3.9/importlib/resources.py", line 111, in open_binary
    raise FileNotFoundError(message)
FileNotFoundError: 'data.json' resource not found in 'little_bits_of_buddha'
07:39:42
@k900:0upti.meK900Post the actual image config07:40:40
@k900:0upti.meK900And check if the file is there in your container07:40:47
@worldofgeese:one.ems.hostworldofgeese Image config is here from line 23 07:41:43
@worldofgeese:one.ems.hostworldofgeese
bash-5.1# ls /nix/store/i6vabb4div9iy6lsl642d86k1q8riasn-python3.9-little-bits-of-buddha-0.1.0/lib/python3.9/site-packages/little_bits_of_buddha/
__pycache__  app.py  data.json	data.py  run.py
07:44:38
@k900:0upti.meK900That is weird07:47:10
@k900:0upti.meK900 What is PYTHONPATH set to in lbob? 07:47:15
@worldofgeese:one.ems.hostworldofgeese I haven't set it explicitly, should I use this StackOverflow answer to find out? 07:49:07
@worldofgeese:one.ems.hostworldofgeeseAnd inside or outside the container?07:49:23
@k900:0upti.meK900 Inside the container, just run cat $(which lbob) 07:50:36
@worldofgeese:one.ems.hostworldofgeese
bash-5.1# cat $(which lbob)
#! /nix/store/2kh3c4v2vf6d6xg6c9n8zvfpwf3zzwca-bash-5.1-p12/bin/bash -e
export PATH='/nix/store/i6vabb4div9iy6lsl642d86k1q8riasn-python3-3.9.9/bin:/nix/store/3jiz0vgryj2si4bglz14wwak4xna80vy-python3.9-little-bits-of-buddha-0.1.0/bin:/nix/store/wmaqg26cza9vvck1wglp3xywsqabnp7n-python3.9-flask-2.0.2/bin'${PATH:+':'}$PATH
export PYTHONNOUSERSITE='true'
exec -a "$0" "/nix/store/3jiz0vgryj2si4bglz14wwak4xna80vy-python3.9-little-bits-of-buddha-0.1.0/bin/.lbob-wrapped"  "$@"
07:51:42
@k900:0upti.meK900 And now cat /nix/store/3jiz0vgryj2si4bglz14wwak4xna80vy-python3.9-little-bits-of-buddha-0.1.0/bin/.lbob-wrapped 07:52:26
@worldofgeese:one.ems.hostworldofgeese
bash-5.1# cat /nix/store/3jiz0vgryj2si4bglz14wwak4xna80vy-python3.9-little-bits-of-buddha-0.1.0/bin/.lbob-wrapped
#!/nix/store/i6vabb4div9iy6lsl642d86k1q8riasn-python3-3.9.9/bin/python3.9
# -*- coding: utf-8 -*-
import sys;import site;import functools;sys.argv[0] = '/nix/store/3jiz0vgryj2si4bglz14wwak4xna80vy-python3.9-little-bits-of-buddha-0.1.0/bin/lbob';functools.reduce(lambda k, p: site.addsitedir(p, k), ['/nix/store/3jiz0vgryj2si4bglz14wwak4xna80vy-python3.9-little-bits-of-buddha-0.1.0/lib/python3.9/site-packages','/nix/store/wmaqg26cza9vvck1wglp3xywsqabnp7n-python3.9-flask-2.0.2/lib/python3.9/site-packages','/nix/store/fn3hgaz6sfr3cpvmzd1lxl10rivs96wc-python3.9-jinja2-3.0.3/lib/python3.9/site-packages','/nix/store/j68i2axxrgn0wcqxfw4lyqqw94v9r889-python3.9-markupsafe-2.0.1/lib/python3.9/site-packages','/nix/store/lvcvbrk3qm14r7qziblnkgcxmx4wj8rb-python3.9-werkzeug-2.0.3/lib/python3.9/site-packages','/nix/store/1fg49005dvz6nl8xmz677zl3vd4pn5li-python3.9-click-8.0.3/lib/python3.9/site-packages','/nix/store/m6zvprr8r0972c1kc0hjsz3ix6qx7jxd-python3.9-itsdangerous-2.0.1/lib/python3.9/site-packages','/nix/store/jsf2dfbia2n1gwyh4m0kjwq51smdyxsp-python3.9-setuptools-57.2.0/lib/python3.9/site-packages'], site._init_pathinfo());
import re
import sys
from little_bits_of_buddha.app import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())
07:53:26
@k900:0upti.meK900That's weird07:53:45
@k900:0upti.meK900It's definitely there07:53:47
@worldofgeese:one.ems.hostworldofgeeseShould I file this as a bug?07:55:12
@k900:0upti.meK900I'm not sure where you would file this, honestly07:56:15
@k900:0upti.meK900Because it's probably not a poetry2nix bug07:56:21
@k900:0upti.meK900 It might be an importlib bug 07:56:26
@worldofgeese:one.ems.hostworldofgeese Isn't it odd it works as both a Nix derivation and with poetry run lbob but not inside a container? 07:57:26
@k900:0upti.meK900It is07:57:43

Show newer messages


Back to Room ListRoom Version: 6