Skip to content

Commit

Permalink
wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
zupo committed Oct 25, 2023
1 parent ba92ab6 commit ec12cb4
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 121 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
.direnv
result/
45 changes: 11 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM ubuntu:23.10
RUN apt-get update \
&& apt-get install git nix -y \
&& 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
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ endif
tesh:
@tesh *.md

.PHONY: examples
examples:
@tesh examples/

.PHONY: test
test: tests

Expand All @@ -79,4 +75,3 @@ tests:
@make types
@make unit
@make tesh
@make examples
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ We provide two development environments for people working on this project, one

For Nix, run `nix develop` to enter the development environment, where everything is ready for use.

For Docker, run `docker build && docker run && docker ssh` to enter the development environment, where everything is ready for use.
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.

Expand Down Expand Up @@ -324,8 +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 .
15 changes: 0 additions & 15 deletions examples/nix-shell.md

This file was deleted.

111 changes: 47 additions & 64 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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"
Expand All @@ -147,7 +130,7 @@
''));

devShells =
{default=self'.devShells.default-python311;}
{ default = self'.devShells.default-python311; }

//

Expand All @@ -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}"
'';

}));
}));
};
};
}

0 comments on commit ec12cb4

Please sign in to comment.