10 Jun 2024 |
| jameswarren (James Warren) joined the room. | 16:23:16 |
jameswarren (James Warren) | Hello all - I have a question about editable packages. I'll try to keep it brief but can expand as needed.
We're looking into using nix and poetry to manage a python monorepo. For a client project to depend on a local utils library, we have this dependency in the utils pyproject.toml:
[tool.poetry.dependencies]
python = "^3.11"
utils = { path = "../utils/", develop = true }
| 16:40:21 |
jameswarren (James Warren) | We'd also like to have utils as an editable installation in the nix development shell for client . I was able to accomplish this by redundantly stating this by using mkPoetryEditablePackage :
devShells = {
explicit = pkgs.mkShell {
buildInputs = [
(mkPoetryEditablePackage {
projectDir = ./.;
editablePackageSources = {
utils = ../utils;
};
})
];
};
};
| 16:42:34 |
jameswarren (James Warren) | * We'd also like to have utils as an editable installation in the nix development shell for client . I was able to accomplish this by redundantly stating this by using mkPoetryEditablePackage in the clients flake.nix:
devShells = {
explicit = pkgs.mkShell {
buildInputs = [
(mkPoetryEditablePackage {
projectDir = ./.;
editablePackageSources = {
utils = ../utils;
};
})
];
};
};
| 16:42:58 |
jameswarren (James Warren) | However, this seems messy and error-prone to declare the same intention in multiple places. Reading the docs for mkPoetryEnv, the comment on editablePackageSources suggests that declaring develop = true in the pyproject.toml should install utils as editable, but empirically testing it does not. Am I misunderstanding how it should be used? | 16:45:43 |
jameswarren (James Warren) | * We'd also like to have utils as an editable installation in the nix development shell for client . I was able to accomplish this by redundantly stating this intention using mkPoetryEditablePackage in the clients flake.nix:
devShells = {
explicit = pkgs.mkShell {
buildInputs = [
(mkPoetryEditablePackage {
projectDir = ./.;
editablePackageSources = {
utils = ../utils;
};
})
];
};
};
| 16:51:02 |
11 Jun 2024 |
TyberiusPrime (smilodon inopinatus) | Hey, I'm trying to specifiy a dependency via {url =...} in my pyproject.toml, but I keep getting a hash mismatched on the downloaded file. Can somebody have a look at my minimal example here: https://github.com/TyberiusPrime/poetry_url_bug_maybe and tell me what's going on? | 08:00:28 |
TyberiusPrime (smilodon inopinatus) | where's that specified hash even coming from... | 08:00:34 |
TyberiusPrime (smilodon inopinatus) | (ok, changing the hash that's in poetry.lock does change the specified hash...) | 08:02:57 |
TyberiusPrime (smilodon inopinatus) | seems it's the to_base32(to_sri(poetry.lock-hash that starts with sha256)) | 08:03:26 |
TyberiusPrime (smilodon inopinatus) | it's gone away... maybe it was just a pypi fluke... | 08:09:05 |
TyberiusPrime (smilodon inopinatus) | or maybe not. hm. | 08:10:29 |
TyberiusPrime (smilodon inopinatus) | I think it's a bug. poetry2nix appears to be using the 'fetchzip' unpacked&recursive hash, while poetry specifies the hash of the tar.gz - https://github.com/nix-community/poetry2nix/issues/1695 | 08:29:33 |
| Óli joined the room. | 12:22:36 |
Óli | In reply to @jameswarren-582a7124d73408ce4f35e991:gitter.im However, this seems messy and error-prone to declare the same intention in multiple places. Reading the docs for mkPoetryEnv, the comment on editablePackageSources suggests that declaring develop = true in the pyproject.toml should install utils as editable, but empirically testing it does not. Am I misunderstanding how it should be used? I'm having similar issues. Are you using a flake for your project? | 16:30:51 |
12 Jun 2024 |
jameswarren (James Warren) | Yes I am. Looking at the source code, it looks somewhat understandable - I was planning on spending more time pondering it to either understand how it's to be used or how I could modify it. It's not my most pressing problem at the moment, though. 🤷 | 03:53:45 |
13 Jun 2024 |
| ixxie joined the room. | 08:18:15 |
ixxie | Hey folks, I'm new to poetry2nix and trying to get my first flake going for a python backend in a monorepo.
The flake quickstart example has a default app output as follows:
apps.${system}.default = {
type = "app";
program = "${myapp}/bin/some_script";
};
But I would like to output multiple scripts as different commands. How would I go about it? I thought I could just do apps.${system}.command_name but it complains:
error: flake 'git+file:///home/ixxie/myapp?dir=backend' does not provide attribute 'packages.x86_64-linux.default' or 'defaultPackage.x86_64-linux
| 08:20:09 |
ixxie | ah right, need to run it as an app, not build it | 08:37:21 |
ixxie | I'm not sure what to make of this... here is the flake for the backend (it's in ${monorepo}/backend ):
{
description = "MyApp Backend - Python, Uvicorn & FastAPI";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
poetry2nix.url = "github:nix-community/poetry2nix";
};
outputs = { self, nixpkgs, poetry2nix }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
# create a custom "mkPoetryApplication" API function that under the hood uses
# the packages and versions (python3, poetry etc.) from our pinned nixpkgs above:
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication;
myapp = mkPoetryApplication { projectDir = ./.; };
in
{
apps.${system}.backend = {
type = "app";
program = "${myapp}/bin/backend";
};
};
}
But I get the following error:
warning: Git tree '/home/ixxie/myapp' is dirty
error:
… while calling a functor (an attribute set with a '__functor' attribute)
at /nix/store/lpqygnph8c5l7ajkmqr4rff0pvkfz1f6-source/default.nix:407:13:
406|
407| app = py.pkgs.buildPythonPackage (
| ^
408| passedAttrs // inputAttrs // {
… while evaluating a branch condition
at /nix/store/dydg48djlykksz8cxq0xjplyxpa9pvf4-source/pkgs/development/interpreters/python/python-packages-base.nix:28:7:
27| in
28| if builtins.isAttrs result then result
| ^
29| else if builtins.isFunction result then {
(stack trace truncated; use '--show-trace' to show the full, detailed trace)
error: expected a set but found null: null
| 08:44:08 |
ixxie | How do I control the name of the package created with mkPoetryApplication and installed with nix profile install ? | 11:29:47 |
TyberiusPrime (smilodon inopinatus) | In reply to @ixxie:matrix.org How do I control the name of the package created with mkPoetryApplication and installed with nix profile install ? I thought it was taken from pyproject.toml? the source indicate that this is true | 12:08:17 |
TyberiusPrime (smilodon inopinatus) | adisbladis: Hi, are you still working on poetry2nix? | 12:09:01 |
TyberiusPrime (smilodon inopinatus) | ixxie: I think you just call mkPoetryApplication and then they're all in ./results/bin | 12:09:58 |
ixxie | In reply to @tyberius_prime:matrix.org I thought it was taken from pyproject.toml? the source indicate that this is true I've set the name in pyproject.toml , and set pname in mkPoetryApplication but when I run nix profile install .#package-name but then I still get something like this:
> nix profile list
Name: path/from/git/root/to/flake
Flake attribute: packages.x86_64-linux.default
Original flake URL: git+file:///home/ixxie/project?dir=path/from/git/root/to/flake
Locked flake URL: git+file:///home/ixxie/project?dir=path/from/git/root/to/flake
Store paths: /nix/store/4r112qhr7f3vsxj3jx4ynvyb8560vjxf-python3.11-cli-0.1
| 12:15:12 |
ixxie | I mean it installs well, I'm just wondering why the name is like this | 12:16:43 |
TyberiusPrime (smilodon inopinatus) | well, the name (pname + version) ends up in the store path, which I giuess is where the python3.11-cli comes from (cli being set in your pyproject.toml).
I suppose you want to change 'Name:'? | 12:16:49 |
ixxie | In reply to @tyberius_prime:matrix.org well, the name (pname + version) ends up in the store path, which I giuess is where the python3.11-cli comes from (cli being set in your pyproject.toml).
I suppose you want to change 'Name:'? yep, because that would be how I refer to it when managing it with nix profile | 12:17:18 |
TyberiusPrime (smilodon inopinatus) | (I don't use nix profile, so I can't comment on where it's getting the name from.) | 12:17:30 |
TyberiusPrime (smilodon inopinatus) | I mean you can change the flake attribute easily enough, so 'flake attribute' is something you could change, at the price of having to do nix profile install /path/to/flake#name | 12:18:41 |