diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e6eacbd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +.direnv +result/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83d583a..10e978f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,52 +46,29 @@ jobs: env: PYTHON: ${{ matrix.python }} run: | + nix build .#checks.x86_64-linux.pre-commit + nix build .#devShells.x86_64-linux.default-$(echo $PYTHON) + nix build .#packages.x86_64-linux.default-$(echo $PYTHON) nix build .#checks.x86_64-linux.tests-$(echo $PYTHON) - nix build .#packages.x86_64-linux.impure-check-$(echo $PYTHON) impure_tests: name: Impure Tests - strategy: - matrix: - python-version: ["3.9", "3.10", "3.11"] - runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Install Poetry - uses: snok/install-poetry@v1 - + - name: Build Docker image with nix env for tesh development + run: docker build -t tesh . - - name: Install Poetry environment - env: - PYTHON: python${{ matrix.python-version }} - run: | - poetry env use $PYTHON - poetry install - - - name: Install test dependencies - run: sudo apt-get -y install nmap + - name: Start a container + run: docker run -d --rm -v .:/tesh --name tesh -it tesh - - name: Run linters and unit tests the Poetry way - run: | - # make lint -> pre-commit-config.yaml is managed by Nix, - # so path entries won't work in Poetry env - source $(poetry env info --path)/bin/activate - make types - make unit - make tesh - - - uses: cachix/install-nix-action@v22 + - name: Make git happy so that pre-commit checks in `make lint` work + run: docker exec tesh git config --global --add safe.directory /tesh - - name: Run 'make examples' - run: poetry run tesh examples/ + - name: Run all tests + run: docker exec tesh nix develop -c make tests release: name: Release diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e57f127 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:23.10 +RUN apt-get update \ + && apt-get install nano git nix -y \ + && echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf \ + && echo "max-jobs = 4" >> /etc/nix/nix.conf +COPY ./. /tesh +RUN nix develop /tesh -c true +WORKDIR /tesh +CMD nix develop diff --git a/Makefile b/Makefile index bdb4580..7bd891e 100644 --- a/Makefile +++ b/Makefile @@ -66,10 +66,6 @@ endif tesh: @tesh *.md -.PHONY: examples -examples: - @tesh examples/ - .PHONY: test test: tests @@ -79,4 +75,3 @@ tests: @make types @make unit @make tesh - @make examples diff --git a/README.md b/README.md index 4ffd02d..79d06b0 100644 --- a/README.md +++ b/README.md @@ -275,13 +275,11 @@ $ pip install tesh ## Developing `tesh` -We provide two development environments for people working on this project, one based on [Nix](https://nixos.org/) and one based on [Poetry](https://www.docker.com/). +We provide two development environments for people working on this project, one based on [Nix](https://nixos.org/) and one based on [Docker](https://www.docker.com/). For Nix, run `nix develop` to enter the development environment, where everything is ready for use. -For Poetry, run the following: -* `poetry install` to prepare the Python development environment -* `pre-commit install --config .pre-commit-config.impure.yaml` +For Docker, run `docker build -t tesh . && docker run --rm -v .:/tesh -it tesh` to enter the development environment, where everything is ready for use. Then you can run `make tests` to run all tests & checks. @@ -326,4 +324,9 @@ $ nix develop .#devShells.aarch64-darwin.default-python39 # TODO: +* rename packages, so they are not default-python310, etc. * docker image +* commands instead of docker actions + + +* docker build . diff --git a/examples/nix-shell.md b/examples/nix-shell.md deleted file mode 100644 index 6521494..0000000 --- a/examples/nix-shell.md +++ /dev/null @@ -1,15 +0,0 @@ -# `nix-shell` example - -```console tesh-session="nix-shell" tesh-ps1="[nix-shell:~]$" tesh-timeout="60" -$ echo $IN_NIX_SHELL -$ export NIX_PATH=nixpkgs=https://github.com/nixos/nixpkgs/archive/c7a18f89ef1dc423f57f3de9bd5d9355550a5d15.tar.gz -$ nix-shell -p hello -... -[nix-shell:~]$ echo $IN_NIX_SHELL -impure -[nix-shell:~]$ which hello -/nix/store/...-hello-.../bin/hello -[nix-shell:~]$ exit -exit -$ -``` diff --git a/flake.nix b/flake.nix index a0d4364..a61a69b 100644 --- a/flake.nix +++ b/flake.nix @@ -20,7 +20,7 @@ imports = [ inputs.pre-commit-hooks-nix.flakeModule ]; - systems = [ "x86_64-linux" "aarch64-darwin" ]; + systems = [ "x86_64-linux" "aarch64-darwin" "aarch64-linux" ]; perSystem = { config, self', inputs', pkgs, system, lib, ... }: let @@ -36,6 +36,21 @@ (python: f python); in lib.mapAttrs' (py: value: { name = "${name}-${py}"; inherit value; }) outputs; + + poetryArgs = python: { + projectDir = ./.; + preferWheels = true; + python = pkgs.${python}; + overrides = inputs'.poetry2nix.legacyPackages.overrides.withDefaults (self: super: { + + ruamel-yaml-clib = super.ruamel-yaml-clib.override ( + old: { + preferWheel = false; + } + ); + }); + }; + in { # Per-system attributes can be defined here. The self' and inputs' @@ -89,47 +104,15 @@ packages = (forAllPythons "default" (python: - inputs.poetry2nix.legacyPackages.${system}.mkPoetryApplication { - projectDir = ./.; - preferWheels = true; - python = pkgs.${python}; - })) + inputs.poetry2nix.legacyPackages.${system}.mkPoetryApplication (poetryArgs python))) // (forAllPythons "testEnv" (python: - inputs.poetry2nix.legacyPackages.${system}.mkPoetryEnv { - projectDir = ./.; - preferWheels = true; - python = pkgs.${python}; - })) + inputs.poetry2nix.legacyPackages.${system}.mkPoetryEnv (poetryArgs python))); - // - - (forAllPythons "impure-check" (python: - pkgs.writeScriptBin "impure-check" '' - # run the impure-check in a temp dir that gets nuked - # if this script fails in any way - export TMPDIR=$(${pkgs.coreutils}/bin/mktemp -d) - trap "${pkgs.coreutils}/bin/chmod -R +w '$TMPDIR'; ${pkgs.coreutils}/bin/rm -rf '$TMPDIR'" EXIT - - export PATH="${lib.makeBinPath [ - pkgs.coreutils - pkgs.gnumake - pkgs.bash - pkgs.nix - pkgs.which - self'.packages."default-${python}" - ]}" - - cd $TMPDIR - cp -r ${./.}/* ./ - make examples - '' - )); - - # 'make lint' not needed since pre-commit is run by pre-commit flake-part - # 'make examples' is an impure test so it's done in `impure-check` + # `make unit` is not needed as it's already run in pre-commit + # check, registered by flake-parts checks = (forAllPythons "tests" (python: pkgs.runCommand "tests" @@ -147,7 +130,7 @@ '')); devShells = - {default=self'.devShells.default-python311;} + { default = self'.devShells.default-python311; } // @@ -157,41 +140,41 @@ in pkgs.mkShell - { - name = "dev-shell"; + { + name = "dev-shell"; - buildInputs = with pkgs; [ - poetry - self'.packages."testEnv-${python}" + buildInputs = with pkgs; [ + poetry + self'.packages."testEnv-${python}" - # test dependency - nmap - ]; + # test dependency + nmap + ]; - inputsFrom = [ config.pre-commit.devShell ]; + inputsFrom = [ config.pre-commit.devShell ]; - shellHook = '' - tmp_path=$(realpath ./.direnv) + shellHook = '' + tmp_path=$(realpath ./.direnv) - source=$(realpath .) - mkdir -p "$tmp_path/python/${testEnv.sitePackages}" + source=$(realpath .) + mkdir -p "$tmp_path/python/${testEnv.sitePackages}" - # Install the package in editable mode - # This allows executing `clan` from within the dev-shell using the current - # version of the code and its dependencies. - PYTHONPATH=${pkgs."python${lib.replaceStrings ["python"] [""] python}Packages".poetry-core}/${testEnv.sitePackages}:${testEnv}/${testEnv.sitePackages} ${pkgs."python${lib.replaceStrings ["python"] [""] python}Packages".pip}/bin/pip install \ - --no-deps \ - --disable-pip-version-check \ - --no-index \ - --no-build-isolation \ - --prefix "$tmp_path/python" \ - --editable $source + # Install the package in editable mode + # This allows executing `clan` from within the dev-shell using the current + # version of the code and its dependencies. + PYTHONPATH=${pkgs."python${lib.replaceStrings ["python"] [""] python}Packages".poetry-core}/${testEnv.sitePackages}:${testEnv}/${testEnv.sitePackages} ${pkgs."python${lib.replaceStrings ["python"] [""] python}Packages".pip}/bin/pip install \ + --no-deps \ + --disable-pip-version-check \ + --no-index \ + --no-build-isolation \ + --prefix "$tmp_path/python" \ + --editable $source - export PATH="$tmp_path/python/bin:$PATH" - export PYTHONPATH="$source/src:$tmp_path/python/${testEnv.sitePackages}:${testEnv}/${testEnv.sitePackages}" - ''; + export PATH="$tmp_path/python/bin:$PATH" + export PYTHONPATH="$source/src:$tmp_path/python/${testEnv.sitePackages}:${testEnv}/${testEnv.sitePackages}" + ''; - })); + })); }; }; }