From 9dad93eaeb30d981fe1a5fbc3b5a7fce49d566a5 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Mon, 14 Oct 2024 11:13:18 +0800 Subject: [PATCH 1/4] Problem: ci test dependency install fail Solution: - switch to nix --- .github/workflows/test.yml | 6 +- flake.nix | 62 ++++++++++++------- .../tests/test_expansion/test_expansion.py | 6 +- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 11ff65b..15d0f38 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,12 +20,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: install dependencies - run: python3 -m pip install --user --upgrade poetry - - name: install - run: poetry install - name: Run tests - run: make test + run: nix develop -c python -mpytest nix-flake: runs-on: ubuntu-latest steps: diff --git a/flake.nix b/flake.nix index 86a3693..9b42444 100644 --- a/flake.nix +++ b/flake.nix @@ -8,17 +8,27 @@ inputs.flake-utils.follows = "flake-utils"; }; }; - outputs = { self, nixpkgs, flake-utils, poetry2nix }: - (flake-utils.lib.eachDefaultSystem (system: + outputs = + { + self, + nixpkgs, + flake-utils, + poetry2nix, + }: + (flake-utils.lib.eachDefaultSystem ( + system: let - pkgs = (import nixpkgs { - inherit system; - config = { }; - overlays = [ - poetry2nix.overlays.default - ]; - }); - overrides = pkgs.poetry2nix.overrides.withDefaults (self: super: + pkgs = ( + import nixpkgs { + inherit system; + config = { }; + overlays = [ + poetry2nix.overlays.default + ]; + } + ); + overrides = pkgs.poetry2nix.overrides.withDefaults ( + self: super: let buildSystems = { durations = [ "setuptools" ]; @@ -26,23 +36,25 @@ pytest-github-actions-annotate-failures = [ "setuptools" ]; flake8-black = [ "setuptools" ]; flake8-isort = [ "hatchling" ]; - docker = [ "hatchling" "hatch-vcs" ]; + docker = [ + "hatchling" + "hatch-vcs" + ]; }; in - pkgs.lib.mapAttrs - (attr: systems: super.${attr}.overridePythonAttrs - (old: { - nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ map (a: self.${a}) systems; - })) - buildSystems + pkgs.lib.mapAttrs ( + attr: systems: + super.${attr}.overridePythonAttrs (old: { + nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ map (a: self.${a}) systems; + }) + ) buildSystems ); in rec { - packages.default = pkgs.poetry2nix.mkPoetryApplication - { - projectDir = ./.; - inherit overrides; - }; + packages.default = pkgs.poetry2nix.mkPoetryApplication { + projectDir = ./.; + inherit overrides; + }; apps.default = { type = "app"; program = "${packages.default}/bin/pystarport"; @@ -53,6 +65,12 @@ projectDir = ./.; inherit overrides; }) + (pkgs.poetry2nix.mkPoetryEditablePackage { + projectDir = ./.; + editablePackageSources = { + pystarport = ./pystarport; + }; + }) ]; }; } diff --git a/pystarport/tests/test_expansion/test_expansion.py b/pystarport/tests/test_expansion/test_expansion.py index 0abd2aa..93b8398 100644 --- a/pystarport/tests/test_expansion/test_expansion.py +++ b/pystarport/tests/test_expansion/test_expansion.py @@ -53,8 +53,10 @@ def test_expansion(type, func): } } + path = Path(__file__).parent + # overriding dotenv with absolute path is expanded and has diff - dotenv = os.path.abspath("test_expansion/dotenv1") + dotenv = os.path.abspath(path / "dotenv1") config = func(cronos_has_dotenv, dotenv) assert DeepDiff( base_config, @@ -72,7 +74,7 @@ def test_expansion(type, func): } # overriding dotenv with absolute path is expanded and no diff - dotenv = os.path.abspath("test_expansion/dotenv") + dotenv = os.path.abspath(path / "dotenv") config = func(cronos_has_posix_no_dotenv, dotenv) assert not DeepDiff( base_config, From 86d125d778ef690a9e7222d7a3adbf4943b9cd97 Mon Sep 17 00:00:00 2001 From: yihuang Date: Mon, 14 Oct 2024 11:19:09 +0800 Subject: [PATCH 2/4] Update .github/workflows/test.yml Signed-off-by: yihuang --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15d0f38..a8711d1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Run tests - run: nix develop -c python -mpytest + run: nix develop -c python -mpytest -vv -s nix-flake: runs-on: ubuntu-latest steps: From d41fad6b48bbe0acb5d01c568a13b9eb284a99ef Mon Sep 17 00:00:00 2001 From: HuangYi Date: Mon, 14 Oct 2024 11:23:09 +0800 Subject: [PATCH 3/4] fix workflow --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a8711d1..4e1139a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: cachix/install-nix-action@v15 - name: Run tests run: nix develop -c python -mpytest -vv -s nix-flake: From ce4557347cec6112e26db254264d487f84c8b67e Mon Sep 17 00:00:00 2001 From: HuangYi Date: Mon, 14 Oct 2024 11:27:03 +0800 Subject: [PATCH 4/4] add magic cache --- .github/workflows/test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4e1139a..20a4aac 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,14 +13,16 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: cachix/install-nix-action@v15 + - uses: cachix/install-nix-action@v30 + - uses: DeterminateSystems/magic-nix-cache-action@main - name: Run linting run: nix develop -c make lint-ci tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: cachix/install-nix-action@v15 + - uses: cachix/install-nix-action@v30 + - uses: DeterminateSystems/magic-nix-cache-action@main - name: Run tests run: nix develop -c python -mpytest -vv -s nix-flake: