|
39 | 39 | };
|
40 | 40 |
|
41 | 41 | initVenvScript = pkgs.writeShellScript "init-venv.sh" ''
|
42 |
| - # Make sure any tools are not attempting to use the python interpreter from any |
| 42 | + # Make sure any tools are not attempting to use the Python interpreter from any |
43 | 43 | # existing virtual environment. For instance if devenv was started within an venv.
|
44 | 44 | unset VIRTUAL_ENV
|
45 | 45 |
|
46 |
| - VENV_PATH="${config.env.DEVENV_STATE}/venv" |
| 46 | + VENV_PATH="${config.env.DEVENV_STATE}/${lib.optionalString (cfg.directory != config.devenv.root) ''"${cfg.directory}/"''}venv" |
47 | 47 |
|
48 | 48 | profile_python="$(${readlink} ${package.interpreter})"
|
49 | 49 | devenv_interpreter_path="$(${pkgs.coreutils}/bin/cat "$VENV_PATH/.devenv_interpreter" 2> /dev/null || echo false )"
|
|
82 | 82 | initPoetryScript = pkgs.writeShellScript "init-poetry.sh" ''
|
83 | 83 | function _devenv_init_poetry_venv
|
84 | 84 | {
|
85 |
| - # Make sure any tools are not attempting to use the python interpreter from any |
| 85 | + # Make sure any tools are not attempting to use the Python interpreter from any |
86 | 86 | # existing virtual environment. For instance if devenv was started within an venv.
|
87 | 87 | unset VIRTUAL_ENV
|
88 | 88 |
|
89 |
| - # Make sure poetry's venv uses the configured python executable. |
| 89 | + # Make sure poetry's venv uses the configured Python executable. |
90 | 90 | ${cfg.poetry.package}/bin/poetry env use --no-interaction --quiet ${package.interpreter}
|
91 | 91 | }
|
92 | 92 |
|
93 | 93 | function _devenv_poetry_install
|
94 | 94 | {
|
95 |
| - local POETRY_INSTALL_COMMAND=(${cfg.poetry.package}/bin/poetry install --no-interaction ${lib.concatStringsSep " " cfg.poetry.install.arguments}) |
| 95 | + 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}''}) |
96 | 96 | # Avoid running "poetry install" for every shell.
|
97 |
| - # Only run it when the "poetry.lock" file or python interpreter has changed. |
| 97 | + # Only run it when the "poetry.lock" file or Python interpreter has changed. |
98 | 98 | # We do this by storing the interpreter path and a hash of "poetry.lock" in venv.
|
99 |
| - local ACTUAL_POETRY_CHECKSUM="${package.interpreter}:$(${pkgs.nix}/bin/nix-hash --type sha256 pyproject.toml):$(${pkgs.nix}/bin/nix-hash --type sha256 poetry.lock):''${POETRY_INSTALL_COMMAND[@]}" |
100 |
| - local POETRY_CHECKSUM_FILE="$DEVENV_ROOT"/.venv/poetry.lock.checksum |
| 99 | + local ACTUAL_POETRY_CHECKSUM="${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[@]}" |
| 100 | + local POETRY_CHECKSUM_FILE="$DEVENV_ROOT"/${lib.optionalString (cfg.directory != config.devenv.root) ''${cfg.directory}/''}.venv/poetry.lock.checksum |
101 | 101 | if [ -f "$POETRY_CHECKSUM_FILE" ]
|
102 | 102 | then
|
103 | 103 | read -r EXPECTED_POETRY_CHECKSUM < "$POETRY_CHECKSUM_FILE"
|
|
116 | 116 | fi
|
117 | 117 | }
|
118 | 118 |
|
119 |
| - if [ ! -f pyproject.toml ] |
| 119 | + if [ ! -f "$DEVENV_ROOT"/${lib.optionalString (cfg.directory != config.devenv.root) ''${cfg.directory}/''}pyproject.toml ] |
120 | 120 | then
|
121 | 121 | echo "No pyproject.toml found. Run 'poetry init' to create one." >&2
|
122 | 122 | else
|
|
125 | 125 | _devenv_poetry_install
|
126 | 126 | ''}
|
127 | 127 | ${lib.optionalString cfg.poetry.activate.enable ''
|
128 |
| - source "$DEVENV_ROOT"/.venv/bin/activate |
| 128 | + source "$DEVENV_ROOT"/${lib.optionalString (cfg.directory != config.devenv.root) ''${cfg.directory}/''}.venv/bin/activate |
129 | 129 | ''}
|
130 | 130 | fi
|
131 | 131 | '';
|
|
173 | 173 | example = "3.11 or 3.11.2";
|
174 | 174 | };
|
175 | 175 |
|
| 176 | + directory = lib.mkOption { |
| 177 | + type = lib.types.str; |
| 178 | + default = config.devenv.root; |
| 179 | + defaultText = lib.literalExpression "config.devenv.root"; |
| 180 | + description = '' |
| 181 | + The Python project's root directory. Defaults to the root of the devenv project. |
| 182 | + Can be an absolute path or one relative to the root of the devenv project. |
| 183 | + ''; |
| 184 | + example = "./directory"; |
| 185 | + }; |
| 186 | + |
176 | 187 | venv.enable = lib.mkEnableOption "Python virtual environment";
|
177 | 188 |
|
178 | 189 | venv.requirements = lib.mkOption {
|
|
205 | 216 | default = false;
|
206 | 217 | description = "Whether the root package (your project) should be installed. See `--no-root`";
|
207 | 218 | };
|
| 219 | + onlyInstallRootPackage = lib.mkOption { |
| 220 | + type = lib.types.bool; |
| 221 | + default = false; |
| 222 | + description = "Whether to only install the root package (your project) should be installed, but no dependencies. See `--only-root`"; |
| 223 | + }; |
| 224 | + compile = lib.mkOption { |
| 225 | + type = lib.types.bool; |
| 226 | + default = false; |
| 227 | + description = "Whether `poetry install` should compile Python source files to bytecode."; |
| 228 | + }; |
208 | 229 | quiet = lib.mkOption {
|
209 | 230 | type = lib.types.bool;
|
210 | 231 | default = false;
|
|
213 | 234 | groups = lib.mkOption {
|
214 | 235 | type = lib.types.listOf lib.types.str;
|
215 | 236 | default = [ ];
|
216 |
| - description = "Which dependency-groups to install. See `--with`."; |
| 237 | + description = "Which dependency groups to install. See `--with`."; |
| 238 | + }; |
| 239 | + ignoredGroups = lib.mkOption { |
| 240 | + type = lib.types.listOf lib.types.str; |
| 241 | + default = [ ]; |
| 242 | + description = "Which dependency groups to ignore. See `--without`."; |
| 243 | + }; |
| 244 | + onlyGroups = lib.mkOption { |
| 245 | + type = lib.types.listOf lib.types.str; |
| 246 | + default = [ ]; |
| 247 | + description = "Which dependency groups to exclusively install. See `--only`."; |
217 | 248 | };
|
218 | 249 | extras = lib.mkOption {
|
219 | 250 | type = lib.types.listOf lib.types.str;
|
|
225 | 256 | default = false;
|
226 | 257 | description = "Whether to install all extras. See `--all-extras`.";
|
227 | 258 | };
|
| 259 | + verbosity = lib.mkOption { |
| 260 | + type = lib.types.enum [ "no" "little" "more" "debug" ]; |
| 261 | + default = "no"; |
| 262 | + description = "What level of verbosity the output of `poetry install` should have."; |
| 263 | + }; |
| 264 | + }; |
| 265 | + activate.enable = lib.mkOption { |
| 266 | + type = lib.types.bool; |
| 267 | + default = false; |
| 268 | + description = "Whether to activate the poetry virtual environment automatically."; |
228 | 269 | };
|
229 |
| - activate.enable = lib.mkEnableOption "activate the poetry virtual environment automatically"; |
230 |
| - |
231 | 270 | package = lib.mkOption {
|
232 | 271 | type = lib.types.package;
|
233 | 272 | default = pkgs.poetry;
|
|
240 | 279 | config = lib.mkIf cfg.enable {
|
241 | 280 | languages.python.poetry.install.enable = lib.mkIf cfg.poetry.enable (lib.mkDefault true);
|
242 | 281 | languages.python.poetry.install.arguments =
|
243 |
| - lib.optional (!cfg.poetry.install.installRootPackage) "--no-root" ++ |
| 282 | + lib.optional cfg.poetry.install.onlyInstallRootPackage "--only-root" ++ |
| 283 | + lib.optional (!cfg.poetry.install.installRootPackage && !cfg.poetry.install.onlyInstallRootPackage) "--no-root" ++ |
| 284 | + lib.optional cfg.poetry.install.compile "--compile" ++ |
244 | 285 | lib.optional cfg.poetry.install.quiet "--quiet" ++
|
245 | 286 | lib.optionals (cfg.poetry.install.groups != [ ]) [ "--with" ''"${lib.concatStringsSep "," cfg.poetry.install.groups}"'' ] ++
|
| 287 | + lib.optionals (cfg.poetry.install.ignoredGroups != [ ]) [ "--without" ''"${lib.concatStringsSep "," cfg.poetry.install.ignoredGroups}"'' ] ++ |
| 288 | + lib.optionals (cfg.poetry.install.onlyGroups != [ ]) [ "--only" ''"${lib.concatStringsSep " " cfg.poetry.install.onlyGroups}"'' ] ++ |
246 | 289 | lib.optionals (cfg.poetry.install.extras != [ ]) [ "--extras" ''"${lib.concatStringsSep " " cfg.poetry.install.extras}"'' ] ++
|
247 |
| - lib.optional cfg.poetry.install.allExtras "--all-extras"; |
| 290 | + lib.optional cfg.poetry.install.allExtras "--all-extras" ++ |
| 291 | + lib.optional (cfg.poetry.install.verbosity == "little") "-v" ++ |
| 292 | + lib.optional (cfg.poetry.install.verbosity == "more") "-vv" ++ |
| 293 | + lib.optional (cfg.poetry.install.verbosity == "debug") "-vvv"; |
248 | 294 |
|
249 | 295 | languages.python.poetry.activate.enable = lib.mkIf cfg.poetry.enable (lib.mkDefault true);
|
250 | 296 |
|
|
0 commit comments