# -*- coding: utf-8 -*-
# tifffile/setup.py

"""Tifffile package setuptools script."""

import sys
import re

from setuptools import setup

buildnumber = ''

imagecodecs = 'imagecodecs>=2019.1.20'

with open('tifffile/tifffile.py') as fh:
    code = fh.read()

version = re.search(r"__version__ = '(.*?)'", code).groups()[0]
version += ('.' + buildnumber) if buildnumber else ''

description = re.search(r'"""(.*)\.(?:\r\n|\r|\n)', code).groups()[0]

readme = re.search(r'(?:\r\n|\r|\n){2}"""(.*)"""(?:\r\n|\r|\n){2}from', code,
                   re.MULTILINE | re.DOTALL).groups()[0]

readme = '\n'.join([description, '=' * len(description)]
                   + readme.splitlines()[1:])

license = re.search(r'(# Copyright.*?(?:\r\n|\r|\n))(?:\r\n|\r|\n)+""', code,
                    re.MULTILINE | re.DOTALL).groups()[0]

license = license.replace('# ', '').replace('#', '')

if 'sdist' in sys.argv:
    with open('LICENSE', 'w') as fh:
        fh.write(license)
    with open('README.rst', 'w') as fh:
        fh.write(readme)

setup(
    name='tifffile',
    version=version,
    description=description,
    long_description=readme,
    author='Christoph Gohlke',
    author_email='cgohlke@uci.edu',
    url='https://www.lfd.uci.edu/~gohlke/',
    license='BSD',
    packages=['tifffile'],
    python_requires='>=2.7',
    install_requires=[
        'numpy>=1.11.3',
        'pathlib;python_version=="2.7"',
        'enum34;python_version=="2.7"',
        'futures;python_version=="2.7"',
        # require imagecodecs on Windows only
        imagecodecs + ';platform_system=="Windows"',
        ],
    extras_require={
        'all': ['matplotlib>=2.2', imagecodecs],
    },
    tests_require=['pytest', imagecodecs,
                   'czifile', 'cmapfile', 'oiffile', 'lfdfiles'],
    entry_points={
        'console_scripts': [
            'tifffile = tifffile:main',
            'lsm2bin = tifffile.lsm2bin:main'
            ]},
    platforms=['any'],
    classifiers=[
        'Development Status :: 4 - Beta',
        'License :: OSI Approved :: BSD License',
        'Intended Audience :: Science/Research',
        'Intended Audience :: Developers',
        'Operating System :: OS Independent',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        ],
)

@@ -684,16 +684,159 @@
 )%5B1:%5D)%0A%0A
+if 'sdist' in sys.argv:%0A    # update README, LICENSE, and CHANGES files%0A%0A    with open('README.rst', 'w') as fh:%0A        fh.write(readme)%0A%0A    
 license 
@@ -898,22 +898,16 @@
 %5Cn)+%22%22',
- code,
 %0A       
@@ -910,32 +910,42 @@
                 
+     code,
  re.MULTILINE %7C 
@@ -968,16 +968,20 @@
 s()%5B0%5D%0A%0A
+    
 license 
@@ -1026,39 +1026,230 @@
 ', '')%0A%0A
-if 'sdist' in sys.argv:
+    with open('LICENSE', 'w') as fh:%0A        fh.write(license)%0A%0A    revisions = re.search(r'(?:%5Cr%5Cn%7C%5Cr%7C%5Cn)%7B2%7D(Revisions.*)   %5C.%5C.%5C.', readme,%0A                          re.MULTILINE %7C re.DOTALL).groups()%5B0%5D.strip()%0A
 %0A    wit
@@ -1252,36 +1252,40 @@
  with open('
-LICENSE
+CHANGES.rst
 ', '
-w
+r
 ') as fh:%0A  
@@ -1290,33 +1290,94 @@
         
-fh.write(license)
+old = fh.read()%0A%0A    d = revisions.splitlines()%5B-1%5D%0A    old = old.split(d)%5B-1%5D
 %0A    wit
@@ -1376,38 +1376,39 @@
 %0A    with open('
-README
+CHANGES
 .rst', 'w') as f
@@ -1429,20 +1429,53 @@
 write(re
-adme
+visions.strip())%0A        fh.write(old
 )%0A%0Asetup

Update setup.py