| 15 Feb 2022 |
K900 | That's what I did anyway | 12:37:03 |
asymmetric | yeah, i just don't like having the main package definition be "incomplete" | 12:39:16 |
asymmetric | anyway, thx! | 12:39:19 |
mou | In reply to @octavioduarte:matrix.org Off course! I didn't want to send the files without being asked to but if anybody can help that would be amazing. I finally got time to look into your issue.
TLDR; your project builds fine with latest version of poetry2nix.
Long answer: many errors comes from outside, from python ecosystem, you can read short explanation in document. Latest version of poetry2nix contain myriad of overrides for many packages which allow to successfully build you project. I do not know why nixpkgs does not update potry2nix. But you can check amount of overrides in this files https://github.com/nix-community/poetry2nix/tree/master/overrides .
To build your project i used flake with overlay over nixpkgs. I'm not experienced user of nix, but i believe you can use flake for poetry2nix with classic nix definitions.
Here is flake.nix i used
{
description = "test";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
inputs.poetry2nix.url = "github:nix-community/poetry2nix";
outputs = { self, nixpkgs, flake-utils, poetry2nix }:
{
# Nixpkgs overlay providing the application
overlay = nixpkgs.lib.composeManyExtensions [
poetry2nix.overlay
(final: prev: {
# The application
example = prev.poetry2nix.mkPoetryApplication {
projectDir = ./.;
};
})
];
} // (flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlay ];
};
in
rec {
defaultPackage = pkgs.example;
}));
}
| 19:41:08 |
| 16 Feb 2022 |
jyamad | I am trying to use poetry2nix via flakes, but I need to downgrade poetry due to https://github.com/python-poetry/poetry/issues/4523 . Does anyone have an example of a flake that overrides the poetry version that poetry2nix uses? | 07:14:42 |
jyamad | In reply to @jyamad:cofree.coffee I am trying to use poetry2nix via flakes, but I need to downgrade poetry due to https://github.com/python-poetry/poetry/issues/4523 . Does anyone have an example of a flake that overrides the poetry version that poetry2nix uses? It looks to me like I may be getting the right version of poetry by making an overlay, but that poetry2nix is maybe not using my overlay version of poetry. | 07:18:21 |
worldofgeese | I have a Poetry flake I can get to reliably build a Nix derivation. I've been banging my head the last two days trying to build a container image from it with dockerTools.streamLayeredImage. The data.json file I use as my "database" can't be found by the Python processing script but only inside the container. Here's the error:
$ docker run docker run -p 5000:5000 --rm -it localhost/lbob:6xwsg8ixlbpaisq1xc7ipvs5qxcs3d1m
* Serving Flask app 'little_bits_of_buddha.app' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://10.0.2.100:5000/ (Press CTRL+C to quit)
[2022-02-16 17:33:30,415] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "/nix/store/wmaqg26cza9vvck1wglp3xywsqabnp7n-python3.9-flask-2.0.2/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "/nix/store/wmaqg26cza9vvck1wglp3xywsqabnp7n-python3.9-flask-2.0.2/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/nix/store/wmaqg26cza9vvck1wglp3xywsqabnp7n-python3.9-flask-2.0.2/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/nix/store/wmaqg26cza9vvck1wglp3xywsqabnp7n-python3.9-flask-2.0.2/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/nix/store/yr8hjra5czylkiz1pkcsclbbc7pqbyh2-python3.9-little-bits-of-buddha-0.1.0/lib/python3.9/site-packages/little_bits_of_buddha/app.py", line 10, in random_sutta
return _random_sutta()
File "/nix/store/yr8hjra5czylkiz1pkcsclbbc7pqbyh2-python3.9-little-bits-of-buddha-0.1.0/lib/python3.9/site-packages/little_bits_of_buddha/data.py", line 8, in _random_sutta
with open("../data.json") as json_file:
FileNotFoundError: [Errno 2] No such file or directory: './data.json'
But the file is there:
ls /nix/store/yr8hjra5czylkiz1pkcsclbbc7pqbyh2-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
Am I doing something wrong?
| 20:22:43 |
K900 | You need to actually declare that the file should be installed | 20:23:56 |
K900 | It won't take the entire directory and drop it in site-packages | 20:24:12 |
K900 | And this is a Python thing, not really a Nix thing | 20:24:24 |
worldofgeese | In reply to @k900:0upti.me You need to actually declare that the file should be installed It is in site-packages, if you look at the second command I put | 20:26:00 |
K900 | Oh, I see | 20:26:44 |
K900 | Your path is wrong for two reasons | 20:26:52 |
K900 | 1) you're looking one folder above the current directory, when the file is in the same directory as your Python code | 20:27:12 |
K900 | And 2) open works relative to current working directory, not source file location | 20:27:35 |
K900 | The actually correct way to do this would be https://docs.python.org/3/library/importlib.html#module-importlib.resources | 20:29:08 |
worldofgeese | This is what I thought! But poetry run lbob actually wants the source directory path. Here's what I wrote in this commit explaining the choice:
Poetry has odd behavior around relative file paths. Python scripts must
import starting from the project (`little_bits_of_buddha`) even if they
occupy the same directory. This commit fixes file paths to operate from
"project in".
| 20:29:24 |
worldofgeese | Of course I admit my thinking could be wrong here but I couldn't argue with the results | 20:29:37 |
worldofgeese | As poetry run lbob and the Nix derivation both run successfully | 20:29:49 |
K900 | So you fixed issue #1, kind of | 20:31:13 |
K900 | But you still have issue #2 | 20:31:19 |
K900 | The easy way out would be to do something like pathlib.Path(__file__) / "../data.json" | 20:31:50 |
K900 | The correct way out would be to use importlib.resources | 20:32:05 |
worldofgeese | Interesting. Can you give me an example of how I would use importlib.resources in this case? | 20:32:40 |
K900 | Basically just from importlib import resources; resources.files("your_package_name").join("data.json").read_text() | 20:34:19 |
worldofgeese | From inside my data.py file right? It would replace the open() | 20:35:20 |
K900 | It would replace the whole thing | 20:35:52 |
worldofgeese | This is my first real Python project, sorry if my questions are very amateur | 20:36:03 |
K900 | You probably want to then pass the result to json.loads | 20:36:04 |
K900 | Also, you might want to move that out of the function | 20:36:43 |