__init__.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from __future__ import annotations
  2. import os
  3. from typing import TYPE_CHECKING
  4. from virtualenv.activation.via_template import ViaTemplateActivator
  5. if TYPE_CHECKING:
  6. from collections.abc import Iterator
  7. from python_discovery import PythonInfo
  8. from virtualenv.create.creator import Creator
  9. class BatchActivator(ViaTemplateActivator):
  10. @classmethod
  11. def supports(cls, interpreter: PythonInfo) -> bool:
  12. return interpreter.os == "nt"
  13. def templates(self) -> Iterator[str]:
  14. yield "activate.bat"
  15. yield "deactivate.bat"
  16. yield "pydoc.bat"
  17. @staticmethod
  18. def quote(string: str) -> str:
  19. return string
  20. def instantiate_template(self, replacements: dict[str, str], template: str, creator: Creator) -> str:
  21. # ensure the text has all newlines as \r\n - required by batch
  22. base = super().instantiate_template(replacements, template, creator)
  23. return base.replace(os.linesep, "\n").replace("\n", os.linesep)
  24. __all__ = [
  25. "BatchActivator",
  26. ]