add python lsp

This commit is contained in:
Malte Tammena 2024-04-25 12:23:30 +02:00
parent 78b37317d2
commit b94555e703
2 changed files with 145 additions and 137 deletions

9
.helix/languages.toml Normal file
View file

@ -0,0 +1,9 @@
[[language]]
name = "python"
language-servers = [ "pyright", "ruff" ]
[language-server.ruff]
command = "ruff-lsp"
[language-server.ruff.config.settings]
args = ["--ignore", "E501"]

273
flake.nix
View file

@ -30,18 +30,17 @@
}; };
}; };
outputs = outputs = inputs @ {
inputs @ { self self,
, nixpkgs nixpkgs,
, flake-parts flake-parts,
, crane crane,
, fenix fenix,
, flake-utils flake-utils,
, advisory-db advisory-db,
, rust-overlay rust-overlay,
, }:
}: flake-parts.lib.mkFlake {inherit inputs self;} {
flake-parts.lib.mkFlake { inherit inputs self; } {
imports = [ imports = [
]; ];
@ -53,160 +52,160 @@
flake.hydraJobs.devShells.x86_64-linux = self.devShells.x86_64-linux; flake.hydraJobs.devShells.x86_64-linux = self.devShells.x86_64-linux;
flake.hydraJobs.checks.x86_64-linux = self.checks.x86_64-linux; flake.hydraJobs.checks.x86_64-linux = self.checks.x86_64-linux;
perSystem = perSystem = {
{ self' self',
, pkgs pkgs,
, lib lib,
, config config,
, system system,
, ... ...
}: }: let
let # Load toolchain from file and extend with rust-src and rust-analyzer + clippy
# Load toolchain from file and extend with rust-src and rust-analyzer + clippy rustToolchain = (pkgs.rust-bin.fromRustupToolchainFile (self + /rust-toolchain.toml)).override {
rustToolchain = (pkgs.rust-bin.fromRustupToolchainFile (self + /rust-toolchain.toml)).override { extensions = [
extensions = [ "rust-src"
"rust-src" "rust-analyzer"
"rust-analyzer" "clippy"
"clippy" ];
};
# NB: we don't need to overlay our custom toolchain for the *entire*
# pkgs (which would require rebuidling anything else which uses rust).
# Instead, we just want to update the scope that crane will use by appending
# our specific toolchain there.
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
src = craneLib.cleanCargoSource (craneLib.path ./.);
# Common arguments can be set here to avoid repeating them later
commonArgs = {
inherit src;
strictDeps = true;
buildInputs =
[
# Add additional build inputs here
]
++ lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
]; ];
};
# NB: we don't need to overlay our custom toolchain for the *entire* # Additional environment variables can be set directly
# pkgs (which would require rebuidling anything else which uses rust). # MY_CUSTOM_VAR = "some value";
# Instead, we just want to update the scope that crane will use by appending };
# our specific toolchain there.
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
src = craneLib.cleanCargoSource (craneLib.path ./.); craneLibLLvmTools =
craneLib.overrideToolchain
(fenix.packages.${system}.complete.withComponents [
"cargo"
"llvm-tools"
"rustc"
]);
# Common arguments can be set here to avoid repeating them later # Build *just* the cargo dependencies, so we can reuse
commonArgs = { # all of that work (e.g. via cachix) when running in CI
inherit src; cargoArtifacts = craneLib.buildDepsOnly commonArgs;
strictDeps = true;
buildInputs = # Build the actual crate itself, reusing the dependency
[ # artifacts from above.
# Add additional build inputs here aba2sat = craneLib.buildPackage (commonArgs
] // {
++ lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
};
craneLibLLvmTools =
craneLib.overrideToolchain
(fenix.packages.${system}.complete.withComponents [
"cargo"
"llvm-tools"
"rustc"
]);
# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual crate itself, reusing the dependency
# artifacts from above.
aba2sat = craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts; inherit cargoArtifacts;
}); });
in in {
{ _module.args.pkgs = import nixpkgs {
_module.args.pkgs = import nixpkgs { inherit system;
inherit system; overlays = [
overlays = [ (import rust-overlay)
(import rust-overlay) ];
]; };
};
checks = { checks = {
# Build the crate as part of `nix flake check` for convenience # Build the crate as part of `nix flake check` for convenience
inherit aba2sat; inherit aba2sat;
# Run clippy (and deny all warnings) on the crate source, # Run clippy (and deny all warnings) on the crate source,
# again, reusing the dependency artifacts from above. # again, reusing the dependency artifacts from above.
# #
# Note that this is done as a separate derivation so that # Note that this is done as a separate derivation so that
# we can block the CI if there are issues here, but not # we can block the CI if there are issues here, but not
# prevent downstream consumers from building our crate by itself. # prevent downstream consumers from building our crate by itself.
aba2sat-clippy = craneLib.cargoClippy (commonArgs aba2sat-clippy = craneLib.cargoClippy (commonArgs
// { // {
inherit cargoArtifacts; inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings"; cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}); });
aba2sat-doc = craneLib.cargoDoc (commonArgs aba2sat-doc = craneLib.cargoDoc (commonArgs
// { // {
inherit cargoArtifacts; inherit cargoArtifacts;
}); });
# Check formatting # Check formatting
aba2sat-fmt = craneLib.cargoFmt { aba2sat-fmt = craneLib.cargoFmt {
inherit src; inherit src;
}; };
# Audit dependencies # Audit dependencies
aba2sat-audit = craneLib.cargoAudit { aba2sat-audit = craneLib.cargoAudit {
inherit src advisory-db; inherit src advisory-db;
}; };
# Audit licenses # Audit licenses
aba2sat-deny = crane.lib.${system}.cargoDeny { aba2sat-deny = crane.lib.${system}.cargoDeny {
inherit src; inherit src;
}; };
# Run tests with cargo-nextest # Run tests with cargo-nextest
# Consider setting `doCheck = false` on `aba2sat` if you do not want # Consider setting `doCheck = false` on `aba2sat` if you do not want
# the tests to run twice # the tests to run twice
aba2sat-nextest = craneLib.cargoNextest (commonArgs aba2sat-nextest = craneLib.cargoNextest (commonArgs
// { // {
inherit cargoArtifacts; inherit cargoArtifacts;
partitions = 1; partitions = 1;
partitionType = "count"; partitionType = "count";
}); });
}; };
packages = packages =
{ {
default = aba2sat; default = aba2sat;
aspforaba = pkgs.callPackage ./nix/packages/aspforaba.nix { inherit (self'.packages) clingo; }; aspforaba = pkgs.callPackage ./nix/packages/aspforaba.nix {inherit (self'.packages) clingo;};
clingo = pkgs.callPackage ./nix/packages/clingo.nix { }; clingo = pkgs.callPackage ./nix/packages/clingo.nix {};
} }
// lib.optionalAttrs (!pkgs.stdenv.isDarwin) { // lib.optionalAttrs (!pkgs.stdenv.isDarwin) {
aba2sat-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs aba2sat-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs
// { // {
inherit cargoArtifacts; inherit cargoArtifacts;
}); });
};
apps.default = flake-utils.lib.mkApp {
drv = aba2sat;
}; };
devShells.default = craneLib.devShell { apps.default = flake-utils.lib.mkApp {
# Inherit inputs from checks. drv = aba2sat;
checks = self.checks.${system};
RUST_LOG = "trace";
inputsFrom = [ ];
packages = [
pkgs.hyperfine
pkgs.lldb
pkgs.nil
pkgs.nodejs
pkgs.pre-commit
pkgs.shellcheck
pkgs.shfmt
self'.packages.aspforaba
];
};
}; };
devShells.default = craneLib.devShell {
# Inherit inputs from checks.
checks = self.checks.${system};
RUST_LOG = "trace";
inputsFrom = [];
packages = [
pkgs.hyperfine
pkgs.lldb
pkgs.nil
pkgs.nodejs
pkgs.pre-commit
pkgs.pyright
pkgs.ruff-lsp
pkgs.shellcheck
pkgs.shfmt
self'.packages.aspforaba
];
};
};
}; };
} }