
    Zoc                        d 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	 ddl
mZ ddlmZ ddlmZ dZd	 Z G d
 de	      Z eed      s; ej(                  ej*                        d        Zej*                  e_        ee_        yy)a  :mod:`sassutils.distutils` --- :mod:`setuptools`/:mod:`distutils` integration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This module provides extensions (and some magical monkey-patches, sorry)
of the standard :mod:`distutils` and :mod:`setuptools` (now it's named
Distribute) for libsass.

To use this, add ``libsass`` into ``setup_requires`` (not ``install_requires``)
option of the :file:`setup.py` script::

    from setuptools import setup

    setup(
        # ...,
        setup_requires=['libsass >= 0.6.0']
    )

It will adds :class:`build_sass` command to the :file:`setup.py` script:

.. sourcecode:: console

   $ python setup.py build_sass

This commands builds Sass/SCSS files to compiled CSS files of the project
and makes the package archive (made by :class:`~distutils.command.sdist.sdist`,
:class:`~distutils.command.bdist.bdist`, and so on) to include these compiled
CSS files.

To set the directory of Sass/SCSS source files and the directory to
store compiled CSS files, specify ``sass_manifests`` option::

    from setuptools import find_packages, setup

    setup(
        name='YourPackage',
        packages=find_packages(),
        sass_manifests={
            'your.webapp': ('static/sass', 'static/css')
        },
        setup_requires=['libsass >= 0.6.0']
    )

The option should be a mapping of package names to pairs of paths, e.g.::

    {
        'package': ('static/sass', 'static/css'),
        'package.name': ('static/scss', 'static')
    }

The option can also be a mapping of package names to manifest dictionaries::

    {
        'package': {
            'sass_path': 'static/sass',
            'css_path': 'static/css',
            'strip_extension': True,
        },
    }

.. versionadded:: 0.15.0
    Added ``strip_extension`` so ``a.scss`` is compiled to ``a.css`` instead
    of ``a.scss.css``.  This option will default to ``True`` in the future.

.. versionadded:: 0.6.0
   Added ``--output-style``/``-s`` option to :class:`build_sass` command.

    N)Command)sdist   )Manifest)OUTPUT_STYLES)
build_sassvalidate_manifestsc                     	 t        j                  |       y# t        $ r/ t        j                  j                  |dz   t        |      z         w xY w)zkVerifies that ``value`` is an expected mapping of package to
    :class:`sassutils.builder.Manifest`.

    zmust be a mapping object like: {'package.name': sassutils.distutils.Manifest('sass/path')}, or as shorten form: {'package.name': ('sass/path', 'css/path'}), not N)r   normalize_manifests	TypeError	distutilserrorsDistutilsSetupErrorrepr)distattrvalues      5/usr/lib/python3/dist-packages/sassutils/distutils.pyr	   r	   U   sZ    

$$U+ 
22 @ @ K
 	

s	    8Ac                   \    e Zd ZdZeZddddj                  e      z   fgZd Zd Z	d Z
d	 Zy
)r   z$Builds Sass/SCSS files to CSS files.zoutput-style=sz4Coding style of the compiled result.  Choose one of z, c                      d | _         d| _        y )Nnested)package_diroutput_style)selfs    r   initialize_optionszbuild_sass.initialize_optionsq   s    $    c                     i | _         | j                  j                   r`i | _         | j                  j                   j                         D ]1  \  }}t        j                  j                  |      | j                   |<   3 y y N)r   distributionitemsr   utilconvert_path)r   namepaths      r   finalize_optionszbuild_sass.finalize_optionsu   so    ((!D"//;;AAC K
d)2)D)DT)J  &K )r   c                 D   | j                   j                  }t        j                  |      }|| j                   _        | j                   j                  }| j                   j
                  xs g }|j                         D ]  \  }}| j                  |      }t        j                  j                  d|       |j                  || j                        }t        t        j                  j                  |       |j                  |g       j                  |       |j!                  ||D cg c]"  }t"        j$                  j'                  ||      $ c}f        || j                   _        || j                   _        d | j                   _        || j                   _        y c c}w )Nzbuilding '%s' sass)r   c                       y)NT r)   r   r   <lambda>z build_sass.run.<locals>.<lambda>   s    r   )r    sass_manifestsr   r   package_data
data_filesr!   get_package_dirr   loginfobuildr   map
setdefaultextendappendosr%   joinhas_data_filescompiled_sass_files)	r   	manifestsr,   r-   package_namemanifestr   	css_filesfs	            r   runzbuild_sass.run|   s[   %%44	00;	+4(((55&&117R
&/oo&7 	"L(..|<KMM3\B !.. ' I 	""I.##L"5<<YG;DEaRWW\\+q1E	 *6&'1$+7(0:- Fs   &'Fc                    |j                  d      }| j                  s|rt        j                  j                  | S yg }|rM	 | j                  dj	                  |         }|j                  d|       t        j                  j                  | S | j                  j                  d      }||j                  d|       |rt        j                  j                  | S y# t        $ r |j                  d|d          |d= Y nw xY w|rŌy)a$  Returns the directory, relative to the top of the source
        distribution, where package ``package`` should be found
        (at least according to the :attr:`package_dir` option, if any).

        Copied from :meth:`distutils.command.build_py.get_package_dir()`
        method.

        . r   )splitr   r6   r%   r7   insertKeyErrorget)r   packager%   tailpdirs        r   r.   zbuild_sass.get_package_dir   s     }}S!ww||T**+''7
 At$ww||T**##''+DAt$ww||T**  AtBx(H s   C !D ?D N)__name__
__module____qualname____doc__descriptionr7   r   user_optionsr   r&   r?   r.   r)   r   r   r   r   e   sF    .K SBIIm$%	
L%K;6r   r   _wrapped_check_readmec                     	 | j                   j                  }|D ]   \  }}| j                  j                  |       " | j                         S # t        $ r Y | j                         S w xY wr   )r    r9   filelistr4   AttributeErrorrQ   )r   files_r=   s       r   check_readmerW      ss    	0%%99E !& 09$$Y/0))++  	 ))++	s   A 	A('A()rN   	functoolsos.pathr6   distutils.errorsr   distutils.logdistutils.util
setuptoolsr   setuptools.command.sdistr   builderr   sassr   __all__r	   r   hasattrwrapsrW   rQ   r)   r   r   <module>rd      s   DJ       *  
,
 P Pj u-.Y__U''(, ), #("4"4E%E /r   