# Buggy code
def sync(
    to_install,
    to_uninstall,
    verbose=False,
    dry_run=False,
    pip_flags=None,
    install_flags=None,
):
    """
    Install and uninstalls the given sets of modules.
    """
    if not to_uninstall and not to_install:
        click.echo("Everything up-to-date")

    if pip_flags is None:
        pip_flags = []

    if not verbose:
        pip_flags += ["-q"]

    if os.environ.get("VIRTUAL_ENV"):
        # find pip via PATH
        pip = "pip"
    else:
        # find pip in same directory as pip-sync entry-point script
        pip = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), "pip")

    if to_uninstall:
        if dry_run:
            click.echo("Would uninstall:")
            for pkg in to_uninstall:
                click.echo("  {}".format(pkg))
        else:
            check_call([pip, "uninstall", "-y"] + pip_flags + sorted(to_uninstall))

    if to_install:
        if install_flags is None:
            install_flags = []
        if dry_run:
            click.echo("Would install:")
            for ireq in to_install:
                click.echo("  {}".format(format_requirement(ireq)))
        else:
            package_args = []
            for ireq in sorted(to_install):
                if ireq.editable:
                    package_args.extend(["-e", str(ireq.link or ireq.req)])
                else:
                    package_args.append(str(ireq.req))
            check_call([pip, "install"] + pip_flags + install_flags + package_args)
    return 0


# Traceback (TypeError)
$ venv/bin/pip-sync dev-requirements.txt
Traceback (most recent call last):
File "venv/bin/pip-sync", line 11, in <module>
sys.exit(cli())
File "venv/lib64/python3.6/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "venv/lib64/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "venv/lib64/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "venv/lib64/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "venv/lib64/python3.6/site-packages/piptools/scripts/sync.py", line 74, in cli
install_flags=install_flags))
File "venv/lib64/python3.6/site-packages/piptools/sync.py", line 159, in sync
for ireq in sorted(to_install):
TypeError: '<' not supported between instances of 'InstallRequirement' and 'InstallRequirement'

# Fixed code
def sync(
    to_install,
    to_uninstall,
    verbose=False,
    dry_run=False,
    pip_flags=None,
    install_flags=None,
):
    """
    Install and uninstalls the given sets of modules.
    """
    if not to_uninstall and not to_install:
        click.echo("Everything up-to-date")

    if pip_flags is None:
        pip_flags = []

    if not verbose:
        pip_flags += ["-q"]

    if os.environ.get("VIRTUAL_ENV"):
        # find pip via PATH
        pip = "pip"
    else:
        # find pip in same directory as pip-sync entry-point script
        pip = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), "pip")

    if to_uninstall:
        if dry_run:
            click.echo("Would uninstall:")
            for pkg in to_uninstall:
                click.echo("  {}".format(pkg))
        else:
            check_call([pip, "uninstall", "-y"] + pip_flags + sorted(to_uninstall))

    if to_install:
        if install_flags is None:
            install_flags = []
        if dry_run:
            click.echo("Would install:")
            for ireq in to_install:
                click.echo("  {}".format(format_requirement(ireq)))
        else:
            package_args = []
            for ireq in sorted(to_install, key=key_from_ireq):
                if ireq.editable:
                    package_args.extend(["-e", str(ireq.link or ireq.req)])
                else:
                    package_args.append(str(ireq.req))
            check_call([pip, "install"] + pip_flags + install_flags + package_args)
    return 0