Skip to content

Commit

Permalink
Use config.devenv.root as default for Python project directory
Browse files Browse the repository at this point in the history
  • Loading branch information
totoroot committed Mar 4, 2024
1 parent f1f49e7 commit 3836eb8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/modules/languages/python.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let
# existing virtual environment. For instance if devenv was started within an venv.
unset VIRTUAL_ENV
VENV_PATH="${config.env.DEVENV_STATE}/${lib.optionalString (cfg.directory != ".") ''"${cfg.directory}/"''}venv"
VENV_PATH="${config.env.DEVENV_STATE}/${lib.optionalString (cfg.directory != config.devenv.root) ''"${cfg.directory}/"''}venv"
if [ ! -L "$VENV_PATH"/devenv-profile ] \
|| [ "$(${pkgs.coreutils}/bin/readlink "$VENV_PATH"/devenv-profile)" != "${config.devenv.profile}" ]
Expand Down Expand Up @@ -59,12 +59,12 @@ let
function _devenv-poetry-install()
{
local POETRY_INSTALL_COMMAND=(${cfg.poetry.package}/bin/poetry install --no-interaction ${lib.concatStringsSep " " cfg.poetry.install.arguments} ${lib.optionalString (cfg.directory != ".") ''--directory=${cfg.directory}''})
local POETRY_INSTALL_COMMAND=(${cfg.poetry.package}/bin/poetry install --no-interaction ${lib.concatStringsSep " " cfg.poetry.install.arguments} ${lib.optionalString (cfg.directory != config.devenv.root) ''--directory=${cfg.directory}''})
# Avoid running "poetry install" for every shell.
# Only run it when the "poetry.lock" file or Python interpreter has changed.
# We do this by storing the interpreter path and a hash of "poetry.lock" in venv.
local ACTUAL_POETRY_CHECKSUM="${cfg.package.interpreter}:$(${pkgs.nix}/bin/nix-hash --type sha256 "$DEVENV_ROOT"/${lib.optionalString (cfg.directory != ".") ''${cfg.directory}/''}pyproject.toml):$(${pkgs.nix}/bin/nix-hash --type sha256 "$DEVENV_ROOT"/${lib.optionalString (cfg.directory != ".") ''${cfg.directory}/''}poetry.lock):''${POETRY_INSTALL_COMMAND[@]}"
local POETRY_CHECKSUM_FILE="$DEVENV_ROOT"/${lib.optionalString (cfg.directory != ".") ''${cfg.directory}/''}.venv/poetry.lock.checksum
local ACTUAL_POETRY_CHECKSUM="${cfg.package.interpreter}:$(${pkgs.nix}/bin/nix-hash --type sha256 "$DEVENV_ROOT"/${lib.optionalString (cfg.directory != config.devenv.root) ''${cfg.directory}/''}pyproject.toml):$(${pkgs.nix}/bin/nix-hash --type sha256 "$DEVENV_ROOT"/${lib.optionalString (cfg.directory != config.devenv.root) ''${cfg.directory}/''}poetry.lock):''${POETRY_INSTALL_COMMAND[@]}"
local POETRY_CHECKSUM_FILE="$DEVENV_ROOT"/${lib.optionalString (cfg.directory != config.devenv.root) ''${cfg.directory}/''}.venv/poetry.lock.checksum
if [ -f "$POETRY_CHECKSUM_FILE" ]
then
read -r EXPECTED_POETRY_CHECKSUM < "$POETRY_CHECKSUM_FILE"
Expand All @@ -83,7 +83,7 @@ let
fi
}
if [ ! -f "$DEVENV_ROOT"/${lib.optionalString (cfg.directory != ".") ''${cfg.directory}/''}pyproject.toml ]
if [ ! -f "$DEVENV_ROOT"/${lib.optionalString (cfg.directory != config.devenv.root) ''${cfg.directory}/''}pyproject.toml ]
then
echo "No pyproject.toml found. Run 'poetry init' to create one." >&2
else
Expand All @@ -92,7 +92,7 @@ let
_devenv-poetry-install
''}
${lib.optionalString cfg.poetry.activate.enable ''
source "$DEVENV_ROOT"/${lib.optionalString (cfg.directory != ".") ''${cfg.directory}/''}.venv/bin/activate
source "$DEVENV_ROOT"/${lib.optionalString (cfg.directory != config.devenv.root) ''${cfg.directory}/''}.venv/bin/activate
''}
fi
'';
Expand Down Expand Up @@ -137,7 +137,7 @@ in

directory = lib.mkOption {
type = lib.types.str;
default = ".";
default = config.devenv.root;
description = ''
The Python project's root directory. Defaults to the root of the devenv project.
'';
Expand Down

0 comments on commit 3836eb8

Please sign in to comment.