import re
import sys
from setuptools import setup, find_packages


def get_version():
    version_re = r"^__version__\s+=\s+['\"]([^'\"]*)['\"]"
    version = None

    package_init = 'openquake/engine/__init__.py'
    for line in open(package_init, 'r'):
        version_match = re.search(version_re, line, re.M)
        if version_match:
            version = version_match.group(1)
            break
    else:
        sys.exit('__version__ variable not found in %s' % package_init)

    return version

version = get_version()

url = "https://github.com/gem/oq-engine"

README = """
OpenQuake is an open source application that allows users to
compute seismic hazard and seismic risk of earthquakes on a global scale.

Please note: the /usr/bin/oq-engine script requires a celeryconfig.py
file in the PYTHONPATH.  Please make sure this is the case and that your
celeryconfig.py file works with your python-celery setup.

Feel free to copy /usr/share/engine/celeryconfig.py and revise it
as needed.

Copyright (C) 2010-2015, GEM Foundation.
"""

PY_MODULES = ['openquake.engine.bin.openquake_cli']

setup(
    entry_points={
        "console_scripts": [
            "oq-engine = openquake.engine.bin.openquake_cli:main"
        ]
    },
    name="openquake.engine",
    version=version,
    author="The OpenQuake team",
    author_email="devops@openquake.org",
    description=("Computes hazard, risk and socio-economic impact of "
                 "earthquakes."),
    license="AGPL3",
    keywords="earthquake seismic hazard risk",
    url=url,
    long_description=README,
    classifiers=[
        "Development Status :: 4 - Beta",
        "Topic :: Scientific/Engineering",
    ],
    packages=find_packages(exclude=["qa_tests", "qa_tests.*",
                                    "tools",
                                    "openquake.engine.bin",
                                    "openquake.engine.bin.*"]),
    py_modules=PY_MODULES,

    include_package_data=True,
    package_data={"openquake.engine": [
        "db/schema/upgrades/*.sql",
        "openquake.cfg", "openquake_worker.cfg", "README", "LICENSE"],
        "openquake.server": [
        "templates/*.html", "templates/*/*.html", "static/css/*.css",
        "static/*/*.js", "static/*/*/*.js", "static/*/*/*/*.js",
        "static/*/*.map", "static/*/*/*.map", "static/*/*/*/*.map",
        "static/font/*.ttf", "static/font/*.css", "static/img/*.png"]},
    scripts=["openquake/engine/bin/oq_create_db",
             "openquake/engine/bin/openquake"],

    namespace_packages=['openquake'],

    zip_safe=False,
    )

@@ -1975,460 +1975,8 @@
 ue,%0A
-    package_data=%7B%22openquake.engine%22: %5B%0A        %22db/schema/upgrades/*.sql%22,%0A        %22openquake.cfg%22, %22openquake_worker.cfg%22, %22README%22, %22LICENSE%22%5D,%0A        %22openquake.server%22: %5B%0A        %22templates/*.html%22, %22templates/*/*.html%22, %22static/css/*.css%22,%0A        %22static/*/*.js%22, %22static/*/*/*.js%22, %22static/*/*/*/*.js%22,%0A        %22static/*/*.map%22, %22static/*/*/*.map%22, %22static/*/*/*/*.map%22,%0A        %22static/font/*.ttf%22, %22static/font/*.css%22, %22static/img/*.png%22%5D%7D,%0A
     

move package data to MANIFEST.in