Skip to content

Commit 8a1a934

Browse files
Daniel Dinnyesnecaris
authored andcommitted
fixed bug with conda-env-manage-for-buffer
When called with only one prefix argument, while no environment YAML file is found. In such case it will conda-env-yaml-process-for-buffer will try to call conda create -f nil, which will throw an error because it expects string as filename. Instead, the behaviour should be fallback to generate a new environment file.
1 parent 888e0ff commit 8a1a934

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

conda.el

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -816,34 +816,38 @@ or one of its parent directories, or else returns nil."
816816
;;;###autoload
817817
(defun conda-env-manage-for-buffer (&optional arg)
818818
"Edit the Conda environment YAML file implied by the current buffer,
819-
or create, update, remove the environment defined in it.
819+
or create, update, remove environments using it.
820820
821-
If called with two \\[universal-argument] prefix, it prompts for an environment
822-
to be removed, suggesting the one defined in the YAML file as default.
821+
If an environment YAML file named `conda-env-yaml-base-name' exists, then is used as the reference.
822+
823+
If called without \\[universal-argument] prefix, and an environment file exists, then opens it for editing.
824+
If called without \\[universal-argument] prefix, and no environment file exists, then prompts for an
825+
environment name, and generates a buffer for a new YAML file in the root directory of the current project,
826+
or in the `default-directory'.
823827
824-
If no environment file exists yet, then generates a buffer for a new YAML file
825-
in the root directory of the current project, or in the `default-directory'.
828+
The newly generated environment YAML file takes its defaults from these variables:
826829
827-
The values from `conda-env-yaml-default-channels', `conda-env-yaml-base-name',
828-
`conda-env-yaml-default-pip-dependencies, are used as content. Additionally,
829-
if a file named `conda-pip-requirements-filename' exists in parent directories,
830-
then the new environment YAML file will be placed next to it, and will reference
831-
the PIP requirements file directly, instead of `conda-env-yaml-default-pip-dependencies'.
830+
- `conda-env-yaml-default-channels',
831+
- `conda-env-yaml-default-dependencies',
832+
- `conda-env-yaml-default-pip-dependencies'.
832833
833-
If the environment file exists, and has been called with one \\[universal-argument] prefix,
834-
then it calls `conda-env-yaml-process-for-buffer' for the environment file.
834+
If file named `conda-pip-requirements-filename' exists in one of the parent
835+
directories, then the generated file will be placed next to it instead,
836+
and will be referenced directly for PIP dependencies, instead of using
837+
the `conda-env-yaml-default-pip-dependencies' variable.
835838
836-
If called with two \\[universal-argument] prefixes, then prompts for the name of
837-
an existing environment and calls `conda-env-yaml-process-for-buffer' with
838-
the prefix to remove it completely, after confirmation. The default candidate
839-
suggested is the one defined in the environment YAML file, if such file exists."
839+
If called with one \\[universal-argument] prefix, and an environment file exists,
840+
then updates the environment from the file, or creates it if not yet exists.
841+
842+
If called with two \\[universal-argument] prefix, it prompts for an environment
843+
to be removed. In environment YAML file exists its name is used as default."
840844
(interactive "P")
841845
(let* ((dir (if-let ((filename (buffer-file-name)))
842846
(f-dirname filename) default-directory))
843847
(env-file (conda--find-env-yaml dir))
844848
(project (project-current dir)))
845849
(cond
846-
((and (not arg) (null env-file))
850+
((and (not env-file) (or (not arg) (and (consp arg) (= (car arg) 4))))
847851
(let* ((pip-reqs-file (conda--find-pip-requirements-file))
848852
(env-dir (or (if pip-reqs-file (f-dirname pip-reqs-file))
849853
(if project (project-root project)) dir))
@@ -869,6 +873,8 @@ suggested is the one defined in the environment YAML file, if such file exists."
869873
(message "Generated new Conda environment file %s" env-file)))
870874
((consp arg)
871875
(conda-env-yaml-process-for-buffer (<= 14 (car arg)) env-file))
876+
;; only interactive universal prefix arguments are expected
877+
(arg (error "Unsupported prefix argument %s" arg))
872878
(env-file (find-file env-file)
873879
(message "Opened Conda environment file %s" env-file)))))
874880

0 commit comments

Comments
 (0)