#
# to build the distrubution @ dist/cloudfeaster-*.*.*.tar.gz
#
#   >git clone https://github.com/simonsdave/cloudfeaster.git
#   >cd cloudfeaster
#   >source cfg4dev
#   >python setup.py sdist --formats=gztar
#
# update pypitest with both meta data and source distribution (FYI ...
# use of pandoc is as per https://github.com/pypa/pypi-legacy/issues/148#issuecomment-226939424
# since PyPI requires long description in RST but the repo's readme is in
# markdown)
#
#   >cat README.md | \
#       sed -e "s|(docs/|(https://github.com/simonsdave/cloudfeaster/blob/master/docs/|g" | \
#       pandoc -o README.rst
#   >python setup.py register -r pypitest
#   >twine upload dist/* -r pypitest
#
# now inspect https://testpypi.python.org/pypi/cloudfeaster
#
# use the package uploaded to pypitest
#
#   >pip install -i https://testpypi.python.org/pypi cloudfeaster
#
import re
import sys
from setuptools import setup

#
# this approach used below to determine ```version``` was inspired by
# https://github.com/kennethreitz/requests/blob/master/setup.py#L31
#
# why this complexity? wanted version number to be available in the
# a runtime.
#
# the code below assumes the distribution is being built with the
# current directory being the directory in which setup.py is stored
# which should be totally fine 99.9% of the time. not going to add
# the coode complexity to deal with other scenarios
#
reg_ex_pattern = r"__version__\s*=\s*['\"](?P<version>[^'\"]*)['\"]"
reg_ex = re.compile(reg_ex_pattern)
version = ""
with open("cloudfeaster/__init__.py", "r") as fd:
    for line in fd:
        match = reg_ex.match(line)
        if match:
            version = match.group("version")
            break
if not version:
    raise Exception("Can't locate cloudfeaster's version number")


_author = "Dave Simons"
_author_email = "simonsdave@gmail.com"


def _long_description():
    """Assuming the following command is used to register the package
        python setup.py register -r pypitest
    then sys.argv should be
        ['setup.py', 'register', '-r', 'pypitest']
    """
    if 2 <= len(sys.argv) and sys.argv[1] == 'register':
        with open('README.rst', 'r') as f:
            return f.read()

    return 'a long description'


setup(
    name="cloudfeaster",
    packages=[
        "cloudfeaster",
        "cloudfeaster.util",
        "cloudfeaster.samples",
    ],
    scripts=[
        "bin/spiderhost.py",
        "bin/spiderhost.sh",
        "bin/spiders.py",
    ],
    install_requires=[
        "colorama>=0.3.5",
        "jsonschema>=2.3.0",
        #
        # spiderhost.py uses requests to integration with SignalFX
        # without ndg-httpsclient running spiderhost.py would generate
        # SNIMissingWarning messages.
        #
        #   https://stackoverflow.com/questions/18578439/using-requests-with-tls-doesnt-give-sni-support/18579484#18579484
        #
        # the article below provides requests specific info on SNI
        #
        #   http://docs.python-requests.org/en/master/community/faq/
        #
        "ndg-httpsclient==0.4.3",
        "python-dateutil==2.6.1",
        "requests>=2.18.2",
        "selenium==3.7.0",
    ],
    include_package_data=True,
    version=version,
    description="Cloudfeaster",
    long_description=_long_description(),
    author=_author,
    author_email=_author_email,
    maintainer=_author,
    maintainer_email=_author_email,
    license="MIT",
    url="https://github.com/simonsdave/cloudfeaster",
    download_url="https://github.com/simonsdave/cloudfeaster/tarball/v%s" % version,
    keywords=[
        'selenium',
    ],
    classifiers=[
        "Development Status :: 5 - Production/Stable",
        "Intended Audience :: Developers",
        "Natural Language :: English",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
        "Programming Language :: Python",
        "Programming Language :: Python :: 2.7",
        "Programming Language :: Python :: Implementation :: CPython",
        "Topic :: Software Development :: Libraries :: Python Modules",
    ],
)

@@ -470,243 +470,176 @@
    %3E
-cat README.md %7C %5C%0A#       sed -e %22s%7C(docs/%7C(https://github.com/simonsdave/cloudfeaster/blob/master/docs/%7Cg%22 %7C %5C
+./.prep-for-release-release-branch-changes.sh
 %0A#   
-    
+%3E
 pandoc 
--o 
 README.
-rst%0A#   %3Epython setup.py register -r pypitest%0A#   %3Etwine upload dist/* -r pypitest%0A#%0A# now inspect
+md -o README.rst%0A#   %3Etwine upload dist/* -r testpypi%0A#%0A# you will be able to find the package at%0A#%0A#  
  htt
@@ -647,36 +647,33 @@
 s://test
+.
 pypi.
-python.org/pypi
+org/project
 /cloudfe
@@ -677,16 +677,17 @@
 dfeaster
+/
 %0A#%0A# use
@@ -691,24 +691,16 @@
 use the 
-package 
 uploaded
@@ -704,19 +704,15 @@
 ded 
-to pypitest
+package
 %0A#%0A#
@@ -746,20 +746,14 @@
 test
+.
 pypi.
-python.
 org/
@@ -1789,347 +1789,179 @@
     
-%22%22%22Assuming the following command is used to register the package%0A        python setup.py register -r pypitest%0A    then sys.argv should be%0A        %5B'setup.py', 'register
+try:%0A        with open('README.rst
 ', '
--
 r'
-, 'pypitest'%5D%0A    %22%22%22%0A    if 2 %3C= len(sys.argv) and sys.argv%5B1%5D == 'register':%0A        with open('README.rst', 'r') as f:%0A            return f.read()%0A%0A
+) as f:%0A            return f.read()%0A    except IOError:%0A        # simple fix for avoid failure on %22source cfg4dev%22%0A   
     
+ 
 return 
-'
+%22
 a lo
@@ -1974,17 +1974,17 @@
 cription
-'
+%22
 %0A%0A%0Asetup

refresh pypi docs in setup.py