activator.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from __future__ import annotations
  2. import os
  3. from abc import ABC, abstractmethod
  4. class Activator(ABC):
  5. """Generates activate script for the virtual environment."""
  6. def __init__(self, options) -> None:
  7. """
  8. Create a new activator generator.
  9. :param options: the parsed options as defined within :meth:`add_parser_arguments`
  10. """
  11. self.flag_prompt = os.path.basename(os.getcwd()) if options.prompt == "." else options.prompt
  12. @classmethod
  13. def supports(cls, interpreter): # noqa: ARG003
  14. """
  15. Check if the activation script is supported in the given interpreter.
  16. :param interpreter: the interpreter we need to support
  17. :return: ``True`` if supported, ``False`` otherwise
  18. """
  19. return True
  20. @classmethod # noqa: B027
  21. def add_parser_arguments(cls, parser, interpreter):
  22. """
  23. Add CLI arguments for this activation script.
  24. :param parser: the CLI parser
  25. :param interpreter: the interpreter this virtual environment is based of
  26. """
  27. @abstractmethod
  28. def generate(self, creator):
  29. """
  30. Generate activate script for the given creator.
  31. :param creator: the creator (based of :class:`virtualenv.create.creator.Creator`) we used to create this \
  32. virtual environment
  33. """
  34. raise NotImplementedError
  35. __all__ = [
  36. "Activator",
  37. ]