__init__.py 924 B

123456789101112131415161718192021222324252627282930
  1. from __future__ import annotations
  2. from typing import TYPE_CHECKING
  3. from virtualenv.activation.via_template import ViaTemplateActivator
  4. if TYPE_CHECKING:
  5. from collections.abc import Iterator
  6. class PowerShellActivator(ViaTemplateActivator):
  7. def templates(self) -> Iterator[str]:
  8. yield "activate.ps1"
  9. @staticmethod
  10. def quote(string: str) -> str:
  11. """This should satisfy PowerShell quoting rules [1], unless the quoted string is passed directly to Windows native commands [2].
  12. [1]: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules
  13. [2]:
  14. https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing#passing-arguments-that-contain-quote-characters
  15. """
  16. string = string.replace("'", "''")
  17. return f"'{string}'"
  18. __all__ = [
  19. "PowerShellActivator",
  20. ]