add fastapi
This commit is contained in:
commit
585caaf327
18
basic_test.py
Normal file
18
basic_test.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import os
|
||||
from pytest import mark
|
||||
|
||||
def test_one():
|
||||
assert 2 + 2 == 4
|
||||
|
||||
def test_nonstandard_module():
|
||||
import numpy as np
|
||||
assert np.linspace(1,2).shape == (50,)
|
||||
|
||||
@mark.skipif(os.getenv('GITHUB_ACTIONS') != 'true',
|
||||
reason = 'Not running on GHA')
|
||||
def test_version():
|
||||
import sys
|
||||
vi = sys.version_info
|
||||
found = f'python{vi.major}{vi.minor}'
|
||||
expected = os.getenv('EXPECTED_PY')
|
||||
assert(found == expected)
|
60
flake.lock
Normal file
60
flake.lock
Normal file
|
@ -0,0 +1,60 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1641205782,
|
||||
"narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1642700792,
|
||||
"narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "846b2ae0fc4cc943637d3d1def4454213e203cba",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1655200170,
|
||||
"narHash": "sha256-/yzkX+10sJhYNIcTtZ5ObS+nh/HrJp01XLaubzbRDcU=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "9ff91ce2e4c5d70551d4c8fd8830931c6c6b26b8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-22.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat",
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
86
flake.nix
Normal file
86
flake.nix
Normal file
|
@ -0,0 +1,86 @@
|
|||
# The core functionality is provided here using flakes. Legacy support for
|
||||
# `nix-shell` is provided by a wrapper in `shell.nix`.
|
||||
|
||||
# TODO Hacking around the Qt problems
|
||||
# TODO PyPI package not in nixpkgs
|
||||
|
||||
|
||||
{
|
||||
description = "Python development environment";
|
||||
|
||||
inputs = {
|
||||
|
||||
# Version pinning is managed in flake.lock. Upgrading can be done with
|
||||
# something like
|
||||
#
|
||||
# nix flake lock --update-input nixpkgs
|
||||
|
||||
nixpkgs .url = "github:nixos/nixpkgs/nixos-22.05";
|
||||
flake-utils .url = "github:numtide/flake-utils";
|
||||
flake-compat = {
|
||||
url = "github:edolstra/flake-compat";
|
||||
flake = false;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, ... }:
|
||||
|
||||
# Option 1: try to support each default system
|
||||
flake-utils.lib.eachDefaultSystem # NB Some packages in nixpkgs are not supported on some systems
|
||||
|
||||
# Option 2: try to support selected systems
|
||||
# flake-utils.lib.eachSystem ["x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin"]
|
||||
(system:
|
||||
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
# Any overlays you need can go here
|
||||
overlays = [ ];
|
||||
};
|
||||
|
||||
# ----- A Python interpreter with the packages that interest us -------
|
||||
python-with-all-my-packages = (python:
|
||||
(python.withPackages (ps: [
|
||||
ps.pytest
|
||||
ps.fastapi
|
||||
])));
|
||||
|
||||
in
|
||||
rec {
|
||||
|
||||
#devShell = self.devShells.${ system }.python310; # does not need `rec`
|
||||
devShell = devShells.python310;
|
||||
|
||||
devShells =
|
||||
builtins.listToAttrs (
|
||||
builtins.map
|
||||
(
|
||||
pythonVersion: {
|
||||
name = pythonVersion;
|
||||
value = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
(python-with-all-my-packages pkgs.${ pythonVersion })
|
||||
pkgs.just
|
||||
pkgs.cowsay
|
||||
];
|
||||
packages = [
|
||||
pkgs.python3Packages.python-lsp-server
|
||||
pkgs.lolcat
|
||||
pkgs.exa
|
||||
];
|
||||
shellHook =
|
||||
''
|
||||
export PS1="${pythonVersion} devshell> "
|
||||
alias foo='cowsay Foo'
|
||||
alias bar='exa -l | lolcat'
|
||||
alias baz='cowsay What is the difference between buildIntputs and packages? | lolcat'
|
||||
'';
|
||||
};
|
||||
}
|
||||
) [ "python37" "python38" "python39" "python310" ]
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
4
justfile
Normal file
4
justfile
Normal file
|
@ -0,0 +1,4 @@
|
|||
# -*-Makefile-*-
|
||||
|
||||
test colours='':
|
||||
pytest -v {{colours}}
|
15
shell.nix
Normal file
15
shell.nix
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Adapts flake.nix to support legacy `nix-shell`
|
||||
|
||||
(import
|
||||
(
|
||||
let
|
||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||
in
|
||||
fetchTarball {
|
||||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||
}
|
||||
)
|
||||
{
|
||||
src = ./.;
|
||||
}).shellNix
|
Loading…
Reference in a new issue