
from paver.easy import error
import os.path

# ----------------------------------------------------------------------------
# UTILS:
# ----------------------------------------------------------------------------
def read_requirements(*filenames):
    """
    Read PIP "requirements*.txt" files.
    These files contains python package requirements.

    :param filenames:   List of requirement files to read.
    :returns: List of packages/package requirements (list-of-strings).
    """
    package_requirements = []
    for filename in filenames:
        if not os.path.exists(filename):
            error("REQUIREMENT-FILE %s not found" % filename)
            continue
        # -- NORMAL CASE:
        requirements_file = open(filename, "r")
        for line in requirements_file.readlines():
            line = line.strip()
            if not line or line.startswith("#"):
                continue    #< SKIP: EMPTY-LINE or COMMENT-LINE
            package_requirements.append(line)
        requirements_file.close()
    return package_requirements


from paver.easy import error
import os.path
import pkg_resources

# ----------------------------------------------------------------------------
# UTILS:
# ----------------------------------------------------------------------------
def read_requirements(*filenames):
    """
    Read PIP "requirements*.txt" files.
    These files contains python package requirements.

    :param filenames:   List of requirement files to read.
    :returns: List of packages/package requirements (list-of-strings).
    """
    package_requirements = []
    for filename in filenames:
        if not os.path.exists(filename):
            error("REQUIREMENT-FILE %s not found" % filename)
            continue
        # -- NORMAL CASE:
        with open(filename, "r") as f:
            requirements = pkg_resources.parse_requirements(f.read())
            package_requirements.extend(requirements)
#        # -- NORMAL CASE:
#        requirements_file = open(filename, "r")
#        for line in requirements_file.readlines():
#            line = line.strip()
#            if not line or line.startswith("#"):
#                continue    #< SKIP: EMPTY-LINE or COMMENT-LINE
#            package_requirements.append(line)
#        requirements_file.close()
    return package_requirements

Use pkg_resources.parse_requirements() to simplify parsing.
Use pkg_resources.parse_requirements() to simplify parsing.

  
  from paver.easy import error
  import os.path
+ import pkg_resources
  
  # ----------------------------------------------------------------------------
  # UTILS:
  # ----------------------------------------------------------------------------
  def read_requirements(*filenames):
      """
      Read PIP "requirements*.txt" files.
      These files contains python package requirements.
  
      :param filenames:   List of requirement files to read.
      :returns: List of packages/package requirements (list-of-strings).
      """
      package_requirements = []
      for filename in filenames:
          if not os.path.exists(filename):
              error("REQUIREMENT-FILE %s not found" % filename)
              continue
          # -- NORMAL CASE:
+         with open(filename, "r") as f:
+             requirements = pkg_resources.parse_requirements(f.read())
+             package_requirements.extend(requirements)
+ #        # -- NORMAL CASE:
-         requirements_file = open(filename, "r")
+ #        requirements_file = open(filename, "r")
-         for line in requirements_file.readlines():
+ #        for line in requirements_file.readlines():
-             line = line.strip()
+ #            line = line.strip()
-             if not line or line.startswith("#"):
+ #            if not line or line.startswith("#"):
-                 continue    #< SKIP: EMPTY-LINE or COMMENT-LINE
+ #                continue    #< SKIP: EMPTY-LINE or COMMENT-LINE
-             package_requirements.append(line)
+ #            package_requirements.append(line)
-         requirements_file.close()
+ #        requirements_file.close()
      return package_requirements
  
Use pkg_resources.parse_requirements() to simplify parsing.
## Code Before:

from paver.easy import error
import os.path

# ----------------------------------------------------------------------------
# UTILS:
# ----------------------------------------------------------------------------
def read_requirements(*filenames):
    """
    Read PIP "requirements*.txt" files.
    These files contains python package requirements.

    :param filenames:   List of requirement files to read.
    :returns: List of packages/package requirements (list-of-strings).
    """
    package_requirements = []
    for filename in filenames:
        if not os.path.exists(filename):
            error("REQUIREMENT-FILE %s not found" % filename)
            continue
        # -- NORMAL CASE:
        requirements_file = open(filename, "r")
        for line in requirements_file.readlines():
            line = line.strip()
            if not line or line.startswith("#"):
                continue    #< SKIP: EMPTY-LINE or COMMENT-LINE
            package_requirements.append(line)
        requirements_file.close()
    return package_requirements

## Instruction:
Use pkg_resources.parse_requirements() to simplify parsing.
## Code After:

from paver.easy import error
import os.path
import pkg_resources

# ----------------------------------------------------------------------------
# UTILS:
# ----------------------------------------------------------------------------
def read_requirements(*filenames):
    """
    Read PIP "requirements*.txt" files.
    These files contains python package requirements.

    :param filenames:   List of requirement files to read.
    :returns: List of packages/package requirements (list-of-strings).
    """
    package_requirements = []
    for filename in filenames:
        if not os.path.exists(filename):
            error("REQUIREMENT-FILE %s not found" % filename)
            continue
        # -- NORMAL CASE:
        with open(filename, "r") as f:
            requirements = pkg_resources.parse_requirements(f.read())
            package_requirements.extend(requirements)
#        # -- NORMAL CASE:
#        requirements_file = open(filename, "r")
#        for line in requirements_file.readlines():
#            line = line.strip()
#            if not line or line.startswith("#"):
#                continue    #< SKIP: EMPTY-LINE or COMMENT-LINE
#            package_requirements.append(line)
#        requirements_file.close()
    return package_requirements
