这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion conda/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def _add_prefix_to_path(self, prefix, starting_path_dirs=None):
path_list = list(self.path_conversion(self._get_starting_path_list()))
else:
path_list = list(self.path_conversion(starting_path_dirs))
path_list[0:0] = list(self._get_path_dirs2(prefix))
path_list[0:0] = list(self.path_conversion(self._get_path_dirs2(prefix)))
return tuple(path_list)

def _remove_prefix_from_path(self, prefix, starting_path_dirs=None):
Expand Down Expand Up @@ -708,6 +708,18 @@ def _build_activate_shell_custom(self, export_vars):
def _hook_preamble(self):
raise NotImplementedError()

def _add_prefix_to_path(self, prefix, starting_path_dirs=None):
# If this is the first time we're activating an environment, we need to ensure that
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really only the first time?
If you'd do

conda activate base
conda activate some-other-env
conda activate base
conda activate some-other-env

wouldn't conda.exe precede condacmd/conda.bat on PATH after the second conda activate base so that the last conda activate some-other-env fails?
I'm not really sure on this though and can't check that right now. Maybe create a test case for that?

# the condacmd directory is included in the path list.
old_conda_shlvl = int(self.environ.get('CONDA_SHLVL', '').strip() or 0)
if starting_path_dirs is None:
starting_path_dirs = self._get_starting_path_list()
starting_path_dirs = list(starting_path_dirs)
if not old_conda_shlvl and not any(p.endswith("condacmd") for p in starting_path_dirs):
condacmd_dir = self.path_conversion(join(context.conda_prefix, "condacmd"))
starting_path_dirs.insert(0, condacmd_dir)
return super(CmdExeActivator, self)._add_prefix_to_path(prefix, starting_path_dirs)


class FishActivator(_Activator):

Expand Down
22 changes: 21 additions & 1 deletion tests/test_activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def test_PS1_no_changeps1(self):
instructions = activator.build_activate("base")
assert instructions['export_vars']['CONDA_PROMPT_MODIFIER'] == ''

def test_add_prefix_to_path(self):
def test_add_prefix_to_path_posix(self):
if on_win and "PWD" not in os.environ:
pytest.skip("This test cannot be run from the cmd.exe shell.")

activator = PosixActivator()

path_dirs = activator.path_conversion(['/path1/bin', '/path2/bin', '/usr/local/bin', '/usr/bin', '/bin'])
Expand All @@ -112,6 +115,23 @@ def test_add_prefix_to_path(self):
new_path = activator._add_prefix_to_path(test_prefix, path_dirs)
assert new_path == added_paths + path_dirs

@pytest.mark.skipif(not on_win, reason="windows-specific test")
def test_add_prefix_to_path_cmdexe(self):
activator = CmdExeActivator()

path_dirs = activator.path_conversion(["C:\\path1", "C:\\Program Files\\Git\\cmd", "C:\\WINDOWS\\system32"])
assert len(path_dirs) == 3
test_prefix = '/usr/mytest/prefix'
added_paths = activator.path_conversion(activator._get_path_dirs(test_prefix))
if isinstance(added_paths, string_types):
added_paths = added_paths,

new_path = activator._add_prefix_to_path(test_prefix, path_dirs)
assert new_path[:len(added_paths)] == added_paths
assert new_path[-len(path_dirs):] == path_dirs
assert len(new_path) == len(added_paths) + len(path_dirs) + 1
assert new_path[len(added_paths)].endswith("condacmd")

def test_remove_prefix_from_path_1(self):
activator = PosixActivator()
original_path = tuple(activator._get_starting_path_list())
Expand Down