import os
import re

from paver.easy import *
from paver.setuputils import setup

def get_version():
    """
    Grab the version from irclib.py.
    """
    here = os.path.dirname(__file__)
    irclib = os.path.join(here, 'irclib.py')
    with open(irclib) as f:
        content = f.read()
    VERSION = eval(re.search('VERSION = (.*)', content).group(1))
    VERSION = '.'.join(map(str, VERSION))
    return VERSION

def read_long_description():
    f = open('README')
    try:
        data = f.read()
    finally:
        f.close()
    return data

setup(
    name="python-irclib",
    description="IRC (Internet Relay Chat) protocol client library for Python",
    long_description=read_long_description(),
    version=get_version(),
    py_modules=["irclib", "ircbot"],
    author="Joel Rosdahl",
    author_email="joel@rosdahl.net",
    maintainer="Jason R. Coombs",
    maintainer_email="jaraco@jaraco.com",
    url="http://python-irclib.sourceforge.net",
    classifiers = [
        "Development Status :: 5 - Production/Stable",
        "Intended Audience :: Developers",
        "Programming Language :: Python :: 2.6",
        "Programming Language :: Python :: 2.7",
    ],
)

@task
@needs('generate_setup', 'minilib', 'distutils.command.sdist')
def sdist():
    "Override sdist to make sure the setup.py gets generated"

import os
import re

from paver.easy import *
from paver.setuputils import setup

def get_version():
    """
    Grab the version from irclib.py.
    """
    here = os.path.dirname(__file__)
    irclib = os.path.join(here, 'irclib.py')
    with open(irclib) as f:
        content = f.read()
    VERSION = eval(re.search('VERSION = (.*)', content).group(1))
    VERSION = '.'.join(map(str, VERSION))
    return VERSION

def read_long_description():
    with open('README') as f:
        data = f.read()
    return data

setup(
    name="python-irclib",
    description="IRC (Internet Relay Chat) protocol client library for Python",
    long_description=read_long_description(),
    version=get_version(),
    py_modules=["irclib", "ircbot"],
    author="Joel Rosdahl",
    author_email="joel@rosdahl.net",
    maintainer="Jason R. Coombs",
    maintainer_email="jaraco@jaraco.com",
    url="http://python-irclib.sourceforge.net",
    classifiers = [
        "Development Status :: 5 - Production/Stable",
        "Intended Audience :: Developers",
        "Programming Language :: Python :: 2.6",
        "Programming Language :: Python :: 2.7",
    ],
)

@task
@needs('generate_setup', 'minilib', 'distutils.command.sdist')
def sdist():
    "Override sdist to make sure the setup.py gets generated"

Use context manager to read README
Use context manager to read README

  import os
  import re
  
  from paver.easy import *
  from paver.setuputils import setup
  
  def get_version():
      """
      Grab the version from irclib.py.
      """
      here = os.path.dirname(__file__)
      irclib = os.path.join(here, 'irclib.py')
      with open(irclib) as f:
          content = f.read()
      VERSION = eval(re.search('VERSION = (.*)', content).group(1))
      VERSION = '.'.join(map(str, VERSION))
      return VERSION
  
  def read_long_description():
+     with open('README') as f:
-     f = open('README')
-     try:
          data = f.read()
-     finally:
-         f.close()
      return data
  
  setup(
      name="python-irclib",
      description="IRC (Internet Relay Chat) protocol client library for Python",
      long_description=read_long_description(),
      version=get_version(),
      py_modules=["irclib", "ircbot"],
      author="Joel Rosdahl",
      author_email="joel@rosdahl.net",
      maintainer="Jason R. Coombs",
      maintainer_email="jaraco@jaraco.com",
      url="http://python-irclib.sourceforge.net",
      classifiers = [
          "Development Status :: 5 - Production/Stable",
          "Intended Audience :: Developers",
          "Programming Language :: Python :: 2.6",
          "Programming Language :: Python :: 2.7",
      ],
  )
  
  @task
  @needs('generate_setup', 'minilib', 'distutils.command.sdist')
  def sdist():
      "Override sdist to make sure the setup.py gets generated"
  
Use context manager to read README
## Code Before:
import os
import re

from paver.easy import *
from paver.setuputils import setup

def get_version():
    """
    Grab the version from irclib.py.
    """
    here = os.path.dirname(__file__)
    irclib = os.path.join(here, 'irclib.py')
    with open(irclib) as f:
        content = f.read()
    VERSION = eval(re.search('VERSION = (.*)', content).group(1))
    VERSION = '.'.join(map(str, VERSION))
    return VERSION

def read_long_description():
    f = open('README')
    try:
        data = f.read()
    finally:
        f.close()
    return data

setup(
    name="python-irclib",
    description="IRC (Internet Relay Chat) protocol client library for Python",
    long_description=read_long_description(),
    version=get_version(),
    py_modules=["irclib", "ircbot"],
    author="Joel Rosdahl",
    author_email="joel@rosdahl.net",
    maintainer="Jason R. Coombs",
    maintainer_email="jaraco@jaraco.com",
    url="http://python-irclib.sourceforge.net",
    classifiers = [
        "Development Status :: 5 - Production/Stable",
        "Intended Audience :: Developers",
        "Programming Language :: Python :: 2.6",
        "Programming Language :: Python :: 2.7",
    ],
)

@task
@needs('generate_setup', 'minilib', 'distutils.command.sdist')
def sdist():
    "Override sdist to make sure the setup.py gets generated"

## Instruction:
Use context manager to read README
## Code After:
import os
import re

from paver.easy import *
from paver.setuputils import setup

def get_version():
    """
    Grab the version from irclib.py.
    """
    here = os.path.dirname(__file__)
    irclib = os.path.join(here, 'irclib.py')
    with open(irclib) as f:
        content = f.read()
    VERSION = eval(re.search('VERSION = (.*)', content).group(1))
    VERSION = '.'.join(map(str, VERSION))
    return VERSION

def read_long_description():
    with open('README') as f:
        data = f.read()
    return data

setup(
    name="python-irclib",
    description="IRC (Internet Relay Chat) protocol client library for Python",
    long_description=read_long_description(),
    version=get_version(),
    py_modules=["irclib", "ircbot"],
    author="Joel Rosdahl",
    author_email="joel@rosdahl.net",
    maintainer="Jason R. Coombs",
    maintainer_email="jaraco@jaraco.com",
    url="http://python-irclib.sourceforge.net",
    classifiers = [
        "Development Status :: 5 - Production/Stable",
        "Intended Audience :: Developers",
        "Programming Language :: Python :: 2.6",
        "Programming Language :: Python :: 2.7",
    ],
)

@task
@needs('generate_setup', 'minilib', 'distutils.command.sdist')
def sdist():
    "Override sdist to make sure the setup.py gets generated"
