@@ -373,26 +373,27 @@ def poetry_project_name(directory: str) -> Union[str, None]:
373373
374374def activator (env_directory : str , args : Args ) -> str :
375375 """Get the activator script for the environment in the given directory."""
376- dir_name = "Scripts" if operating_system () == Os .WINDOWS else "bin"
376+ is_windows = operating_system () == Os .WINDOWS
377+ dir_name = "Scripts" if is_windows else "bin"
377378 if args .fish :
378379 script = "activate.fish"
379380 elif args .pwsh :
380- poetry_dir = poetry_cache_dir ()
381- if (
382- poetry_dir is not None
383- and env_directory .startswith (poetry_dir )
384- and operating_system () != Os .WINDOWS
385- ):
386- # In poetry environments on *NIX systems, this activator has
387- # a lowercase A.
388- script = "activate.ps1"
381+ if is_windows :
382+ script = "Activate.ps1"
389383 else :
390- # In venv environments, and Windows poetry environments,
391- # this activator has an uppercase A.
384+ # PowerShell activation scripts on Nix systems have some
385+ # slightly inconsistent naming. When using Poetry or uv, the
386+ # activation script is lower case, using the venv module,
387+ # the script is title case.
388+ # We can't really know what was used to generate the venv
389+ # so just check which activation script exists.
390+ script_path = os .path .join (env_directory , dir_name , "activate.ps1" )
391+ if os .path .isfile (script_path ):
392+ return script_path
392393 script = "Activate.ps1"
393394 else :
394395 script = "activate"
395- return os .path .join (env_directory , dir_name , f" { script } " )
396+ return os .path .join (env_directory , dir_name , script )
396397
397398
398399@lru_cache (maxsize = 128 )
0 commit comments