관리-도구
편집 파일: golang.cpython-38.pyc
U ,�e� � @ s d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl Z d dl Z d dlZd dlZ d dlZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d lmZ d d lmZ d dlmZ d dlm Z d d l!m"Z" d dl!m#Z# dZ$ej%Z&ej'Z(dddddd�Z)e�*� �+� Z,e)�-e,e,�Z,G dd� de�Z.e jdk�rrdZ/ddd�dd�Z0ndZ/ddd�dd�Z0ej1d d!�d"d#�d$d%��Z2d"d"d&d'�d(d)�Z3ej1d"d"d*�d+d,��Z4d"d"d*�d-d.�Z5d"d"d/d0�d1d2�Z6ej7d3d"d4d5�d6d7��Z8d3d"d8d/d9�d:d;�Z9dS )<� )�annotationsN)�ContextManager)� Generator)�IO)�Protocol)�Sequence)� lang_base)� envcontext)�PatchesT)�Var)�Prefix)� cmd_output)�rmtreeZ golangenv�amd64Z386�arm64Zarmv6l)�x86_64�i386�aarch64Zarmv8�armv7lc @ s e Zd Zddd�dd�ZdS )� ExtractAll�str�None)�path�returnc C s d S �N� )�selfr r r �I/opt/hc_python/lib/python3.8/site-packages/pre_commit/languages/golang.py� extractall. � zExtractAll.extractallN)�__name__� __module__�__qualname__r r r r r r - s r �win32�zipz IO[bytes]zContextManager[ExtractAll])�bior c C s t �| �S r )�zipfile�ZipFile�r% r r r � _open_archive4 s r) ztar.gzc C s t j| d�S )N)�fileobj)�tarfile�openr( r r r r) 9 s � )�maxsizer )r c C s t �d�rdS tjS d S )N�go�system)r Z exe_exists�C�DEFAULTr r r r �get_default_version= s r3 r )�venv�versionr c C sj |dkr(dt j�| d�t jtd�fffS dt j�| d�fdt j�| d�t jt j�| dd�t jtd�fffS )Nr0 �PATH�bin�GOROOT�.go)�osr �join�pathsepr )r4 r5 r r r � get_env_patchE s � ���r= )r5 r c C s4 | t jkr| S tj�d�}t�|�d d dd � S )Nzhttps://go.dev/dl/?mode=jsonr r5 � )r1 r2 �urllib�request�urlopen�json�load)r5 �respr r r �_infer_go_versionV s rE c C s0 t �� �� }t| �} d| � d|� dt� dt� �S )Nzhttps://dl.google.com/go/go�.�-)�platformr0 �lowerrE �_ARCH�_EXT)r5 �os_namer r r �_get_url_ s rM r )r5 �destr c C s� zt j�t| ��}W nT t jjk rh } z2|jdkrVtdt� � � � � dt� d��|�n� W 5 d }~X Y njX t� � �:}t�||� |�d� t|��}|�|� W 5 Q R X W 5 Q R X t�tj�|d�tj�|d�� d S )Ni� z?Could not find a version matching your system requirements (os=z; arch=�)r r/ r9 )r? r@ rA rM �error� HTTPError�code� ValueErrorrH r0 rI rJ �tempfile� TemporaryFile�shutil�copyfileobj�seekr) r �mover: r r; )r5 rN rD �e�f�archiver r r �_install_goe s �� r] r zGenerator[(None, None, None)])�prefixr5 r c c s2 t �| t|�}tt||��� d V W 5 Q R X d S r )r �environment_dir�ENVIRONMENT_DIRr r= )r^ r5 Zenvdirr r r �in_envz s ra z Sequence[str])r^ r5 �additional_dependenciesr c C s� t �| t|�}|dkr t||� tjdkr@tdd|�d �� }n|}tt j |d�}|�dd � |dkr�t j� |d�|d <