code: def release(session):
      package_name = "packaging"
      version_file = Path(f"src/{package_name}/__init__.py")
      changelog_file = Path("CHANGELOG.rst")
  
      try:
          release_version = _get_version_from_arguments(session.posargs)
      except ValueError as e:
          session.error(f"Invalid arguments: {e}")
          return
  
      # Check state of working directory and git.
      _check_working_directory_state(session)
      _check_git_state(session, release_version)
  
      # Prepare for release.
      _changelog_update_unreleased_title(
          release_version, file=changelog_file
      )
      session.run("git", "add", str(changelog_file), external=True)
      _bump(
          session,
          version=release_version,
          file=version_file,
          kind="release",
      )
  
      # Tag the release commit.
      # fmt: off
      session.run(
          "git", "tag",
          "-s", release_version,
          "-m", f"Release {release_version}",
          external=True,
      )
      # fmt: on
  
      # Prepare for development.
      _changelog_add_unreleased_title(file=changelog_file)
      session.run("git", "add", str(changelog_file), external=True)
  
      major, minor = map(int, release_version.split("."))
      next_version = f"{major}.{minor + 1}.dev0"
      _bump(
          session,
          version=next_version,
          file=version_file,
          kind="development",
      )
  
      # Checkout the git tag.
      session.run(
          "git", "checkout", "-q", release_version, external=True
      )
  
      session.install("build", "twine")
  
      # Build the distribution.
      session.run("python", "-m", "build")
  
      # Check what files are in dist/ for upload.
      files = sorted(glob.glob("dist/*"))
      expected = [
          f"dist/{package_name}-{release_version}-py3-none-any.whl",
          f"dist/{package_name}-{release_version}.tar.gz",
      ]
      if files != expected:
          diff_generator = difflib.context_diff(
              expected,
              files,
              fromfile="expected",
              tofile="got",
              lineterm="",
          )
          diff = "\n".join(diff_generator)
          session.error(f"Got the wrong files:\n{diff}")
  
      # Get back out into main.
      session.run("git", "checkout", "-q", "main", external=True)
  
      # Check and upload distribution files.
      session.run("twine", "check", *files)
  
      # Push the commits and tag.
      # NOTE: The following fails if pushing to the branch is not allowed. This can
      #       happen on GitHub, if the main branch is protected, there are required
      #       CI checks and "Include administrators" is enabled on the protection.
      session.run(
          "git",
          "push",
          "upstream",
          "main",
          release_version,
          external=True,
      )
  
      # Upload the distribution.
      session.run("twine", "upload", *files)
  
      # Open up the GitHub release page.
      webbrowser.open("https://github.com/pypa/packaging/releases")
  
imports: import contextlib
  import datetime
  import difflib
  import glob
  import os
  import re
  import shutil
  import subprocess
  import sys
  import tempfile
  import textwrap
  import time
  import webbrowser
  from pathlib import Path
  import nox
label_desc: Use image node_id 4 for calling a global function with example usage: release(session) without return types