Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/python/cpython/src/__pycache__/cowasm_bundler.cpython-311.pyc
1067 views
�

���c����dZddlZddlZddlZddlZddlZddlZGd�dej��Zd�Z	e
dkr&e	ejdejdd���dSdS)	aN
Creates a "CoWasm bundle", which is a PyZipFile (so has pyc files),
plus we also include .so files and possibly some other extra files
on a case-by-case basis.  There is no version information, since that's
going to be in the npm package.json file, and obviously no architecture
since there is only one architecture.

The idea of making Python modules only available in maximally compiled
zip archive form is very inspired by Javascript web bundlers.  It is
is antithetical to how wheels, and Python packaging generally works!
But that is because the constraints are very, very different.
�Nc�*�eZdZd�Zdd�Zdd�Zd�ZdS)	�CoWasmBundlec�V�tjj|g|�Ri|��d|_d|_dS)N��	)�zipfile�	PyZipFile�__init__�debug�
compresslevel)�self�args�kwdss   ��/Users/wstein/build/cocalc/src/data/projects/2c9318d1-4f8b-4910-8da7-68a965514c95/cowasm-python/packages/cpython/src/cowasm_bundler.pyr
zCoWasmBundle.__init__s;����"�4�7�$�7�7�7�$�7�7�7���
�������Nc���tj|��}|rL||��sA|jr8tj�|��rdnd}t|�d|�d���dStj�|��\}}tj�|���r�tj�|d��}tj�|���r�|r|�d|��}n|}|jrtd|d|��ttj
|����}|�d��|D�]*}	tj�||	��}
tj�|	��\}}tj�|
��rVtj�tj�|
d����r|�
|
||�	����|d
krj|r%||
��s|jrtd|
z����|�|
|��}
|jrtd|
��|�|
|
����,dSdStj�|��d
d
krE|�||��}
|jrtd|
��|�||
��dSdS)N�path�file� z skipped by filterfuncz__init__.py�/�Adding package in�as��
filterfuncz.sozfile %r skipped by filterfunc�Addingr�Adding file)�os�fspathrr�isdir�print�split�join�isfile�sorted�listdir�remove�splitext�write_so�get_archive_name�write)r
�pathname�basenamer�label�dir�name�initname�dirlist�filenamer�root�ext�arcnames              rr)zCoWasmBundle.write_sos����9�X�&�&���	�j�j��2�2�	��z�
I�"$�'�-�-��"9�"9�E���v���u�u�u�h�h�h�G�H�H�H��F��G�M�M�(�+�+�	��T�
�7�=�=��"�"�%	*��w�|�|�H�m�<�<�H��w�~�~�h�'�'�
��$�*2�(�(�D�D�9�H�H�#�H��:�I��-�x��x�H�H�H� ���H�!5�!5�6�6�����}�-�-�-� '�2�2�H��7�<�<��(�;�;�D� "�� 0� 0�� :� :�I�D�#��w�}�}�T�*�*�2��7�>�>�"�'�,�,�t�]�*K�*K�L�L�7� �M�M� $�h�+5�*�7�7�7�����2�%�%�j�j��.>�.>�%�#�z�N� %�&E��&L� M� M� M�$�"&�"7�"7��h�"G�"G���:�5�!�(�G�4�4�4��
�
�4��1�1�1��#2�2�&��
�W�
�
�h�
'�
'��
*�e�
3�	*��+�+�H�h�?�?�G��z�
.��m�W�-�-�-��J�J�x��)�)�)�)�)�		*�	*rc�\�tj|��}tj�|���r*tj�|��\}}|r|�d|��}n|}|jrt
d|d|��ttj|����}|D]�}tj�	||��}tj�
|��\}}	tj�|��r|�||���z|�||��}
|jrt
d|
��|�
||
����dStj�	||��}
|jrt
d|
��|�
||
��dS)Nrrrrr)rrrr r"rr!r%r&r#r(�	write_allr*r+)r
r,r-�_r0r2r3rr4r5r6s           rr8zCoWasmBundle.write_allGs����9�X�&�&��
�7�=�=��"�"�	*��g�m�m�H�-�-�G�A�t��
$�&.�h�h���5���#���z�
E��)�8�T�8�D�D�D��R�Z��1�1�2�2�G�#�

.�

.���w�|�|�H�h�7�7���G�,�,�X�6�6�	��c��7�=�=��&�&�.��N�N�4��2�2�2�2�"�3�3�D�(�C�C�G��z�1��h��0�0�0��J�J�t�W�-�-�-�-�

.�

.��g�l�l�8�X�6�6�G��z�
.��m�W�-�-�-��J�J�x��)�)�)�)�)rc��tj�|��d}|r tj�||��}|S)Nr)rrr"r#)r
rr-r6s    rr*zCoWasmBundle.get_archive_namees<���'�-�-��%�%�a�(���	6��g�l�l�8�W�5�5�G��r)rN)r)�__name__�
__module__�__qualname__r
r)r8r*�rrrrs[���������
-*�-*�-*�-*�^*�*�*�*�<����rrc���d�}ttj��dtj���}|�||���|�||���|D]*}td|�d���|�|���+tj
|�d�d��}tj��}|���D]�}|�
d	��r�td
|�d���|�|��}tj��}	||	_t#|��|	_||	_|�|	tj|������dS)Nc�t�tj�|��}d|vp|�d��S)Nz/tests/�test_)rrr-�
startswith)�s�fns  r�notestszcreate_bundle.<locals>.notestsms5��
�W�
�
�a�
 �
 ���!�^�=�r�}�}�W�'=�'=�>�?r�w)�compressionrzIncluding extra '�'z.tar.xzzw:xzrzAdding ')r�io�BytesIOr�
ZIP_STORED�writepyr)r!r8�tarfile�open�time�namelist�endswith�read�TarInfor0�len�size�mtime�addfile)
r0�extra_filesrE�zip�extra�tar�nowr3�data�tarinfos
          r�
create_bundler_ksy��@�@�@��r�z�|�|��")�"4�6�6�6�C��K�K���K�)�)�)��L�L��'�L�*�*�*�����
�*�%�*�*�*�+�+�+��
�
�e������,�$�'�'�'��
0�
0�C�
�)�+�+�C��L�L�N�N�/�/�����S�!�!�+�8�
�$��$�$�$�%�%�%��x�x��!�!���/�#�#������4�y�y�����
����G�R�Z��-�-�.�.�.�.�/�/r�__main__r�)�__doc__rIr�sysrMrOrr	rr_r;�argvr>rr�<module>res�����+�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�X�X�X�X�X�7�$�X�X�X�t,/�,/�,/�^�z��-��M�#�(�1�+�s�x����|�,�,�,�,�,�-�-r