Skip to content

Commit a8b063f

Browse files
authored
chore: introduce minimal flake.nix (#336)
* feat: do not supress callback exceptions raised from calling callbacks * fix: add explicit clauses for ConnectionClosedOK in send and heartbeat * fix: change import order * fix: apply ruff format * feat: introduce flake.nix leveraging pyproject.nix introduce flake.nix configuration leveraging the already existing information in pyproject.toml, by using pyproject.nix to parse it and generate the correct derivation. this way, any updates to pyproject.toml should automatically be reflected in the flake configuration, with low additional maintaining overhead required. the only time when this may come as a problem is due to dependabot constantly upgrading the packages to versions that do not exist yet in nixpkgs. it may be required to force dependabot to also update the nixpkgs version declared in the flake for it to not also break (or at least to upgrade less often) * chore: make `flake.nix` aware of dev dependencies, including ruff and pre-commit by adding `dependency-groups`, `pyproject.nix` can now parse the dependency groups and add these to the project, by passing `groups = ["dev"]` when calling the renderer. special care was needed in order to expose `ruff` and `pre-commit` to the toplevel of the environment. by default, it will treat them as python dependencies and hide them in the python wrapper. by using `groupBy`, we split the dependency list in "python" dependencies and top level ones, such that they can be exposed. sadly, these toplevel packages are not exposed in `python.pkgs` so we must manually override them in a case by case basis. * chore: refactor `dependencies-for` * feat: add nix develop CI job ensure that `nix develop` works on CI * fix: change job name to be more compatible with the other actions * feat: setup infra and run `python -m pytest` to run tests in nix setup action do not rely on poetry to run tests, we'd like to not rely on it from within the nix environment * fix: do not rely on `npx` as its not on nix develop use manual `supabase start` command instead * fix: add `--command` typo * chore: change name of nix develop command part * feat: add coverage information and upload it to coveralls * chore: run nix setup tests in both ubuntu and macos * chore: undo macos latest as it apparently does not work for some reason, `supabase start` does not seem to work on `macos-latest` host in CI * chore: switch from pylsp + mypy to pyright (basepyright) it seems that pyright is better and faster than mypy in most if not all cases, and the only reason I wasn't using it before is because it was not working with eglot's default config. * feat: add `basedpyright` to `pyproject.toml` instead of flake.nix only this makes it available to all users, preparing for including it into the standard CI later on * fix: change back to python-lsp-server with pylsp-mypy
1 parent 146d649 commit a8b063f

File tree

5 files changed

+624
-73
lines changed

5 files changed

+624
-73
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,28 @@ jobs:
4343
flag-name: run-${{ join(matrix.*, '-') }}
4444
parallel: true
4545

46+
ensure_nix_setup_works:
47+
name: Test / OS ubuntu-latest / nix develop
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Install nix
51+
uses: cachix/install-nix-action@v31
52+
with:
53+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
54+
- name: Clone Repository
55+
uses: actions/checkout@v4
56+
- name: Start Supabase local development setup
57+
run: nix develop --command supabase start --workdir infra -x studio,mailpit,edge-runtime,logflare,vector,supavisor,imgproxy,storage-api
58+
- name: Run python tests through nix
59+
run: nix develop --command python -m pytest --cov=realtime --cov-report=xml --cov-report=html -vv
60+
- name: Upload coverage to Coveralls
61+
uses: coverallsapp/github-action@v2
62+
with:
63+
github-token: ${{ secrets.GITHUB_TOKEN }}
64+
flag-name: run-ubuntu-latest-nix-develop
65+
parallel: true
66+
67+
4668
finish_tests:
4769
needs: test
4870
name: Upload tests coveralls results

flake.lock

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
description = "realtime-py: a Realtime python client.";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
6+
pyproject-nix = {
7+
url = "github:pyproject-nix/pyproject.nix";
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
};
10+
};
11+
12+
outputs = { nixpkgs, pyproject-nix, ... }: let
13+
for-all-systems = f:
14+
nixpkgs.lib.genAttrs [
15+
"x86_64-linux"
16+
"aarch64-darwin"
17+
"aarch64-linux"
18+
"x86_64-darwin"
19+
] (system: f nixpkgs.legacyPackages.${system});
20+
project = pyproject-nix.lib.project.loadPyproject {
21+
projectRoot = ./.;
22+
};
23+
dev-tools = pkgs: [
24+
pkgs.supabase-cli
25+
];
26+
dependencies-for = pkgs: let
27+
# override to add top-level packages in nixpkgs as
28+
# python3.pkgs packages, so that the renderers can find them
29+
python = pkgs.python3.override {
30+
packageOverrides = self: super: {
31+
ruff = self.toPythonModule pkgs.ruff;
32+
pre-commit = self.toPythonModule pkgs.pre-commit;
33+
basedpyright = self.toPythonModule pkgs.basedpyright;
34+
};
35+
};
36+
all-dependencies = project.renderers.withPackages {
37+
inherit python;
38+
groups = [ "dev" ];
39+
};
40+
dependencies = builtins.groupBy (pkg: if python.pkgs.hasPythonModule pkg then "python" else "toplevel") (all-dependencies python);
41+
in {
42+
python-env = python.buildEnv.override {
43+
extraLibs = dependencies.python or [];
44+
};
45+
toplevel = dependencies.toplevel or [];
46+
};
47+
in {
48+
devShells = for-all-systems (pkgs: let
49+
inherit (dependencies-for pkgs) python-env toplevel;
50+
in {
51+
default = pkgs.mkShell {
52+
packages = [ python-env ] ++ (dev-tools pkgs) ++ toplevel;
53+
};
54+
});
55+
};
56+
}

0 commit comments

Comments
 (0)