# -*- coding: utf-8 -*-
# setup.py template made by the 'datafolder' package

# If you need help about packaging, read
# https://python-packaging-user-guide.readthedocs.org/en/latest/distributing.html

import subprocess
import sys
import pkg_resources

from setuptools import setup

from modified_mnist.bootdf import Installer, DataFolderException     # <-- ADAPT THIS

# write the name of the package (in this case 'mypkg'!)
MYPKG = 'modified_mnist'                                             # <-- ADAPT THIS

# mypkg supports these python versions
SUPPORT = ('3.1', '3.2', '3.3', '3.4', '3.5', '3.6')        # <-- ADAPT THIS

# list of data files in mypkg (just the names)
# [don't forget to include these files in MANIFEST.in!]
MYDATAFILES = ['t10k-images-idx3-ubyte',
               't10k-labels-idx1-ubyte',
               'train-images-idx3-ubyte',
               'train-labels-idx1-ubyte']


# (many people get confused with the next step...)


# tell setup were these files are in your package
# (I assume that they are together with the first __init__.py)
MYRESOURCES = [pkg_resources.resource_filename(MYPKG, datafile)
               for datafile in MYDATAFILES]

# now, create the installer
installer = Installer(sys.argv)

# use the installer to check supported python versions
installer.support(SUPPORT)

# checks if there are already data files and makes a backup
installer.backup(MYPKG, files=MYDATAFILES)

# create the data folder and tell setup to put the data files there
try:
    DATAPATH = installer.data_path(MYPKG)
    print("DATAPATHS IS", DATAPATH)
except DataFolderException:
    # here you can handle any exception raised with the creation
    # of the data folder, e.g., abort installation
    raise Exception('Abort installation!')
data_files = [(DATAPATH, MYRESOURCES)]
print("data_files issssss", data_files)
print("DATAPATH", DATAPATH)
print("resource:", MYRESOURCES[-1])
print(["cp", MYRESOURCES[0], DATAPATH])
if DATAPATH is not None:
    for MYRESOURCE in MYRESOURCES:
        subprocess.call(["cp", MYRESOURCE, DATAPATH])


# now, setup can do his thing...
setup(
    name=MYPKG,
    packages=[MYPKG],  # <-- ADAPT THIS
    data_files=data_files,
    author='William Harvey',                 # <-- ADAPT THIS
    author_email='...@...',    # <-- ADAPT THIS
    url='',                    # <-- ADAPT THIS
    license='',                # <-- ADAPT THIS
    description='',            # <-- ADAPT THIS
    classifiers=[
        'Programming Language :: Python',
        ...  # <-- ADAPT THIS (https://pypi.python.org/pypi?%3Aaction=list_classifiers)
    ]
)

# but we are NOT READY, in some cases the data files
# don't have the appropriate permissions and 'pip'
# overwrites all data files that have been
# previously installed (even if they have been changed!).
# By default '.conf', '.cfg', '.ini' and '.yaml' files
# are protected, you can change this by passing
# parameter 'fns', e.g. fns=('*.db','data.csv'), to 'pos_setup'.
installer.pos_setup(MYDATAFILES)
