def generateRequirementsTxt(packages):
    """
        generateRequirementsTxt - Generates a requirements.txt suitable for pip to ingest based on packages param.

            @param packages - Describes the required packages. Takes one of the following forms:

                String - Directly becomes contents of requirements.txt file to be ingested by pip
                List   - A list/tuple/set of package names (optionally including version requirements, e.x. MyPkg==1.2.3)
                Dict   - A dictionary of package names to versions. If no value is present, the latest will be fetched.

            @return <str> - generated requirements.txt file contents
    """
    if not packages:
        reqContents = ''
    elif isinstance(packages, (list, tuple, set)):
        reqContents = '\n'.join(packages)
    elif isinstance(packages, dict):
        reqContents = []
        for name, value in packages.items():
            if not name:
                raise ValueError('Missing name in packages dictionary.')
            if value:
                reqContents.append('%s==%s' % (str(name), str(value)))
            else:
                reqContents.append('%s' % (str(name),))
        reqContents = '\n'.join(reqContents)
    else:
        reqContents = packages
    return reqContents
