Skip to content

Commit

Permalink
Merge pull request #2752 from IntersectMBO/remove_poetry2nix
Browse files Browse the repository at this point in the history
Remove poetry2nix
  • Loading branch information
mkoura authored Nov 12, 2024
2 parents 5ee1f82 + 6395b9c commit 2233f47
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 275 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Sometimes it is useful to run individual tests and keep the local cluster runnin

```sh
nix flake update --accept-flake-config --override-input cardano-node "github:IntersectMBO/cardano-node/master" # change `master` to rev you want
nix develop --accept-flake-config .#venv
nix develop --accept-flake-config
```

1. prepare testing environment
Expand Down
193 changes: 1 addition & 192 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 4 additions & 82 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,92 +9,21 @@
membench.follows = "/";
};
};
poetry2nix = {
inputs.nixpkgs.follows = "nixpkgs";
};
poetry2nix-old = {
# pin poetry2nix to 2023.10.05.49422, sometime after
# there is a change in the boostrap packages that expects
# wheel to take a flint-core argument, but it doesn't. It
# doesn't with the nixpkgs reference from cardano-node.
# Hence we need to make sure we pin it to an old enough
# version to work with our nixpkgs ref from cardano-node.
url = "github:nix-community/poetry2nix?ref=2023.10.05.49422";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.follows = "cardano-node/nixpkgs";
flake-utils = {
url = "github:numtide/flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils, cardano-node, poetry2nix, poetry2nix-old }:
outputs = { self, nixpkgs, flake-utils, cardano-node }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};

# As we are using [poetry](https://python-poetry.org) as the python dependency manager for cardano-node-tests, we will be using
# [poetry2nix](https://github.com/nix-community/poetry2nix) to convert the poetry project (pyproject.toml,
# and poetry.lock) into a nix-buildable expression. This is preferable over using `pkgs.python3.withPackages`
# as it adheres to the poetry setup instead of replicating it in nix again.
p2n-for-nixpkgs =
# if we are using an old nixpkgs (<23.11) then pin poetry2nix to
# 2023.10.05.49422, sometime after there is a change in the boostrap
# packages that expects wheel to take a flit-core argument, but it
# doesn't. It doesn't with the nixpkgs reference from cardano-node.
# Hence we need to make sure we pin it to an old enough version to
# work with our nixpkgs ref from cardano-node.

# see https://github.com/NixOS/nixpkgs/commit/3cd71e0ae67cc48f1135e55bf78cb0d67b53ff86
# for why we do this check.
if pkgs.lib.versionAtLeast pkgs.python3Packages.wheel.version "0.41.1"
then (__trace "using NEW poetry2nix" poetry2nix)
else (__trace "using OLD poetry2nix" poetry2nix-old);
p2n = (import p2n-for-nixpkgs { inherit pkgs; });

# base config of poetry2nix for our local project:
p2nConfig = {
projectDir = self;
# We use sdist by default for faster build. Also avoid having to manually inject dependencies on build-tools:
preferWheels = true;
# Because we transitively depend on `py`, (through `pytest-html`), we need to drop the module from `pytest`:
overrides = p2n.overrides.withDefaults (self: super: {
# we remove py.py shim fallback in pytest, which might accidentally take precedence over actual py lib
# due to the multiple site-packages in $PYTHONPATH generated by nix:
pytest = (super.pytest.override {
# Build from source so that we can patch:
preferWheel = false;
}).overridePythonAttrs (
old: {
postPatch = old.postPatch or "" + ''
rm src/py.py
'';
}
);
});
};

# Packaging of [tool.poetry.scripts] as applications:
cardano-nodes-tests-apps = p2n.mkPoetryApplication p2nConfig;

# All python dependencies of our local project:
cardano-nodes-tests-env = p2n.mkPoetryEnv (p2nConfig // {
groups = [ "dev" "docs" ];
});

in
{
packages = {
inherit cardano-nodes-tests-apps;
default = cardano-nodes-tests-apps;
};
devShells = rec {
dev = pkgs.mkShell {
# for local python dev:
nativeBuildInputs = with pkgs; [ poetry cardano-nodes-tests-env ];
};
base = pkgs.mkShell {
nativeBuildInputs = with pkgs; [ bash coreutils curl git gnugrep gnumake gnutar jq python3Packages.supervisor xz ];
};
Expand All @@ -114,16 +43,9 @@
pkgs.python3Packages.virtualenv
];
});
default = (
cardano-node.devShells.${system}.devops
).overrideAttrs (oldAttrs: rec {
nativeBuildInputs = base.nativeBuildInputs ++ postgres.nativeBuildInputs ++ oldAttrs.nativeBuildInputs ++ [
cardano-node.packages.${system}.cardano-submit-api
cardano-nodes-tests-apps
# TODO: can be removed once tests scripts do not rely on cardano-nodes-tests-apps dependencies:
cardano-nodes-tests-apps.dependencyEnv
];
});
# Use 'venv' directly as 'default' and 'dev'
default = venv;
dev = venv;
};
});

Expand Down

0 comments on commit 2233f47

Please sign in to comment.