# Buggy code
def vendoring(session):
    # type: (nox.Session) -> None
    session.install("vendoring>=0.3.0")

    if "--upgrade" not in session.posargs:
        session.run("vendoring", "sync", ".", "-v")
        return

    def pinned_requirements(path):
        # type: (Path) -> Iterator[Tuple[str, str]]
        for line in path.read_text().splitlines():
            one, two = line.split("==", 1)
            name = one.strip()
            version = two.split("#")[0].strip()
            yield name, version

    vendor_txt = Path("src/pip/_vendor/vendor.txt")
    for name, old_version in pinned_requirements(vendor_txt):
        if name == "setuptools":
            continue

        # update requirements.txt
        session.run("vendoring", "update", ".", name)

        # get the updated version
        new_version = old_version
        for inner_name, inner_version in pinned_requirements(vendor_txt):
            if inner_name == name:
                # this is a dedicated assignment, to make flake8 happy
                new_version = inner_version
                break
        else:
            session.error(f"Could not find {name} in {vendor_txt}")

        # check if the version changed.
        if new_version == old_version:
            continue  # no change, nothing more to do here.

        # synchronize the contents
        session.run("vendoring", "sync", ".")

        # Determine the correct message
        message = f"Upgrade {name} to {new_version}"

        # Write our news fragment
        news_file = Path("news") / (name + ".vendor.rst")
        news_file.write_text(message + "\n")  # "\n" appeases end-of-line-fixer

        # Commit the changes
        release.commit_file(session, ".", message=message)


# Traceback (ValueError)
nox -s vendoring -- --upgrade
nox > Running session vendoring
nox > Re-using existing virtual environment at .nox\vendoring.
nox > python -m pip install vendoring>=0.3.0
nox > vendoring update . appdirs
Load configuration... Done!
Updating requirements... Done!
nox > vendoring update . CacheControl
Load configuration... Done!
Updating requirements...
[(2, ''), (4, ''), (6, ''), (8, ''), (10, ''), (12, ''), (14, ''), (16, ''), (18, ''), (20, ''), (22, ''), (24, ''), (26, ''), (28, ''), (30, ''), (32, ''), (34, ''), (36, ''), (38, ''), (40, ''), (42, ''), (44, ''), (46, '')]
nox > Session vendoring raised exception ValueError('not enough values to unpack (expected 2, got 1)')
Traceback (most recent call last):
File "c:\users\gustav\.local\pipx\venvs\nox\lib\site-packages\nox\sessions.py", line 549, in execute
self.func(session)
File "c:\users\gustav\.local\pipx\venvs\nox\lib\site-packages\nox\_decorators.py", line 53, in __call__
return self.func(*args, **kwargs)
File "D:\Work\Projects\pip\noxfile.py", line 182, in vendoring
for inner_name, inner_version in pinned_requirements(vendor_txt):
File "D:\Work\Projects\pip\noxfile.py", line 167, in pinned_requirements
one, two = line.split("==", 1)
ValueError: not enough values to unpack (expected 2, got 1)
nox > Session vendoring failed.

# Fixed code
def vendoring(session):
    # type: (nox.Session) -> None
    session.install("vendoring>=0.3.0")

    if "--upgrade" not in session.posargs:
        session.run("vendoring", "sync", ".", "-v")
        return

    def pinned_requirements(path):
        # type: (Path) -> Iterator[Tuple[str, str]]
        for line in path.read_text().splitlines(keepends=False):
            one, sep, two = line.partition("==")
            if not sep:
                continue
            name = one.strip()
            version = two.split("#", 1)[0].strip()
            if name and version:
                yield name, version

    vendor_txt = Path("src/pip/_vendor/vendor.txt")
    for name, old_version in pinned_requirements(vendor_txt):
        if name == "setuptools":
            continue

        # update requirements.txt
        session.run("vendoring", "update", ".", name)

        # get the updated version
        new_version = old_version
        for inner_name, inner_version in pinned_requirements(vendor_txt):
            if inner_name == name:
                # this is a dedicated assignment, to make flake8 happy
                new_version = inner_version
                break
        else:
            session.error(f"Could not find {name} in {vendor_txt}")

        # check if the version changed.
        if new_version == old_version:
            continue  # no change, nothing more to do here.

        # synchronize the contents
        session.run("vendoring", "sync", ".")

        # Determine the correct message
        message = f"Upgrade {name} to {new_version}"

        # Write our news fragment
        news_file = Path("news") / (name + ".vendor.rst")
        news_file.write_text(message + "\n")  # "\n" appeases end-of-line-fixer

        # Commit the changes
        release.commit_file(session, ".", message=message)