# Copyright (c) 2008-2015 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Setup script for installing MetPy."""

from __future__ import print_function

import sys

from setuptools import Command, find_packages, setup
import versioneer


class MakeExamples(Command):
    """Create example scripts from IPython notebooks."""

    description = __doc__
    user_options = []

    def initialize_options(self):
        """Initialize command options (unused)."""
        pass

    def finalize_options(self):
        """Finalize command options (unused)."""
        pass

    def run(self):
        """Run the command."""
        import glob
        import os
        import os.path
        from nbconvert.exporters import python
        from traitlets.config import Config
        examples_dir = os.path.join(os.path.dirname(__file__), 'examples')
        script_dir = os.path.join(examples_dir, 'scripts')
        if not os.path.exists(script_dir):
            os.makedirs(script_dir)
        c = Config({'Exporter': {'template_file': 'examples/python-scripts.tpl'}})
        exporter = python.PythonExporter(config=c)
        for fname in glob.glob(os.path.join(examples_dir, 'notebooks', '*.ipynb')):
            output, _ = exporter.from_filename(fname)
            out_fname = os.path.splitext(os.path.basename(fname))[0]
            out_name = os.path.join(script_dir, out_fname + '.py')
            print(fname, '->', out_name)  # noqa: T003
            with open(out_name, 'w') as outf:
                outf.write(output)


ver = versioneer.get_version()
commands = versioneer.get_cmdclass()
commands.update(examples=MakeExamples)

# Need to conditionally add enum support for older Python
dependencies = ['matplotlib>=1.4', 'numpy>=1.9.1', 'scipy>=0.14', 'pint>=0.6']
if sys.version_info < (3, 4):
    dependencies.append('enum34')

setup(
    name='MetPy',
    version=ver,
    description='Collection of tools for reading, visualizing and'
                'performing calculations with weather data.',
    long_description='The space MetPy aims for is GEMPAK '
                     '(and maybe NCL)-like functionality, in a way that '
                     'plugs easily into the existing scientific Python '
                     'ecosystem (numpy, scipy, matplotlib).',

    url='http://github.com/Unidata/MetPy',

    author='Ryan May, Patrick Marsh, Sean Arms, Eric Bruning',
    author_email='python-users@unidata.ucar.edu',
    maintainer='MetPy Developers',
    maintainer_email='python-users@unidata.ucar.edu',

    license='BSD',

    classifiers=['Development Status :: 3 - Alpha',
                 'Programming Language :: Python :: 2',
                 'Programming Language :: Python :: 2.7',
                 'Programming Language :: Python :: 3',
                 'Programming Language :: Python :: 3.3',
                 'Programming Language :: Python :: 3.4',
                 'Programming Language :: Python :: 3.5',
                 'Topic :: Scientific/Engineering',
                 'Intended Audience :: Science/Research',
                 'Operating System :: OS Independent',
                 'License :: OSI Approved :: BSD License'],
    keywords='meteorology weather',

    packages=find_packages(exclude=['doc', 'examples']),
    package_data={'metpy.plots': ['colortables/*.tbl', 'nexrad_tables/*.tbl',
                                  'fonts/*.ttf']},

    install_requires=dependencies,
    extras_require={
        'cdm': ['pyproj>=1.9.4'],
        'dev': ['ipython[all]>=3.1'],
        'doc': ['sphinx>=1.3', 'ipython[all]>=3.1'],
        'examples': ['cartopy>=0.13.1'],
        'test': ['pytest>=2.4', 'pytest-runner', 'pytest-mpl', 'pytest-flake8',
                 'flake8>3.2.0', 'flake8-builtins',
                 'flake8-comprehensions', 'flake8-copyright',
                 'flake8-docstrings', 'flake8-import-order', 'flake8-mutable',
                 'flake8-pep3101', 'flake8-print', 'flake8-quotes',
                 'pep8-naming']
    },

    cmdclass=commands,

    zip_safe=True,

    download_url='https://github.com/Unidata/MetPy/archive/v{}.tar.gz'.format(ver),)

@@ -255,17 +255,8 @@
 port
- Command,
  fin
@@ -296,1405 +296,37 @@
 er%0A%0A
-%0Aclass MakeExamples(Command):%0A    %22%22%22Create example scripts from IPython notebooks.%22%22%22%0A%0A    description = __doc__%0A    user_options = %5B%5D%0A%0A    def initialize_options(self):%0A        %22%22%22Initialize command options (unused).%22%22%22%0A        pass%0A%0A    def finalize_options(self):%0A        %22%22%22Finalize command options (unused).%22%22%22%0A        pass%0A%0A    def run(self):%0A        %22%22%22Run the command.%22%22%22%0A        import glob%0A        import os%0A        import os.path%0A        from nbconvert.exporters import python%0A        from traitlets.config import Config%0A        examples_dir = os.path.join(os.path.dirname(__file__), 'examples')%0A        script_dir = os.path.join(examples_dir, 'scripts')%0A        if not os.path.exists(script_dir):%0A            os.makedirs(script_dir)%0A        c = Config(%7B'Exporter': %7B'template_file': 'examples/python-scripts.tpl'%7D%7D)%0A        exporter = python.PythonExporter(config=c)%0A        for fname in glob.glob(os.path.join(examples_dir, 'notebooks', '*.ipynb')):%0A            output, _ = exporter.from_filename(fname)%0A            out_fname = os.path.splitext(os.path.basename(fname))%5B0%5D%0A            out_name = os.path.join(script_dir, out_fname + '.py')%0A            print(fname, '-%3E', out_name)  # noqa: T003%0A            with open(out_name, 'w') as outf:%0A                outf.write(output)%0A%0A%0Aver = versioneer.get_version()%0Acommands = versioneer.get_cmdclass()%0Acommands.update(examples=MakeExamples
+ver = versioneer.get_version(
 )%0A%0A#
@@ -2698,16 +2698,33 @@
 ass=
-commands
+versioneer.get_cmdclass()
 ,%0A%0A 

Remove setup.py command for examples.