diff --git a/packaging/nix/flake.nix b/packaging/nix/flake.nix index dd0830d05..564007e78 100644 --- a/packaging/nix/flake.nix +++ b/packaging/nix/flake.nix @@ -97,6 +97,10 @@ packagesWith = pkgs: rec { default = villas; + villas-python = pkgs.callPackage ./python.nix { + src = ../../python; + }; + villas-minimal = pkgs.callPackage ./villas.nix { src = ../..; version = "minimal"; diff --git a/packaging/nix/python.nix b/packaging/nix/python.nix new file mode 100644 index 000000000..d1a4dac58 --- /dev/null +++ b/packaging/nix/python.nix @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2023 OPAL-RT Germany GmbH +# SPDX-License-Identifier: Apache-2.0 +{ + src, + python3Packages, + villas-minimal, +}: +python3Packages.buildPythonPackage { + name = "villas-python"; + src = src; + propagatedBuildInputs = with python3Packages; [ + linuxfd + requests + villas-minimal + ]; + nativeCheckInputs = with python3Packages; [ + black + flake8 + mypy + pytest + types-requests + ]; +} diff --git a/python/.envrc b/python/.envrc new file mode 100644 index 000000000..5a55089c7 --- /dev/null +++ b/python/.envrc @@ -0,0 +1,36 @@ +# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 + +export_or_unset() +{ + local var=$1 + + if [ -z "${!var+x}" ]; then + return + fi + + if [ -n "$2" ]; then + export $var="$2" + else + unset $var + fi + +} + +if direnv_version "2.30.0" \ +&& has nix \ +&& nix show-config experimental-features 2>/dev/null | grep -wqF flakes +then + local oldtmp="$TMP" + local oldtemp="$TEMP" + local oldtmpdir="$TMPDIR" + local oldtempdir="$TEMPDIR" + + watch_file ../packaging/nix/*.nix + use flake ../packaging/nix#villas-python + + export_or_unset TMP "$oldtmp" + export_or_unset TEMP "$oldtemp" + export_or_unset TMPDIR "$oldtmpdir" + export_or_unset TEMPDIR "$oldtempdir" +fi