def build(source_dir, target_dir, package_name=None, version_number=None):
source_dir = ph.path(source_dir).realpath()<EOL>target_dir = ph.path(target_dir).realpath()<EOL>target_dir.makedirs_p()<EOL>source_archive = source_dir.joinpath(source_dir.name + '<STR_LIT>')<EOL>if package_name is None:<EOL><INDENT>package_name = str(target_dir.name)<EOL><DEDENT>logger.info('<STR_LIT>', source_dir)<EOL>logger.info('<STR_LIT>', source_archive)<EOL>logger.info('<STR_LIT>', target_dir)<EOL>logger.info('<STR_LIT>', package_name)<EOL>original_dir = ph.path(os.getcwd())<EOL>try:<EOL><INDENT>os.chdir(source_dir)<EOL>sp.check_call(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', source_archive, '<STR_LIT>'],<EOL>shell=True)<EOL><DEDENT>finally:<EOL><INDENT>os.chdir(original_dir)<EOL><DEDENT>with zipfile.ZipFile(source_archive, '<STR_LIT:r>') as zip_ref:<EOL><INDENT>zip_ref.extractall(target_dir)<EOL><DEDENT>source_archive.remove()<EOL>target_dir.joinpath('<STR_LIT>').rmtree()<EOL>for p in target_dir.files('<STR_LIT>'):<EOL><INDENT>p.remove()<EOL><DEDENT>original_dir = ph.path(os.getcwd())<EOL>try:<EOL><INDENT>os.chdir(source_dir)<EOL>if version_number is None:<EOL><INDENT>import _version as v<EOL>version_info = {'<STR_LIT:version>': v.get_versions()['<STR_LIT:version>'],<EOL>'<STR_LIT>': v.get_versions()}<EOL><DEDENT>else:<EOL><INDENT>version_info = {'<STR_LIT:version>': version_number}<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>os.chdir(original_dir)<EOL><DEDENT>properties = {'<STR_LIT>': package_name,<EOL>'<STR_LIT>': str(target_dir.name)}<EOL>properties.update(version_info)<EOL>with target_dir.joinpath('<STR_LIT>').open('<STR_LIT:w>') as properties_yml:<EOL><INDENT>yaml.dump(properties, properties_yml, default_flow_style=False)<EOL><DEDENT>
Create a release of a MicroDrop plugin source directory in the target
directory path.

Skip the following patterns:

 - ``bld.bat``
 - ``.conda-recipe/*``
 - ``.git/*``

.. versionchanged:: 0.24.1
    Remove temporary archive after extraction.

    Change directory into source directory before running ``git archive``.

.. versionchanged:: 0.25
    Add optional :data:`version_number` argument.

Parameters
----------
source_dir : str
    Source directory.
target_dir : str
    Target directory.
package_name : str, optional
    Name of plugin Conda package (defaults to name of :data:`target_dir`).
version_number : str, optional
    Package version number.

    If not specified, assume version package exposes version using
    `versioneer <https://github.com/warner/python-versioneer>`_.