o
    È6÷dŽ  ã                   @   st   d dl mZmZmZmZ d dlZd dlZd dlZd dlZd dl	Z	d dl
mZmZ G dd„ deƒZG dd„ deƒZdS )é    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literalsN)ÚBackendÚremove_aliases_from_apic                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚBackendExceptionz8Saves the traceback of an exception raised by a backend.c                    s   t t| ƒ ¡  || _|| _dS )z?
        :type backend_name: str
        :type tb: str
        N)Úsuperr   Ú__init__Úbackend_nameÚ	traceback)Úselfr   Útb©Ú	__class__© úeC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\stone/compiler.pyr
      s   
zBackendException.__init__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   Ú__classcell__r   r   r   r   r      s    r   c                   @   sH   e Zd ZdZdZ	ddd„Zdd„ Zedd	„ ƒZe	d
d„ ƒZ
dd„ ZdS )ÚCompilerzh
    Applies a collection of backends found in a single backend module to an
    API specification.
    z.stonegFc                 C   s\   t  d¡| _|| _|| _|| _|| _|r*tj 	| j¡r,t  
d| j¡ t | j¡ dS dS dS )aŽ  
        Creates a Compiler.

        :param stone.ir.Api api: A Stone description of the API.
        :param backend_module: Python module that contains at least one
            top-level class definition that descends from a
            :class:`stone.backend.Backend`.
        :param list(str) backend_args: A list of command-line arguments to
            pass to the backend.
        :param str build_path: Location to save compiled sources to. If None,
            source files are compiled into the same directories.
        :param bool clean_build: If True, the build_path is removed before
            source files are compiled into them.
        zstone.compilerz'Cleaning existing build directory %s...N)ÚloggingÚ	getLoggerÚ_loggerÚapiÚbackend_moduleÚbackend_argsÚ
build_pathÚosÚpathÚexistsÚinfoÚshutilÚrmtree)r   r   r   r   r   Zclean_buildr   r   r   r
   $   s   ÿýzCompiler.__init__c                 C   sD   t j | j¡rt j | j¡s| j d¡ dS t | j¡ |  	¡  dS )z5Creates outputs. Outputs are files made by a backend.z1Output path must be a folder if it already existsN)
r    r!   r"   r   Úisdirr   Úerrorr   Ú_mkdirÚ_execute_backend_on_spec)r   r   r   r   ÚbuildE   s
   zCompiler.buildc              
   C   sD   zt  | ¡ W dS  ty! } z|jdkr‚ W Y d}~dS d}~ww )zÆ
        Creates a directory at path if it doesn't exist. If it does exist,
        this function does nothing. Note that if path is a file, it will not
        be converted to a directory.
        é   N)r    ÚmakedirsÚOSErrorÚerrno)r!   Úer   r   r   r(   M   s   
ÿ€ÿzCompiler._mkdirc                 C   s*   t j |¡\}}t j |¡\}}|| jkS )zž
        Returns True if the file name matches the format of a stone backend,
        ie. its inner extension of "stoneg". For example: xyz.stoneg.py
        )r    r!   ÚsplitextÚbackend_extension)Úclsr!   Zpath_without_extÚ_Z
second_extr   r   r   Úis_stone_backendZ   s   
zCompiler.is_stone_backendc              	   C   s¶   d}t | jƒD ]Q}t| j|ƒ}t |¡rXt|tƒrXt |¡sX| j 	d|j
¡ || j| jƒ}|jr4| j}n	|s;t| jƒ}|}z| |¡ W q tyW   t|j
t ¡ dd… ƒ‚w qdS )z*Renders a source file into its final form.NzRunning backend: %séÿÿÿÿ)Údirr   ÚgetattrÚinspectÚisclassÚ
issubclassr   Ú
isabstractr   r#   r   r   r   Zpreserve_aliasesr   r   ÚgenerateÚ	Exceptionr   r   Ú
format_exc)r   Zapi_no_aliases_cacheZattr_keyÚ
attr_valueÚbackendr   r   r   r   r)   d   s0   
ÿþ
ÿü€ïz!Compiler._execute_backend_on_specN)F)r   r   r   r   r1   r
   r*   Ústaticmethodr(   Úclassmethodr4   r)   r   r   r   r   r      s    
û!

	r   )Ú
__future__r   r   r   r   r   r8   r    r$   r   Zstone.backendr   r   r=   r   Úobjectr   r   r   r   r   Ú<module>   s    