code: def render_pep440_branch_based(pieces):
      
      replacements = ([' ', '.'], ['(', ''], [')', ''], ['\\', '.'], ['/', '.'])
      branch_name = pieces.get('branch') or ''
      if branch_name:
          for old, new in replacements:
              branch_name = branch_name.replace(old, new)
      else:
          branch_name = 'unknown_branch'
  
      if pieces["closest-tag"]:
          rendered = pieces["closest-tag"]
          if pieces["distance"] or pieces["dirty"]:
              rendered += '.dev0' + plus_or_dot(pieces)
              rendered += "%d.%s.g%s" % (
                  pieces["distance"],
                  branch_name,
                  pieces['short']
              )
              if pieces["dirty"]:
                  rendered += ".dirty"
      else:
          # exception #1
          rendered = "0+untagged.%d.%s.g%s" % (
              pieces["distance"],
              branch_name,
              pieces['short']
          )
          if pieces["dirty"]:
              rendered += ".dirty"
      return rendered
docs: Build up version string, with post-release "local version identifier".
  
      Our goal: TAG[+DISTANCE.BRANCH_gHEX[.dirty]] . Note that if you
      get a tagged build and then dirty it, you'll get TAG+0.BRANCH_gHEX.dirty
  
      Exceptions:
      1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.BRANCH_gHEX[.dirty]