o
    WiP                     @  s   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dl
mZ d dl
mZ d d	lmZ d d
lmZ dZe	jZe	jZd'ddZd(ddZejd)d!d"Zd*d%d&ZdS )+    )annotationsN)	Generator)Sequence)	lang_base)
envcontext)PatchesTUNSET)Prefix)cmd_output_bjuliaenvprefixr
   entrystrargsSequence[str]	file_argsis_localboolrequire_serialcolorreturntuple[int, bytes]c          	      C  sP   t ||}|r|d n| |d }dd|g|dd  R }t j||||dS )Nr   julia--startup-file=no   )r   r   )r   hook_cmdpath	run_xargs)	r   r   r   r   r   r   r   cmdscript r!   N/home/ubuntu/.local/lib/python3.10/site-packages/pre_commit/languages/julia.pyrun_hook   s   r#   
target_dirversionr   c                 C  s   d| fdt ffS )NJULIA_LOAD_PATHJULIA_PROJECTr   )r$   r%   r!   r!   r"   get_env_patch1   s   r(   Generator[None]c                 c  sJ    t | t|}tt|| d V  W d    d S 1 sw   Y  d S )N)r   environment_dirENVIRONMENT_DIRr   r(   )r   r%   envdirr!   r!   r"   in_env9   s
   "r-   additional_dependenciesNonec                 C  s   t | t|}t| |g tj|dd d}d}|D ]}| |}tj|s(qt	|| d} |s?t
tj|dd  d}|D ]}	| |	}
tj|
sQqCt	|
|  d}td	d
d|d|g|R d| ji W d    d S 1 svw   Y  d S )NT)exist_ok)zJuliaProject.tomlProject.tomlFr1   a)zJuliaManifest.tomlzManifest.tomla  
        @assert length(ARGS) > 0
        hook_env = ARGS[1]
        deps = join(ARGS[2:end], " ")

        # We prepend @stdlib here so that we can load the package manager even
        # though `get_env_patch` limits `JULIA_LOAD_PATH` to just the hook env.
        pushfirst!(LOAD_PATH, "@stdlib")
        using Pkg
        popfirst!(LOAD_PATH)

        # Instantiate the environment shipped with the hook repo. If we have
        # additional dependencies we disable precompilation in this step to
        # avoid double work.
        precompile = isempty(deps) ? "1" : "0"
        withenv("JULIA_PKG_PRECOMPILE_AUTO" => precompile) do
            Pkg.instantiate()
        end

        # Add additional dependencies (with precompilation)
        if !isempty(deps)
            withenv("JULIA_PKG_PRECOMPILE_AUTO" => "1") do
                Pkg.REPLMode.pkgstr("add " * deps)
            end
        end
        r   r   z-ez--cwd)r   r*   r+   r-   osmakedirsr   isfileshutilcopyopenjoincloser   
prefix_dir)r   r%   r.   r,   project_namesproject_foundproject_nameproject_filemanifest_namesmanifest_namemanifest_file
julia_coder!   r!   r"   install_environment@   s<   

"rE   )r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r$   r   r%   r   r   r   )r   r
   r%   r   r   r)   )r   r
   r%   r   r.   r   r   r/   )
__future__r   
contextlibr4   r7   collections.abcr   r   
pre_commitr   pre_commit.envcontextr   r   r	   pre_commit.prefixr
   pre_commit.utilr   r+   basic_health_checkhealth_checkbasic_get_default_versionget_default_versionr#   r(   contextmanagerr-   rE   r!   r!   r!   r"   <module>   s(    

