Merge pull request 'clan-app: Fix default.nix' (#2699) from Qubasa/clan-core:Qubasa-main into main
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -14,7 +14,7 @@ example_clan
|
|||||||
nixos.qcow2
|
nixos.qcow2
|
||||||
**/*.glade~
|
**/*.glade~
|
||||||
/docs/out
|
/docs/out
|
||||||
|
**/.local.env
|
||||||
|
|
||||||
# dream2nix
|
# dream2nix
|
||||||
.dream2nix
|
.dream2nix
|
||||||
|
|||||||
@@ -92,13 +92,12 @@
|
|||||||
treefmt.programs.mypy.directories =
|
treefmt.programs.mypy.directories =
|
||||||
{
|
{
|
||||||
"clan-cli" = {
|
"clan-cli" = {
|
||||||
extraPythonPackages = self'.packages.clan-cli.testDependencies;
|
|
||||||
directory = "pkgs/clan-cli";
|
directory = "pkgs/clan-cli";
|
||||||
|
extraPythonPackages = (self'.packages.clan-cli.devshellPyDeps pkgs.python3Packages);
|
||||||
};
|
};
|
||||||
"clan-app" = {
|
"clan-app" = {
|
||||||
directory = "pkgs/clan-app";
|
directory = "pkgs/clan-app";
|
||||||
extraPythonPackages =
|
extraPythonPackages = (self'.packages.clan-app.devshellPyDeps pkgs.python3Packages);
|
||||||
(self'.packages.clan-app.externalTestDeps or [ ]) ++ self'.packages.clan-cli.testDependencies;
|
|
||||||
extraPythonPaths = [ "../clan-cli" ];
|
extraPythonPaths = [ "../clan-cli" ];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -107,8 +106,9 @@
|
|||||||
{
|
{
|
||||||
"clan-vm-manager" = {
|
"clan-vm-manager" = {
|
||||||
directory = "pkgs/clan-vm-manager";
|
directory = "pkgs/clan-vm-manager";
|
||||||
extraPythonPackages =
|
extraPythonPackages = self'.packages.clan-vm-manager.externalTestDeps ++ [
|
||||||
self'.packages.clan-vm-manager.externalTestDeps ++ self'.packages.clan-cli.testDependencies;
|
(pkgs.python3.withPackages (ps: self'.packages.clan-cli.devshellPyDeps ps))
|
||||||
|
];
|
||||||
extraPythonPaths = [ "../clan-cli" ];
|
extraPythonPaths = [ "../clan-cli" ];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 86 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 163 KiB |
@@ -1,63 +0,0 @@
|
|||||||
/* Insert custom styles here */
|
|
||||||
|
|
||||||
navigation-view {
|
|
||||||
padding: 5px;
|
|
||||||
/* padding-left: 5px;
|
|
||||||
padding-right: 5px;
|
|
||||||
padding-bottom: 5px; */
|
|
||||||
}
|
|
||||||
|
|
||||||
avatar {
|
|
||||||
margin: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.trust {
|
|
||||||
padding-top: 25px;
|
|
||||||
padding-bottom: 25px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.join-list {
|
|
||||||
margin-top: 1px;
|
|
||||||
margin-left: 2px;
|
|
||||||
margin-right: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.progress-bar {
|
|
||||||
margin-right: 25px;
|
|
||||||
min-width: 200px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.group-list {
|
|
||||||
background-color: inherit;
|
|
||||||
}
|
|
||||||
.group-list > .activatable:hover {
|
|
||||||
background-color: unset;
|
|
||||||
}
|
|
||||||
|
|
||||||
.group-list > row {
|
|
||||||
margin-top: 12px;
|
|
||||||
border-bottom: unset;
|
|
||||||
}
|
|
||||||
|
|
||||||
.vm-list {
|
|
||||||
margin-top: 25px;
|
|
||||||
margin-bottom: 25px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.no-shadow {
|
|
||||||
box-shadow: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.search-entry {
|
|
||||||
margin-bottom: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
searchbar {
|
|
||||||
margin-bottom: 25px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-view {
|
|
||||||
margin-top: 12px;
|
|
||||||
font-family: monospace;
|
|
||||||
padding: 8px;
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,13 @@ from collections.abc import Callable
|
|||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from clan_cli.api import MethodRegistry, dataclass_to_dict, from_dict
|
from clan_cli.api import (
|
||||||
|
ApiError,
|
||||||
|
ErrorDataClass,
|
||||||
|
MethodRegistry,
|
||||||
|
dataclass_to_dict,
|
||||||
|
from_dict,
|
||||||
|
)
|
||||||
|
|
||||||
from ._webview_ffi import _encode_c_string, _webview_lib
|
from ._webview_ffi import _encode_c_string, _webview_lib
|
||||||
|
|
||||||
@@ -20,6 +26,11 @@ class SizeHint(IntEnum):
|
|||||||
FIXED = 3
|
FIXED = 3
|
||||||
|
|
||||||
|
|
||||||
|
class FuncStatus(IntEnum):
|
||||||
|
SUCCESS = 0
|
||||||
|
FAILURE = 1
|
||||||
|
|
||||||
|
|
||||||
class Size:
|
class Size:
|
||||||
def __init__(self, width: int, height: int, hint: SizeHint) -> None:
|
def __init__(self, width: int, height: int, hint: SizeHint) -> None:
|
||||||
self.width = width
|
self.width = width
|
||||||
@@ -85,44 +96,48 @@ class Webview:
|
|||||||
try:
|
try:
|
||||||
args = json.loads(req.decode())
|
args = json.loads(req.decode())
|
||||||
|
|
||||||
try:
|
log.debug(f"Calling {method_name}({args[0]})")
|
||||||
log.debug(f"Calling {method_name}({args[0]})")
|
# Initialize dataclasses from the payload
|
||||||
# Initialize dataclasses from the payload
|
reconciled_arguments = {}
|
||||||
reconciled_arguments = {}
|
for k, v in args[0].items():
|
||||||
for k, v in args[0].items():
|
# Some functions expect to be called with dataclass instances
|
||||||
# Some functions expect to be called with dataclass instances
|
# But the js api returns dictionaries.
|
||||||
# But the js api returns dictionaries.
|
# Introspect the function and create the expected dataclass from dict dynamically
|
||||||
# Introspect the function and create the expected dataclass from dict dynamically
|
# Depending on the introspected argument_type
|
||||||
# Depending on the introspected argument_type
|
arg_class = api.get_method_argtype(method_name, k)
|
||||||
arg_class = api.get_method_argtype(method_name, k)
|
|
||||||
|
|
||||||
# TODO: rename from_dict into something like construct_checked_value
|
# TODO: rename from_dict into something like construct_checked_value
|
||||||
# from_dict really takes Anything and returns an instance of the type/class
|
# from_dict really takes Anything and returns an instance of the type/class
|
||||||
reconciled_arguments[k] = from_dict(arg_class, v)
|
reconciled_arguments[k] = from_dict(arg_class, v)
|
||||||
|
|
||||||
reconciled_arguments["op_key"] = seq.decode()
|
reconciled_arguments["op_key"] = seq.decode()
|
||||||
# TODO: We could remove the wrapper in the MethodRegistry
|
# TODO: We could remove the wrapper in the MethodRegistry
|
||||||
# and just call the method directly
|
# and just call the method directly
|
||||||
result = wrap_method(**reconciled_arguments)
|
result = wrap_method(**reconciled_arguments)
|
||||||
success = True
|
|
||||||
except Exception as e:
|
|
||||||
log.exception(f"Error calling {method_name}")
|
|
||||||
result = str(e)
|
|
||||||
success = False
|
|
||||||
|
|
||||||
try:
|
serialized = json.dumps(
|
||||||
serialized = json.dumps(
|
dataclass_to_dict(result), indent=4, ensure_ascii=False
|
||||||
dataclass_to_dict(result), indent=4, ensure_ascii=False
|
)
|
||||||
)
|
|
||||||
except TypeError:
|
|
||||||
log.exception(f"Error serializing result for {method_name}")
|
|
||||||
raise
|
|
||||||
|
|
||||||
log.debug(f"Result for {method_name}: {serialized}")
|
log.debug(f"Result for {method_name}: {serialized}")
|
||||||
self.return_(seq.decode(), 0 if success else 1, serialized)
|
self.return_(seq.decode(), FuncStatus.SUCCESS, serialized)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(f"Unhandled error in webview {method_name}")
|
log.exception(f"Error while handling result of {method_name}")
|
||||||
self.return_(seq.decode(), 1, str(e))
|
result = ErrorDataClass(
|
||||||
|
op_key=seq.decode(),
|
||||||
|
status="error",
|
||||||
|
errors=[
|
||||||
|
ApiError(
|
||||||
|
message="An internal error occured",
|
||||||
|
description=str(e),
|
||||||
|
location=["bind_jsonschema_api", method_name],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
serialized = json.dumps(
|
||||||
|
dataclass_to_dict(result), indent=4, ensure_ascii=False
|
||||||
|
)
|
||||||
|
self.return_(seq.decode(), FuncStatus.FAILURE, serialized)
|
||||||
|
|
||||||
thread = threading.Thread(target=thread_task)
|
thread = threading.Thread(target=thread_task)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
{
|
{
|
||||||
python3Full,
|
|
||||||
runCommand,
|
runCommand,
|
||||||
setuptools,
|
|
||||||
copyDesktopItems,
|
copyDesktopItems,
|
||||||
clan-cli,
|
clan-cli,
|
||||||
makeDesktopItem,
|
makeDesktopItem,
|
||||||
webview-ui,
|
webview-ui,
|
||||||
webview-lib,
|
webview-lib,
|
||||||
fontconfig,
|
fontconfig,
|
||||||
|
pythonRuntime,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
source = ./.;
|
source = ./.;
|
||||||
|
|
||||||
desktop-file = makeDesktopItem {
|
desktop-file = makeDesktopItem {
|
||||||
name = "org.clan.app";
|
name = "org.clan.app";
|
||||||
exec = "clan-app %u";
|
exec = "clan-app %u";
|
||||||
@@ -25,24 +25,29 @@ let
|
|||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
pyDeps = ps: [
|
||||||
|
ps.tkinter
|
||||||
|
];
|
||||||
|
|
||||||
# Dependencies required for running tests
|
# Dependencies required for running tests
|
||||||
pyTestDeps =
|
pyTestDeps =
|
||||||
ps:
|
ps:
|
||||||
with ps;
|
|
||||||
[
|
[
|
||||||
(python3Full.pkgs.toPythonModule pytest)
|
|
||||||
# Testing framework
|
# Testing framework
|
||||||
pytest-cov # Generate coverage reports
|
ps.pytest
|
||||||
pytest-subprocess # fake the real subprocess behavior to make your tests more independent.
|
ps.pytest-cov # Generate coverage reports
|
||||||
pytest-xdist # Run tests in parallel on multiple cores
|
ps.pytest-subprocess # fake the real subprocess behavior to make your tests more independent.
|
||||||
pytest-timeout # Add timeouts to your tests
|
ps.pytest-xdist # Run tests in parallel on multiple cores
|
||||||
|
ps.pytest-timeout # Add timeouts to your tests
|
||||||
]
|
]
|
||||||
++ pytest.propagatedBuildInputs;
|
++ ps.pytest.propagatedBuildInputs;
|
||||||
|
|
||||||
clan-cli-module = [ (python3Full.pkgs.toPythonModule clan-cli) ];
|
clan-cli-module = [
|
||||||
|
(pythonRuntime.pkgs.toPythonModule (clan-cli.override { inherit pythonRuntime; }))
|
||||||
|
];
|
||||||
|
|
||||||
in
|
in
|
||||||
python3Full.pkgs.buildPythonApplication rec {
|
pythonRuntime.pkgs.buildPythonApplication {
|
||||||
name = "clan-app";
|
name = "clan-app";
|
||||||
src = source;
|
src = source;
|
||||||
format = "pyproject";
|
format = "pyproject";
|
||||||
@@ -51,7 +56,7 @@ python3Full.pkgs.buildPythonApplication rec {
|
|||||||
preFixup = ''
|
preFixup = ''
|
||||||
makeWrapperArgs+=(
|
makeWrapperArgs+=(
|
||||||
--set FONTCONFIG_FILE ${fontconfig.out}/etc/fonts/fonts.conf
|
--set FONTCONFIG_FILE ${fontconfig.out}/etc/fonts/fonts.conf
|
||||||
--set WEBUI_PATH "$out/${python3Full.sitePackages}/clan_app/.webui"
|
--set WEBUI_PATH "$out/${pythonRuntime.sitePackages}/clan_app/.webui"
|
||||||
--set WEBVIEW_LIB_DIR "${webview-lib}/lib"
|
--set WEBVIEW_LIB_DIR "${webview-lib}/lib"
|
||||||
# This prevents problems with mixed glibc versions that might occur when the
|
# This prevents problems with mixed glibc versions that might occur when the
|
||||||
# cli is called through a browser built against another glibc
|
# cli is called through a browser built against another glibc
|
||||||
@@ -62,7 +67,7 @@ python3Full.pkgs.buildPythonApplication rec {
|
|||||||
|
|
||||||
# Deps needed only at build time
|
# Deps needed only at build time
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
setuptools
|
(pythonRuntime.withPackages (ps: [ ps.setuptools ]))
|
||||||
copyDesktopItems
|
copyDesktopItems
|
||||||
fontconfig
|
fontconfig
|
||||||
];
|
];
|
||||||
@@ -71,8 +76,9 @@ python3Full.pkgs.buildPythonApplication rec {
|
|||||||
# same values for your Python package within Nix largely stems from ensuring
|
# same values for your Python package within Nix largely stems from ensuring
|
||||||
# that all necessary dependencies are consistently available both
|
# that all necessary dependencies are consistently available both
|
||||||
# at build time and runtime,
|
# at build time and runtime,
|
||||||
buildInputs = clan-cli-module ++ runtimeDependencies;
|
propagatedBuildInputs = [
|
||||||
propagatedBuildInputs = buildInputs;
|
(pythonRuntime.withPackages (ps: clan-cli-module ++ (pyDeps ps)))
|
||||||
|
] ++ runtimeDependencies;
|
||||||
|
|
||||||
# also re-expose dependencies so we test them in CI
|
# also re-expose dependencies so we test them in CI
|
||||||
passthru = {
|
passthru = {
|
||||||
@@ -81,7 +87,7 @@ python3Full.pkgs.buildPythonApplication rec {
|
|||||||
runCommand "clan-app-pytest"
|
runCommand "clan-app-pytest"
|
||||||
{
|
{
|
||||||
buildInputs = runtimeDependencies ++ [
|
buildInputs = runtimeDependencies ++ [
|
||||||
(python3Full.withPackages (ps: clan-cli-module ++ (pyTestDeps ps)))
|
(pythonRuntime.withPackages (ps: clan-cli-module ++ (pyTestDeps ps) ++ (pyDeps ps)))
|
||||||
fontconfig
|
fontconfig
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -105,7 +111,7 @@ python3Full.pkgs.buildPythonApplication rec {
|
|||||||
echo "STARTING ..."
|
echo "STARTING ..."
|
||||||
export WEBVIEW_LIB_DIR="${webview-lib}/lib"
|
export WEBVIEW_LIB_DIR="${webview-lib}/lib"
|
||||||
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1
|
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1
|
||||||
python3 -m pytest -s -m "not impure" ./tests
|
python -m pytest -s -m "not impure" ./tests
|
||||||
touch $out
|
touch $out
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
@@ -113,11 +119,12 @@ python3Full.pkgs.buildPythonApplication rec {
|
|||||||
|
|
||||||
# Additional pass-through attributes
|
# Additional pass-through attributes
|
||||||
passthru.desktop-file = desktop-file;
|
passthru.desktop-file = desktop-file;
|
||||||
passthru.devshellDeps = ps: (pyTestDeps ps);
|
passthru.devshellPyDeps = ps: (pyTestDeps ps) ++ (pyDeps ps);
|
||||||
|
passthru.pythonRuntime = pythonRuntime;
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
mkdir -p $out/${python3Full.sitePackages}/clan_app/.webui
|
mkdir -p $out/${pythonRuntime.sitePackages}/clan_app/.webui
|
||||||
cp -r ${webview-ui}/lib/node_modules/@clan/webview-ui/dist/* $out/${python3Full.sitePackages}/clan_app/.webui
|
cp -r ${webview-ui}/lib/node_modules/@clan/webview-ui/dist/* $out/${pythonRuntime.sitePackages}/clan_app/.webui
|
||||||
mkdir -p $out/share/icons/hicolor
|
mkdir -p $out/share/icons/hicolor
|
||||||
cp -r ./clan_app/assets/white-favicons/* $out/share/icons/hicolor
|
cp -r ./clan_app/assets/white-favicons/* $out/share/icons/hicolor
|
||||||
'';
|
'';
|
||||||
|
|||||||
@@ -4,23 +4,19 @@
|
|||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
|
||||||
system,
|
|
||||||
self',
|
self',
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
if lib.elem system lib.platforms.darwin then
|
{
|
||||||
{ }
|
devShells.clan-app = pkgs.callPackage ./shell.nix {
|
||||||
else
|
inherit (config.packages) clan-app webview-lib;
|
||||||
{
|
inherit self';
|
||||||
devShells.clan-app = pkgs.callPackage ./shell.nix {
|
|
||||||
inherit (config.packages) clan-app webview-lib;
|
|
||||||
inherit self';
|
|
||||||
};
|
|
||||||
packages.clan-app = pkgs.python3.pkgs.callPackage ./default.nix {
|
|
||||||
inherit (config.packages) clan-cli webview-ui webview-lib;
|
|
||||||
};
|
|
||||||
|
|
||||||
checks = config.packages.clan-app.tests;
|
|
||||||
};
|
};
|
||||||
|
packages.clan-app = pkgs.callPackage ./default.nix {
|
||||||
|
inherit (config.packages) clan-cli webview-ui webview-lib;
|
||||||
|
pythonRuntime = pkgs.python3;
|
||||||
|
};
|
||||||
|
|
||||||
|
checks = config.packages.clan-app.tests;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,3 @@ disallow_untyped_calls = true
|
|||||||
disallow_untyped_defs = true
|
disallow_untyped_defs = true
|
||||||
no_implicit_optional = true
|
no_implicit_optional = true
|
||||||
|
|
||||||
[[tool.mypy.overrides]]
|
|
||||||
module = "clan_cli.*"
|
|
||||||
ignore_missing_imports = true
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
ruff,
|
ruff,
|
||||||
gtk4,
|
gtk4,
|
||||||
webview-lib,
|
webview-lib,
|
||||||
python3Full,
|
|
||||||
self',
|
self',
|
||||||
}:
|
}:
|
||||||
|
|
||||||
@@ -14,14 +13,14 @@ mkShell {
|
|||||||
inputsFrom = [ self'.devShells.default ];
|
inputsFrom = [ self'.devShells.default ];
|
||||||
|
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
(python3Full.withPackages (
|
(clan-app.pythonRuntime.withPackages (
|
||||||
ps:
|
ps:
|
||||||
with ps;
|
with ps;
|
||||||
[
|
[
|
||||||
ruff
|
ruff
|
||||||
mypy
|
mypy
|
||||||
]
|
]
|
||||||
++ (clan-app.devshellDeps ps)
|
++ (clan-app.devshellPyDeps ps)
|
||||||
))
|
))
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -42,6 +41,6 @@ mkShell {
|
|||||||
export XDG_DATA_DIRS=${gsettings-desktop-schemas}/share/gsettings-schemas/gsettings-desktop-schemas-46.0:$XDG_DATA_DIRS
|
export XDG_DATA_DIRS=${gsettings-desktop-schemas}/share/gsettings-schemas/gsettings-desktop-schemas-46.0:$XDG_DATA_DIRS
|
||||||
|
|
||||||
export WEBVIEW_LIB_DIR=${webview-lib}/lib
|
export WEBVIEW_LIB_DIR=${webview-lib}/lib
|
||||||
# export WEBVIEW_LIB_DIR=$HOME/Projects/webview/build/core
|
source $PKG_ROOT/.local.env
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,5 +16,6 @@
|
|||||||
"virtiofsd",
|
"virtiofsd",
|
||||||
"zbar",
|
"zbar",
|
||||||
"util-linux",
|
"util-linux",
|
||||||
"avahi"
|
"avahi",
|
||||||
|
"gnupg"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,67 +1,53 @@
|
|||||||
{
|
{
|
||||||
# callPackage args
|
# callPackage args
|
||||||
argcomplete,
|
|
||||||
gnupg,
|
gnupg,
|
||||||
installShellFiles,
|
installShellFiles,
|
||||||
lib,
|
lib,
|
||||||
nix,
|
nix,
|
||||||
pkgs,
|
pkgs,
|
||||||
pytest-cov,
|
|
||||||
pytest-subprocess,
|
|
||||||
pytest-timeout,
|
|
||||||
pytest-xdist,
|
|
||||||
pytest,
|
|
||||||
python3,
|
|
||||||
runCommand,
|
runCommand,
|
||||||
setuptools,
|
|
||||||
stdenv,
|
stdenv,
|
||||||
nixVersions,
|
nixVersions,
|
||||||
|
|
||||||
# custom args
|
# custom args
|
||||||
clan-core-path,
|
clan-core-path,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
includedRuntimeDeps,
|
includedRuntimeDeps,
|
||||||
|
|
||||||
inventory-schema-abstract,
|
inventory-schema-abstract,
|
||||||
classgen,
|
classgen,
|
||||||
|
pythonRuntime,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
pythonDependencies = [
|
pyDeps = ps: [
|
||||||
argcomplete # Enables shell completions
|
ps.argcomplete # Enables shell completions
|
||||||
];
|
];
|
||||||
|
pyTestDeps =
|
||||||
|
ps:
|
||||||
|
[
|
||||||
|
ps.pytest
|
||||||
|
ps.pytest-cov
|
||||||
|
ps.pytest-subprocess
|
||||||
|
ps.pytest-xdist
|
||||||
|
ps.pytest-timeout
|
||||||
|
]
|
||||||
|
++ (pyDeps ps);
|
||||||
|
pythonRuntimeWithDeps = pythonRuntime.withPackages (ps: pyDeps ps);
|
||||||
|
|
||||||
# load nixpkgs runtime dependencies from a json file
|
# load nixpkgs runtime dependencies from a json file
|
||||||
# This file represents an allow list at the same time that is checked by the run_cmd
|
# This file represents an allow list at the same time that is checked by the run_cmd
|
||||||
# implementation in nix.py
|
# implementation in nix.py
|
||||||
allDependencies = lib.importJSON ./clan_cli/nix/allowed-programs.json;
|
allDependencies = lib.importJSON ./clan_cli/nix/allowed-programs.json;
|
||||||
|
|
||||||
generateRuntimeDependenciesMap =
|
generateRuntimeDependenciesMap =
|
||||||
deps:
|
deps:
|
||||||
lib.filterAttrs (_: pkg: !pkg.meta.unsupported or false) (lib.genAttrs deps (name: pkgs.${name}));
|
lib.filterAttrs (_: pkg: !pkg.meta.unsupported or false) (lib.genAttrs deps (name: pkgs.${name}));
|
||||||
|
|
||||||
runtimeDependenciesMap = generateRuntimeDependenciesMap allDependencies;
|
runtimeDependenciesMap = generateRuntimeDependenciesMap allDependencies;
|
||||||
|
|
||||||
runtimeDependencies = lib.attrValues runtimeDependenciesMap;
|
runtimeDependencies = lib.attrValues runtimeDependenciesMap;
|
||||||
|
|
||||||
includedRuntimeDependenciesMap = generateRuntimeDependenciesMap includedRuntimeDeps;
|
includedRuntimeDependenciesMap = generateRuntimeDependenciesMap includedRuntimeDeps;
|
||||||
|
|
||||||
testDependencies =
|
testDependencies = runtimeDependencies ++ [
|
||||||
runtimeDependencies
|
gnupg
|
||||||
++ [
|
stdenv.cc # Compiler used for certain native extensions
|
||||||
gnupg
|
(pythonRuntime.withPackages (ps: (pyTestDeps ps) ++ (pyDeps ps)))
|
||||||
stdenv.cc # Compiler used for certain native extensions
|
];
|
||||||
]
|
|
||||||
++ pythonDependencies
|
|
||||||
++ [
|
|
||||||
pytest
|
|
||||||
pytest-cov # Generate coverage reports
|
|
||||||
pytest-subprocess # fake the real subprocess behavior to make your tests more independent.
|
|
||||||
pytest-xdist # Run tests in parallel on multiple cores
|
|
||||||
pytest-timeout # Add timeouts to your tests
|
|
||||||
];
|
|
||||||
|
|
||||||
# Setup Python environment with all dependencies for running tests
|
|
||||||
pythonWithTestDeps = python3.withPackages (_ps: testDependencies);
|
|
||||||
|
|
||||||
source = runCommand "clan-cli-source" { } ''
|
source = runCommand "clan-cli-source" { } ''
|
||||||
cp -r ${./.} $out
|
cp -r ${./.} $out
|
||||||
@@ -73,7 +59,6 @@ let
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
# Create a custom nixpkgs for use within the project
|
# Create a custom nixpkgs for use within the project
|
||||||
|
|
||||||
nixpkgs' =
|
nixpkgs' =
|
||||||
runCommand "nixpkgs"
|
runCommand "nixpkgs"
|
||||||
{
|
{
|
||||||
@@ -101,7 +86,7 @@ let
|
|||||||
--extra-experimental-features 'nix-command flakes'
|
--extra-experimental-features 'nix-command flakes'
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
python3.pkgs.buildPythonApplication {
|
pythonRuntime.pkgs.buildPythonApplication {
|
||||||
name = "clan-cli";
|
name = "clan-cli";
|
||||||
src = source;
|
src = source;
|
||||||
format = "pyproject";
|
format = "pyproject";
|
||||||
@@ -123,30 +108,29 @@ python3.pkgs.buildPythonApplication {
|
|||||||
];
|
];
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
setuptools
|
(pythonRuntime.withPackages (ps: [ ps.setuptools ]))
|
||||||
installShellFiles
|
installShellFiles
|
||||||
];
|
];
|
||||||
|
|
||||||
propagatedBuildInputs = pythonDependencies;
|
propagatedBuildInputs = [ pythonRuntimeWithDeps ] ++ runtimeDependencies;
|
||||||
|
|
||||||
# Define and expose the tests and checks to run in CI
|
# Define and expose the tests and checks to run in CI
|
||||||
passthru.tests = (lib.mapAttrs' (n: lib.nameValuePair "clan-dep-${n}") runtimeDependenciesMap) // {
|
passthru.tests = (lib.mapAttrs' (n: lib.nameValuePair "clan-dep-${n}") runtimeDependenciesMap) // {
|
||||||
clan-pytest-without-core =
|
clan-pytest-without-core =
|
||||||
runCommand "clan-pytest-without-core"
|
runCommand "clan-pytest-without-core" { nativeBuildInputs = testDependencies; }
|
||||||
{ nativeBuildInputs = [ pythonWithTestDeps ] ++ testDependencies; }
|
|
||||||
''
|
''
|
||||||
cp -r ${source} ./src
|
cp -r ${source} ./src
|
||||||
chmod +w -R ./src
|
chmod +w -R ./src
|
||||||
cd ./src
|
cd ./src
|
||||||
|
|
||||||
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1 PYTHONWARNINGS=error
|
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1 PYTHONWARNINGS=error
|
||||||
${pythonWithTestDeps}/bin/python -m pytest -m "not impure and not with_core" ./tests
|
python -m pytest -m "not impure and not with_core" ./tests
|
||||||
touch $out
|
touch $out
|
||||||
'';
|
'';
|
||||||
clan-pytest-with-core =
|
clan-pytest-with-core =
|
||||||
runCommand "clan-pytest-with-core"
|
runCommand "clan-pytest-with-core"
|
||||||
{
|
{
|
||||||
nativeBuildInputs = [ pythonWithTestDeps ] ++ testDependencies;
|
nativeBuildInputs = testDependencies;
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
pkgs.bash
|
pkgs.bash
|
||||||
pkgs.coreutils
|
pkgs.coreutils
|
||||||
@@ -177,25 +161,25 @@ python3.pkgs.buildPythonApplication {
|
|||||||
mkdir -p "$CLAN_TEST_STORE/nix/store"
|
mkdir -p "$CLAN_TEST_STORE/nix/store"
|
||||||
xargs cp --recursive --target "$CLAN_TEST_STORE/nix/store" < "$closureInfo/store-paths"
|
xargs cp --recursive --target "$CLAN_TEST_STORE/nix/store" < "$closureInfo/store-paths"
|
||||||
nix-store --load-db --store "$CLAN_TEST_STORE" < "$closureInfo/registration"
|
nix-store --load-db --store "$CLAN_TEST_STORE" < "$closureInfo/registration"
|
||||||
${pythonWithTestDeps}/bin/python -m pytest -m "not impure and with_core" ./tests
|
python -m pytest -m "not impure and with_core" ./tests
|
||||||
touch $out
|
touch $out
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
passthru.nixpkgs = nixpkgs';
|
passthru.nixpkgs = nixpkgs';
|
||||||
passthru.testDependencies = testDependencies;
|
passthru.devshellPyDeps = ps: (pyTestDeps ps) ++ (pyDeps ps);
|
||||||
passthru.pythonWithTestDeps = pythonWithTestDeps;
|
passthru.pythonRuntime = pythonRuntime;
|
||||||
passthru.runtimeDependencies = runtimeDependencies;
|
passthru.runtimeDependencies = runtimeDependencies;
|
||||||
passthru.runtimeDependenciesMap = runtimeDependenciesMap;
|
passthru.runtimeDependenciesMap = runtimeDependenciesMap;
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
cp -r ${nixpkgs'} $out/${python3.sitePackages}/clan_cli/nixpkgs
|
cp -r ${nixpkgs'} $out/${pythonRuntime.sitePackages}/clan_cli/nixpkgs
|
||||||
installShellCompletion --bash --name clan \
|
installShellCompletion --bash --name clan \
|
||||||
<(${argcomplete}/bin/register-python-argcomplete --shell bash clan)
|
<(${pythonRuntimeWithDeps.pkgs.argcomplete}/bin/register-python-argcomplete --shell bash clan)
|
||||||
installShellCompletion --fish --name clan.fish \
|
installShellCompletion --fish --name clan.fish \
|
||||||
<(${argcomplete}/bin/register-python-argcomplete --shell fish clan)
|
<(${pythonRuntimeWithDeps.pkgs.argcomplete}/bin/register-python-argcomplete --shell fish clan)
|
||||||
installShellCompletion --zsh --name _clan \
|
installShellCompletion --zsh --name _clan \
|
||||||
<(${argcomplete}/bin/register-python-argcomplete --shell zsh clan)
|
<(${pythonRuntimeWithDeps.pkgs.argcomplete}/bin/register-python-argcomplete --shell zsh clan)
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Clean up after the package to avoid leaking python packages into a devshell
|
# Clean up after the package to avoid leaking python packages into a devshell
|
||||||
|
|||||||
@@ -103,21 +103,23 @@
|
|||||||
inherit self';
|
inherit self';
|
||||||
};
|
};
|
||||||
packages = {
|
packages = {
|
||||||
clan-cli = pkgs.python3.pkgs.callPackage ./default.nix {
|
clan-cli = pkgs.callPackage ./default.nix {
|
||||||
inherit (inputs) nixpkgs;
|
inherit (inputs) nixpkgs;
|
||||||
inherit (self'.packages) classgen;
|
inherit (self'.packages) classgen;
|
||||||
inherit (self'.legacyPackages.schemas) inventory-schema-abstract;
|
inherit (self'.legacyPackages.schemas) inventory-schema-abstract;
|
||||||
|
pythonRuntime = pkgs.python3;
|
||||||
clan-core-path = clanCoreWithVendoredDeps;
|
clan-core-path = clanCoreWithVendoredDeps;
|
||||||
includedRuntimeDeps = [
|
includedRuntimeDeps = [
|
||||||
"age"
|
"age"
|
||||||
"git"
|
"git"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
clan-cli-full = pkgs.python3.pkgs.callPackage ./default.nix {
|
clan-cli-full = pkgs.callPackage ./default.nix {
|
||||||
inherit (inputs) nixpkgs;
|
inherit (inputs) nixpkgs;
|
||||||
inherit (self'.packages) classgen;
|
inherit (self'.packages) classgen;
|
||||||
inherit (self'.legacyPackages.schemas) inventory-schema-abstract;
|
inherit (self'.legacyPackages.schemas) inventory-schema-abstract;
|
||||||
clan-core-path = clanCoreWithVendoredDeps;
|
clan-core-path = clanCoreWithVendoredDeps;
|
||||||
|
pythonRuntime = pkgs.python3;
|
||||||
includedRuntimeDeps = lib.importJSON ./clan_cli/nix/allowed-programs.json;
|
includedRuntimeDeps = lib.importJSON ./clan_cli/nix/allowed-programs.json;
|
||||||
};
|
};
|
||||||
clan-cli-docs = pkgs.stdenv.mkDerivation {
|
clan-cli-docs = pkgs.stdenv.mkDerivation {
|
||||||
|
|||||||
@@ -45,19 +45,4 @@ disallow_untyped_defs = true
|
|||||||
no_implicit_optional = true
|
no_implicit_optional = true
|
||||||
exclude = "clan_cli.nixpkgs"
|
exclude = "clan_cli.nixpkgs"
|
||||||
|
|
||||||
[[tool.mypy.overrides]]
|
|
||||||
module = "argcomplete.*"
|
|
||||||
ignore_missing_imports = true
|
|
||||||
|
|
||||||
[[tool.mypy.overrides]]
|
|
||||||
module = "ipdb.*"
|
|
||||||
ignore_missing_imports = true
|
|
||||||
|
|
||||||
[[tool.mypy.overrides]]
|
|
||||||
module = "pytest.*"
|
|
||||||
ignore_missing_imports = true
|
|
||||||
|
|
||||||
[[tool.mypy.overrides]]
|
|
||||||
module = "setuptools.*"
|
|
||||||
ignore_missing_imports = true
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,25 +5,22 @@
|
|||||||
clan-cli-full,
|
clan-cli-full,
|
||||||
mkShell,
|
mkShell,
|
||||||
ruff,
|
ruff,
|
||||||
python3,
|
|
||||||
self',
|
self',
|
||||||
}:
|
}:
|
||||||
let
|
|
||||||
devshellTestDeps =
|
|
||||||
clan-cli.passthru.testDependencies
|
|
||||||
++ (with python3.pkgs; [
|
|
||||||
rope
|
|
||||||
setuptools
|
|
||||||
wheel
|
|
||||||
webcolors
|
|
||||||
pip
|
|
||||||
]);
|
|
||||||
in
|
|
||||||
mkShell {
|
mkShell {
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
|
(clan-cli.pythonRuntime.withPackages (
|
||||||
|
ps:
|
||||||
|
with ps;
|
||||||
|
[
|
||||||
|
ruff
|
||||||
|
mypy
|
||||||
|
]
|
||||||
|
++ (clan-cli.devshellPyDeps ps)
|
||||||
|
))
|
||||||
nix-unit
|
nix-unit
|
||||||
ruff
|
] ++ clan-cli.runtimeDependencies;
|
||||||
] ++ devshellTestDeps;
|
|
||||||
|
|
||||||
inputsFrom = [ self'.devShells.default ];
|
inputsFrom = [ self'.devShells.default ];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user