CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
github.cpython-310.pyc134 linesDownload Raw Back to __pycache__
1o

2��Yi�-�@sPddlZddlZddlZddlmZddlmZddlmZGdd�de�Z	dS)	�N�)�AbstractFileSystem��infer_storage_options�)�3MemoryFilecs�eZdZdZdZdZdZdZ	d&�fdd�	Ze	d	d4��Z5ed'dd
��Ze	dd��Z
e	dd��Ze	dd��Zd(dd�Zd)dd�Ze�fdd��Zedd��Z				d*dd�Zd(d d!�Zd)d"d#�Zd$d%�Z�ZS)+�GithubFileSystema�Interface to files in github6 7    An instance of this class provides the files residing within a remote github8    repository. You may specify a point in the repos history, by SHA, branch9    or tag (default is current master).10 11    For files less than 1 MB in size, file content is returned directly in a12    MemoryFile. For larger files, or for files tracked by git-lfs, file content13    is returned as an HTTPFile wrapping the ``download_url`` provided by the14    GitHub API.15 16    When using fsspec.open, allows URIs of the form:17 18    - "github://path/file", in which case you must specify org, repo and19      may specify sha in the extra args20    - 'github://org:repo@/precip/catalog.yml', where the org and repo are21      part of the URI22    - 'github://org:repo@sha/precip/catalog.yml', where the sha is also included23 24    ``sha`` can be the full or abbreviated hex of the commit you want to fetch25    from, or a branch or tag name (so long as it doesn't contain special characters26    like "/", "?", which would have to be HTTP-encoded).27 28    For authorised access, you must provide username and token, which can be made29    at https://github.com/settings/tokens30    z9https://api.github.com/repos/{org}/{repo}/git/trees/{sha}zChttps://api.github.com/repos/{org}/{repo}/contents/{path}?ref={sha}Zgithub)�<r	Ncs�t�jd	i|��||_||_|du|duArtd��||_||_|dur(||_|durJd}tj	|j31||d�fd|ji|j��}	|	��|	�
�d}||_|�d�zddlm}32|33d	i|��|_WdStypd|_YdSw)34Nz%Auth required both username and tokenz)https://api.github.com/repos/{org}/{repo}��org�repo�timeoutZdefault_branch�r)�HTTPFileSystem�)�super�__init__rr�35ValueError�username�tokenr
�requests�get�format�kw�raise_for_status�json�root�ls�httpr�http_fs�ImportError)�selfrr�sharrr
�kwargs�u�rr��	__class__r��E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\fsspec/implementations/github.pyr,s8���36�zGithubFileSystem.__init__cCs|jrd|j|jfiSiS)N�auth)rr�r!rrr(rJszGithubFileSystem.kwTcCs@tjdddg|�d|�d�|jd�}|��dd�|��D�S)	avList repo names for given org or user37 38        This may become the top level of the FS39 40        Parameters41        ----------42        org_or_user: str43            Name of the github org or user to query44        is_org: bool (default True)45            Whether the name is an organisation (True) or user (False)46 47        Returns48        -------49        List of string50        zhttps://api.github.com/ZusersZorgs�/z/repos)r
cS�g|]}|d�qS��namer)�.0rrrr(�51<listcomp>f�z*GithubFileSystem.repos.<locals>.<listcomp>)rrr
rr)�clsZorg_or_userZis_orgr%rrr(�reposPs�zGithubFileSystem.reposcC�Ftjd|j�d|j�d�fd|ji|j��}|��dd�|��D�S)zNames of tags in the repo�https://api.github.com/repos/r+z/tagsr
cSr,r-r�r/�trrr(r0qr1z)GithubFileSystem.tags.<locals>.<listcomp>�rrrrr
rrr�r!r%rrr(�tagsh����zGithubFileSystem.tagscCr4)zNames of branches in the repor5r+z	/branchesr
cSr,r-rr6rrr(r0|r1z-GithubFileSystem.branches.<locals>.<listcomp>r8r9rrr(�branchessr;zGithubFileSystem.branchescCs|j|jd�S)z#Named references, tags and branches�r:r<r=r*rrr(�refs~szGithubFileSystem.refsFc52s�|�����dkr|p
|j}|dura��d��d�}d�|p |j}|D]=}|j�d||d�}��r5d|n|7��fdd�|D�}|sGt���|d}|d	d53kr\|rX|gS�S|d}q#�|jvsm||jdfvr�tj|j	j54|j|j|d�fd
|j
i|j��}	|	jdkr�t���|	��d55dd����fdd�|	��dD�}||jdfvr�||j�<n|j�}|r�|Stdd�|D��S)a	List files at given path56 57        Parameters58        ----------59        path: str60            Location to list, relative to repo root61        detail: bool62            If True, returns list of dicts, one per file; if False, returns63            list of full filenames only64        sha: str (optional)65            List at the given point in the repo history, branch or tag name or commit66            SHA67        _sha: str (optional)68            List this specific tree object (used internally to descend into trees)69        rNr+T)r"�_shacsg|]70}|d�kr|�qSr-r)r/�o)�so_farrr(r0�sz'GithubFileSystem.ls.<locals>.<listcomp>r�type�filer")rrr"r
��	directory)Zblob�treec	sXg|](}|d�vr�r�d|dn|d|d�|d|�dd�|dd��qS)rBr+�path�mode�sizerr")r.rHrBrIr")r�r/�f)rG�typesrr(r0�s�7172�rFcSr,r-rrJrrr(r0�r1)�_strip_protocolr�rstrip�splitr�FileNotFoundError�dircacherr�urlrrrr
r�status_coderr�sorted)73r!rG�detailr"r?r#�parts�part�outr%r)rGrArLr(r�sR7475767778���798081�82�83zGithubFileSystem.lscCs|j��dS�N)rQ�clear)r!rGrrr(�invalidate_cache�sz!GithubFileSystem.invalidate_cachecs*t|�}d|vrt��|�S|d�d�S)NrrGr+)rrrM�lstrip)r2rG�optsr&rr(rM�sz GithubFileSystem._strip_protocolcCs>t|�}d|vr84iS|d|dd�}|dr|d|d<|S)Nr�passwordr85�hostr"r)rGr]rXrrr(�_get_kwargs_from_urls�sz&GithubFileSystem._get_kwargs_from_urls�rbcKs�|dkrt�|jj|j|j||p|jd�}tj|fd|ji|j	��}|j86dkr+t|��|��|�
�}	|	drIt�|	d�}87|88�d�sItdd|89�S|jdurRtd��|jj|	df|||d	�|��S)90Nra�rrrGr"r
rD�contents#version https://git-lfs.github.com/zRPlease install fsspec[http] to access github files >1 MB or git-lfs tracked files.Zdownload_url)rH�91block_size�
cache_options)�NotImplementedError�content_urlrrrrrrr
rrSrPrr�base64�	b64decode�92startswithrrr �open)r!rGrHrdrer"r#rRr%Zcontent_jsonrcrrr(�_open�s6	�939495����zGithubFileSystem._opencCs0|j|||d�}t|�D]	}|j||d�qdS)N)�	recursive�maxdepth)�message)Zexpand_path�reversed�rm_file)r!rGrmrnro�prrr(�rms�zGithubFileSystem.rmcKs$|jstd��|�|�}|�|�}|sC|jj|j|j|�d�|j	d�}t96j|fd|ji|j
��}|jdkr9t|��|��|��d}|jj|j|j||j	d�}|j	}|pYd|��|d�|rbd	|ini�}	t97j|f|	|jd98�|j
��}|���dd�}99t�d
|100�r�d}t|��|��|�|�dS)aW101        Remove a file from a specified branch using a given commit message.102 103        Since Github DELETE operation requires a branch name, and we can't reliably104        determine whether the provided SHA refers to a branch, tag, or commit, we105        assume it's a branch. If it's not, the user will encounter an error when106        attempting to retrieve the file SHA or delete the file.107 108        Parameters109        ----------110        path: str111            The file's location relative to the repository root.112        message: str, optional113            The commit message for the deletion.114        zAuthentication requiredr+rbr
rDr"zDelete )ror"�branch)rr
rorzBranch .+ not foundzTRemove only works when the filesystem is initialised from a branch or default (None)N)rrrM�_get_sha_from_cachergrrrr\rrrr
rrSrPrr�delete�re�searchr[)r!rGror#r"rRr%Z115delete_urlrt�data�
error_message�errorrrr(rqs:116117�118���zGithubFileSystem.rm_filecCsL|j��D]}|D]}|�d�}|r"||kr"d|vr"|dSq	qdS)Nr.r")rQ�valuesr)r!rG�entries�entry�119entry_pathrrr(ruGs120��z$GithubFileSystem._get_sha_from_cache)NNNN)T)FNNrY)raNNN)�__name__�121__module__�__qualname__�__doc__rRrg�protocolr
r�propertyr�classmethodr3r:r<r>rr[rM�staticmethodr`rlrsrqru�
__classcell__rrr&r(rs@�122123124 125126 127128129B13013113231336r)134rhrwr�specr�utilsrZmemoryrrrrrr(�<module>s
Aluode/PerceptionLabPortable · CoolFace