sys
===

.. py:module:: sys


Attributes
----------

.. autoapisummary::

   sys.logger


Exceptions
----------

.. autoapisummary::

   sys.RewriteNodeError


Classes
-------

.. autoapisummary::

   sys.RewriteImportRule
   sys.RewriteImportNodeTransformer


Functions
---------

.. autoapisummary::

   sys.version
   sys.sanity_check
   sys.main
   sys.set_python_env
   sys.interpreter
   sys.python_script
   sys.is_console
   sys.relocate_python_distrib


Module Contents
---------------

.. py:data:: logger

.. py:exception:: RewriteNodeError

   Bases: :py:obj:`Exception`


   Common base class for all non-exit exceptions.


.. py:class:: RewriteImportRule(module: str, name: str = '.*', action: RuleAction | None = None)

   Rewrite Import node from AST.

   Skip or reject names imported by::

       from <module> import <names>

   or directly::

       import <module>


   .. py:class:: RuleAction(*args, **kwds)

      Bases: :py:obj:`enum.Enum`


      Possible rule actions when rewriting an import rule.


      .. py:attribute:: reject
         :value: 0



      .. py:attribute:: skip
         :value: 1




   .. py:attribute:: module


   .. py:attribute:: name
      :value: '.*'



   .. py:attribute:: action


   .. py:method:: rewrite_node(node: ast.stmt) -> ast.stmt

      Rewrite a node.

      :param node: ast node
      :return: a modified ast node



.. py:class:: RewriteImportNodeTransformer(rules: list[RewriteImportRule])

   Bases: :py:obj:`ast.NodeTransformer`


   Walk the AST applying a set of rules.

   Currently only the RewriteImportRule are supported.


   .. py:attribute:: rules


   .. py:method:: visit_ImportFrom(node: ast.stmt) -> ast.stmt


   .. py:method:: visit_Import(node: ast.stmt) -> ast.stmt


.. py:function:: version() -> str

.. py:function:: sanity_check() -> int

   Sanity check the E3 install.


.. py:function:: main() -> None

.. py:function:: set_python_env(prefix: str) -> None

   Set environment for a Python distribution.

   :param prefix: root directory of the python distribution


.. py:function:: interpreter(prefix: str | None = None) -> str

   Return location of the Python interpreter.

   When there are both a python3 and python binary file return the path to
   the python3 binary.

   :param prefix: root directory of the python distribution. if None location
       of the current interpreter is returned
   :return: python executable path


.. py:function:: python_script(name: str, prefix: str | None = None) -> list[str]

   Return path to scripts contained in this Python distribution.

   :param name: the script name
   :param prefix: root directory of the Python distribution. if None the
       distribution currently used by this script will be used
   :return: a list that will be the prefix of your command line


.. py:function:: is_console() -> bool

   Check if stdin is a console or not.

   :return: True if stdin is an interactive console


.. py:function:: relocate_python_distrib(python_distrib_dir: str | None = None, freeze: bool = False, platform: str | None = None) -> None

   Adjust shebangs to freeze a Python distrib or make it relocatable.

   :param python_distrib_dir: Python distrib prefix. If None the current
       Python is used.
   :param freeze: if True use absolute paths in shebangs. If not use relative paths.
   :param platform: if None use sys.platform. Otherwise should be a platform value
       as returned by sys.platform.


