| 16 Feb 2022 |
K900 | Because importlib will be slower than just reading the file off the disk | 20:37:00 |
K900 | Probably not by enough for it to mattrr | 20:37:10 |
K900 | * Probably not by enough for it to matter | 20:37:13 |
K900 | But it's generally good practice to load resources once and then keep them in memory | 20:37:26 |
K900 | Because 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 | 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 it into some form of life | 20:39:54 |
worldofgeese | * 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 life | 20:43:18 |
| asymmetric left the room. | 22:08:54 |
| 17 Feb 2022 |
worldofgeese | 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 | * 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 | Post the actual image config | 07:40:40 |
K900 | And check if the file is there in your container | 07:40:47 |
worldofgeese | Image config is here from line 23 | 07:41:43 |
worldofgeese | 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 | That is weird | 07:47:10 |
K900 | What is PYTHONPATH set to in lbob? | 07:47:15 |
worldofgeese | I haven't set it explicitly, should I use this StackOverflow answer to find out? | 07:49:07 |
worldofgeese | And inside or outside the container? | 07:49:23 |
K900 | Inside the container, just run cat $(which lbob) | 07:50:36 |
worldofgeese | 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 | And now cat /nix/store/3jiz0vgryj2si4bglz14wwak4xna80vy-python3.9-little-bits-of-buddha-0.1.0/bin/.lbob-wrapped | 07:52:26 |
worldofgeese | 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 | That's weird | 07:53:45 |
K900 | It's definitely there | 07:53:47 |
worldofgeese | Should I file this as a bug? | 07:55:12 |
K900 | I'm not sure where you would file this, honestly | 07:56:15 |
K900 | Because it's probably not a poetry2nix bug | 07:56:21 |
K900 | It might be an importlib bug | 07:56:26 |
worldofgeese | 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 | It is | 07:57:43 |