# Always prefer setuptools over distutils
from setuptools import setup
# To use a consistent encoding
from codecs import open
from os import path

import json
import re

here = path.abspath(path.dirname(__file__))

# get the long description from the readme file
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
    long_description = f.read()

runtime_reqs = ['datadog_checks_base']
with open(path.join(here, 'requirements.txt'), encoding='utf-8') as f:
    for line in f.readlines():
        line = line.strip()
        if not line or line.startswith('--hash') or line[0] == '#':
            continue
        req = line.rpartition('#')
        if not len(req[1]):
            if '--hash=' in req[2]:
                tokens = req[2].split()
                if len(tokens) > 1:
                    runtime_reqs.append(tokens[0])
            elif ';' in req[2]:
                runtime_reqs.append(req[2])
        else:
            runtime_reqs.append(req[0])

def read(*parts):
    with open(path.join(here, *parts), 'r') as fp:
        return fp.read()

def find_version(*file_paths):
    version_file = read(*file_paths)
    version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
                              version_file, re.M)
    if version_match:
        return version_match.group(1)
    raise RuntimeError("Unable to find version string.")

# https://packaging.python.org/guides/single-sourcing-package-version/
version = find_version("datadog_checks", "dns_check", "__init__.py")

manifest_version = None
with open(path.join(here, 'manifest.json'), encoding='utf-8') as f:
    manifest = json.load(f)
    manifest_version = manifest.get('version')

if version != manifest_version:
    raise Exception("Inconsistent versioning in module and manifest - aborting wheel build")

setup(
    name='datadog-dns_check',
    version=version,
    description='The DNS check',
    long_description=long_description,
    keywords='datadog agent dns_check check',

    # The project's main homepage.
    url='https://github.com/DataDog/integrations-core',

    # Author details
    author='Datadog',
    author_email='packages@datadoghq.com',

    # License
    license='MIT',

    # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'Intended Audience :: System Administrators',
        'Topic :: System :: Monitoring',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
    ],

    # The package we're going to ship
    packages=['datadog_checks.dns_check'],

    # Run-time dependencies
    install_requires=list(set(runtime_reqs)),

    # Development dependencies, run with:
    # $ pip install -e .[dev]
    extras_require={
        'dev': [
            'check-manifest',
            'datadog_agent_tk>=5.15',
        ],
    },

    # Testing setup and dependencies
    tests_require=[
        'nose',
        'coverage',
        'datadog_agent_tk>=5.15',
    ],
    test_suite='nose.collector',

    # Extra files to ship with the wheel package
    package_data={b'datadog_checks.dns_check': ['conf.yaml.example']},
    include_package_data=True,
)

@@ -208,16 +208,504 @@
 le__))%0A%0A
+def parse_req_line(line):%0A    line = line.strip()%0A    if not line or line.startswith('--hash') or line%5B0%5D == '#':%0A        return None%0A    req = line.rpartition('#')%0A    if len(req%5B1%5D) == 0:%0A        line = req%5B2%5D.strip()%0A    else:%0A        line = req%5B1%5D.strip()%0A%0A    if '--hash=' in line:%0A        line = line%5B:line.find('--hash=')%5D.strip()%0A    if ';' in line:%0A        line = line%5B:line.find(';')%5D.strip()%0A    if '%5C%5C' in line:%0A        line = line%5B:line.find('%5C%5C')%5D.strip()%0A%0A    return line%0A%0A
 # get th
@@ -841,16 +841,37 @@
 read()%0A%0A
+# Parse requirements%0A
 runtime_
@@ -1015,431 +1015,49 @@
     
-line = line.strip()%0A        if not line or line.startswith('--hash') or line%5B0%5D == '#':%0A            continue%0A        req = line.rpartition('#')%0A        if not len(req%5B1%5D):%0A            if '--hash=' in req%5B2%5D:%0A                tokens = req%5B2%5D.split()%0A                if len(tokens) %3E 1:%0A                    runtime_reqs.append(tokens%5B0%5D)%0A            elif ';' in req%5B2%5D:%0A                runtime_reqs.append(req%5B2%5D)%0A        else
+req = parse_req_line(line)%0A        if req
 :%0A  
@@ -1089,19 +1089,16 @@
 pend(req
-%5B0%5D
 )%0A%0Adef r

Fix parsing of requirements file so that `dnspython` is listed as a req (#1603)